匹配Chrome扩展程序中除某些网址之外的所有网址

时间:2022-08-29 16:49:05

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?

我试图让它以便我的内容脚本在除了3之外的每个站点上运行。我知道可能有一种方法可以用正则表达式进行,但我不想这样做。 chrome扩展清单是否允许例外?

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

如果正则表达式是唯一的解决方案,并且任何人都知道排除这3个URL的模式也会很棒。

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

2 个解决方案

#1


6  

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

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/"
        ]
    }
]

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.

我猜你最后会想要一个*:“https://twitter.com/*”等,以排除这些域上所有页面上的脚本,而不仅仅是主页。您还可以查看exclude_globs选项。

#2


1  

Well, in this case, Regex is quite straight forward:

那么,在这种情况下,Regex非常直接:

(www\.linkedin\.com)|(mail\.google\.com)|(twitter\.com)

)nly thing, you have to escape the dots (.) With Backslash (). Assuming the protocol should be left open. Else just put the escaped protocol up front

)nly,你必须用反斜杠()来逃避点(。)。假设协议应该保持开放。其他只是把逃脱的协议放在前面

https:\/\/

#1


6  

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

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/"
        ]
    }
]

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.

我猜你最后会想要一个*:“https://twitter.com/*”等,以排除这些域上所有页面上的脚本,而不仅仅是主页。您还可以查看exclude_globs选项。

#2


1  

Well, in this case, Regex is quite straight forward:

那么,在这种情况下,Regex非常直接:

(www\.linkedin\.com)|(mail\.google\.com)|(twitter\.com)

)nly thing, you have to escape the dots (.) With Backslash (). Assuming the protocol should be left open. Else just put the escaped protocol up front

)nly,你必须用反斜杠()来逃避点(。)。假设协议应该保持开放。其他只是把逃脱的协议放在前面

https:\/\/