Chrome扩展程序适用于所有网站,仅针对少数网站执行不同的操作

时间:2016-03-08 15:10:35

标签: google-chrome google-chrome-extension google-chrome-devtools

我试图在所有网站上进行扩展工作。对于某些网站特定网站(Google和LinkedIn),我还希望执行其他一些操作。我已设法在Google搜索google.com/search和LinkedIn搜索页linkedin.com/vsearch/上进行操作,并分别执行操作A和B.但我正在努力使其在所有其他网站上运行以执行操作C.

{
  "manifest_version": 2,
  "name": "extname",
  "description": "Welcome to my ext",
   "icons": {
      "48": "images/ext.png"
   },
  "version": "2.6",
  "background": {
    "scripts": [ "js/jquery-2.1.4.min.js", "js/background.js","js/select2.min.js","js/lodash.js","js/bootstrap.min.js","js/bootstrap-select.min.js" ]
  },
  "content_scripts": [{
    "css": [ "css/select2.css" ,"css/bootstrap.min.css","css/bootstrap-select.min.css"  ],
    "js": [ "js/jquery-2.1.4.min.js", "js/extension_google_result.js" ,"js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js"],
    "matches": [ "*://*.google.com/search*" ] //for Google Search page
  },
   {
      "css": [ "css/extension_linkedin_search_page.css", "css/bootstrap.min.css","css/bootstrap-select.min.css" ],
      "js": [ "js/jquery-2.1.4.min.js","js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js"],
      "matches": [ "*://*.linkedin.com/vsearch/*"] //for Linkedin Search page
   },
  {
      "css": [ "css/extension_linkedin_search_page.css" ,"css/bootstrap.min.css","css/bootstrap-select.min.css","css/select2.css" ],
      "js": ["js/lodash.js", "js/jquery-2.1.4.min.js", "js/extension_linkedin_sales_navigator_search_page.js" ,"js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js", "js/akash.js"],
      "matches": [ "<all_urls>"] //for all other sites
  }
    ],
   "content_security_policy": "script-src 'self' 'unsafe-eval' https://d37gvrvc0wt4s1.cloudfront.net https://*.pusher.com; object-src 'self'",
  "browser_action": {
    "default_icon": "images/found128.png",
    "default_popup": "html/extension-login-popup.html",
    "default_title": "Search with Found"
  },
  "permissions": ["cookies","tabs", "http://*/*", "https://*/*","contextMenus", "tabs", "storage", "\u003Call_urls>", "notifications", "webRequest" ]
}

但是这里谷歌和搜索链接的前两个案例完美无缺,我只按预期在那些页面上获得回调(动作A和B)。我也可以调用动作c肌动蛋白c也一直在谷歌和链接搜索页面上调用每一个我不想要的新标签动作。我怎么能解决这个问题?任何的想法?

1 个答案:

答案 0 :(得分:2)

查看Content Scripts,您会发现exclude_matches中的manifest.json可以排除不会注入内容脚本的网页。