我正在开发一个需要在文档中注入 css 的 Firefox 插件。
这是manifest.json
文件的一部分。
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["inject_css.js"]
}
],
"permissions": [
"storage",
"<all_urls>",
"activeTab",
"tabs"
]
我试过这段代码(inject_css.js
):
function restoreOptions() {
function onError(error) {
console.log(`Error: ${error}`);
};
function setCurrentChoice(result) {
var css = '::selection { background: ' + result.background_color || "auto" + '; color: ' + result.color || "auto" + '}';
var insertingCSS = browser.tabs.insertCSS({code: css});
insertingCSS.then(null, console.log("Injection error !"));
};
let getting = browser.storage.sync.get();
getting.then(setCurrentChoice, onError);
};
document.addEventListener("DOMContentLoaded", restoreOptions);
但是没有注入css,但没有任何错误。但是,代码被执行是因为我尝试添加一些alert()
.
您可以在此处安装插件