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);
}
添加回答
舉報