匹配Chrome扩展程序中除特定网址以外的所有网址 [英] Match all URLs except certain URLs in Chrome Extension

查看:684
本文介绍了匹配Chrome扩展程序中除特定网址以外的所有网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图拥有它,以便我的内容脚本可以在除3以外的每个站点上运行。我知道可能有一种方法可以用正则表达式来实现,但我不希望这样做。如果正则表达式是唯一的解决方案,并且任何人都知道排除这3个URL的模式,那么这个URL也很棒。

  https://www.linkedin.com/ 
https://mail.google.com/
https: //twitter.com/


解决方案

https://developer.chrome.com/extensions/content_scripts 列出了一个选项 exclude_matches

 content_scripts:[
{
matches:[< ; all_urls>],
js:[myscript.js],
exclude_matches:[
https://www.linkedin.com/,
https://mail.google.com/,
https://twitter.com/
]
}
]

我猜你会在结尾处要一个 * 那些:http s://twitter.com/*,et.c.,排除这些域上所有页面上的脚本,而不仅仅是主页。
您还可以查看 exclude_globs 选项。


I'm trying to have it so that my content script runs on every site except for 3. I know there's probably a way to do it with regex but I'd prefer not to. Does the chrome extension manifest allow for exceptions?

If regex is the only solution and anyone knows the pattern to exclude these 3 URLs that would be great too.

https://www.linkedin.com/
https://mail.google.com/
https://twitter.com/

解决方案

https://developer.chrome.com/extensions/content_scripts lists an option exclude_matches:

"content_scripts": [
    {
        "matches": ["<all_urls>"],
        "js": ["myscript.js"],
        "exclude_matches": [
            "https://www.linkedin.com/",
            "https://mail.google.com/",
            "https://twitter.com/"
        ]
    }
]

I'm guessing you'll want a * at the end of those: "https://twitter.com/*", et.c., to exclude the script on all pages on those domains, and not just the homepages. You can also look into the exclude_globs option.

这篇关于匹配Chrome扩展程序中除特定网址以外的所有网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆