gpt4 book ai didi

css - 从 manifest.json 中的 content_scripts 中排除域对 CSS 文件不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:50 25 4
gpt4 key购买 nike

我想写一个 chrome 扩展来强制所有网站使用给定的 CSS 样式,除了 Gmail 页面。但是,manifest.json 中内容脚本中的以下代码不起作用(Gmail 页面仍将使用 font.css 中给出的样式)。

"content_scripts":  [{
"matches": ["http://*/*", "https://*/*"],
"exclude_matches": ["*://mail.google.com/*"],
"css": ["font.css"]
}]

即使采用建议的策略也无法解决这个问题 here通过将 exclude_matches 替换为 exclude_globs

我知道这个错误存在了一段时间,即所谓的Bug #100106 .关于如何解决这个问题的任何想法?或者我可以使用其他方法来实现我的目标吗?

最佳答案

如果您从某些内容 JavaScript 代码中注入(inject) CSS,则可以手动过滤页面。我刚刚做了一个快速测试,以下内容适用于 Chrome 31.0.1650.63:

list .json:

{
"manifest_version": 2,
"name": "My Style",
"description": "Insert custom CSS",
"version": "0.1",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["font.js"],
"run_at":"document_start"
}],
"web_accessible_resources": ["font.css"]
}

字体.js

if (location.hostname.indexOf(".google.com") == -1) {
var link = document.createElement("link");
link.href = chrome.extension.getURL("font.css");
link.type = "text/css";
link.rel = "stylesheet";
document.documentElement.insertBefore(link);
}

字体.css

body {
color: red;
}

通过这种方式,font.css 脚本被注入(inject)所有非 Google 页面。

关于css - 从 manifest.json 中的 content_scripts 中排除域对 CSS 文件不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20784654/

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