1 回答

TA贡献1831条经验 获得超10个赞
"run_at": "document_start"
在内容脚本声明中是绝对必要的。
内容脚本将在页面为空时运行,因此我们还需要以下内容之一:
使用
MutationObserver
on观察正在构建的页面document
,例如,检查添加的节点并隐藏与 id 列表匹配的节点。或者构造一个
style
带有选择器的元素来隐藏。
在性能方面,它的速度要快几个数量级。也更简单。
hideSelectors([
'#s_top_wrap',
'#bottom_layer',
'#lm-new',
'#s-top-left',
'#u1',
'#s-hotsearch-wrapper',
'#s_side_wrapper',
]);
function hideSelectors(sels) {
const el = document.createElement('style');
el.textContent = sels.join(',') + '{ display: none !important }';
// there's no <head> at this point so we're adding to <html>
// which is allowed in DOM despite violating the HTML specification
document.documentElement.appendChild(el);
}
添加回答
举报