gpt4 book ai didi

javascript - Chrome 扩展程序 : How do I get me Content Script Extension to show up on select websites

转载 作者:行者123 更新时间:2023-11-28 01:57:39 26 4
gpt4 key购买 nike

我希望我的 Chrome 扩展程序能够显示在 Google 和亚马逊上。我的manifest.json看起来像这样:

{
"background": {"scripts": ["background.js"]},
"content_scripts": [
{
"matches": ["*://*.google.com/*", "http://www.amazon.com/*", "*://*.amazon.com/*"],
"js": ["background.js"]
}
],
"name": "Denver Public Library Lookup",
"description": "Does Stuff",
"homepage_url": "http://www.artifacting.com",
"icons": {
"16": "icon-16.png",
"48": "icon-48.png",
"128": "icon-128.png" },
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
],
"version": "1.0",
"manifest_version": 2
}

但它没有出现在谷歌或亚马逊上,我不明白为什么。

这是我的背景.js

chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(tab.id, {file: "bookmarklet.js"})
});

这是 bookmarlet.js

setTimeout('x99.focus()', 300);
var re = /([\/-]|at[at]n=)/i;
if (re.test(location.href) == true) {
var isbn = RegExp.$2;
var x99 = window.open('http://searchsite/search/searchresults.aspx?ctx=1.1033.0.0.6&type=Keyword&term=' + atatn, 'Library', 'scrollbars=1,resizable=1,top=0,left=0,location=1,width=800,height=600');
x99.focus();
}

有什么想法吗?感谢您的帮助。

最佳答案

代码中有很多错误。

  • 这里不需要内容脚本,所有操作都可以执行在后台页面内容内
  • 制作背景页很难代码在内容脚本中工作,这绝对不是您的情况。因此使用相同的background.js作为背景和内容脚本至少在你的情况下不起作用
  • Manifest 未声明浏览器行动。
  • 等等

我强烈建议从 Google extension documentation 开始。您将节省大量时间。

我认为文件可能是什么样子

list .json

{
"background": {"scripts": ["background.js"]},
"name": "Denver Public Library Lookup",
"description": "Does Stuff",
"homepage_url": "http://www.artifacting.com",
"icons": {
"16": "icon-16.png",
"48": "icon-48.png",
"128": "icon-128.png" },
"browser_action": {
"default_icon": {
"19": "images/icon-19.png",
"38": "images/icon-38.png"
},
"default_title": "Do Staff" // optional; shown in tooltip
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
],
"version": "1.0",
"manifest_version": 2
}

背景.js

chrome.browserAction.onClicked.addListener(function(tab) {
// You need more sothisticated regexp here which checks for amazon and google domains
var re = /([\/-]|at[at]n=)/i;
if (re.test(tab.url)) {
var isbn = RegExp.$2;
var url = "http://searchsite/search/searchresults.aspx?ctx=1.1033.0.0.6&type=Keyword&term=" + isbn;
chrome.windows.create({
url : url,
left: 0,
top: 0,
width: 800,
height: 600,
focused: true,
type: "popup"
});
}
});

不需要bookmarlet.js

关于javascript - Chrome 扩展程序 : How do I get me Content Script Extension to show up on select websites,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18883801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com