javascript - 加载特定网站时自动运行我的 Chrome 扩展程序

标签 javascript html google-chrome-extension

我建立了一个 Chrome 扩展程序,我希望它在我观看某些特定网站(例如“Youtube”)时自动工作,我该如何制作呢?任何帮助将不胜感激。

{
  "manifest_version": 2,

  "name": "My extension",
  "description": "bla bla",
  "version": "1.0",
  "browser_action": {
  "default_icon": "gjx.png",
  "default_popup": "popup.html"
   },
  "permissions": [
  "http://localhost/*",
   "tabs",
   "cookies",
   "storage"
   ],
  "background":["crawler.js"],
  "content_scripts":[{
  "matches": ["*://*.youtube.com/*"],
  "js": ["crawler.js"]
  }]
}

最佳答案

例如,这里的 script.js 将在您所在的 Youtube 页面上自动执行。

manifest.json:

{
    "content_scripts": [{
        "matches": ["https://www.youtube.com/*"],
        "js": ["script.js"]
    }],
    "permissions": [
        "tabs", "http://*/*"
    ]
}

我建议阅读有关匹配和内容脚本的内容 herehere .

关于javascript - 加载特定网站时自动运行我的 Chrome 扩展程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46459149/

相关文章:

javascript - 我的 BooksAPI 无法在我的代码中解析?

javascript - 如何设置属性的特定持续时间

javascript - 如何使用 swig 创建动态链接,以便我可以在链接上设置事件/非事件类?

oauth - 在 Chrome 扩展程序和 Gmail 小工具中安全处理 OAuth 使用者 key 和 secret

facebook - 无法从 Chrome 扩展加载 facebook js sdk

javascript - Chrome 扩展程序太慢

javascript - 在 Rails 中的 .js.erb 中使用 ruby​​ 编码时, Assets 管道无法返回 @variables

html - Div 超过 2 个其他 div?

javascript - jQuery 平滑滚动到任何 anchor

html - 如何确保 <td> 的高度恰好是 200px?