清单.json
{
"name": "Background",
"permissions" : ["http://*/*", "https://*/*"],
"version": "1.0",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["script.js"],
"all_frames": false,
"run_at": "document_start"
}],
"manifest_version": 2
}
脚本.js
var color = document.documentElement.style.backgroundColor;
document.documentElement.style.backgroundColor = "black";
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.target.nodeName == "BODY") {
observer.disconnect();
document.documentElement.style.backgroundColor = color || "";
}
});
});
observer.observe(document, { childList: true, subtree: true });
将所有文件放在一个文件夹中。在chrome中,转到设置->扩展->打开开发者模式->加载解压的扩展->选择刚刚创建的文件夹。