2017-10-28 89 views
0

我正在研究一個Chrome擴展,它允許您隱藏留言板中的線程。我有它的工作,但「隱藏我」鏈接頁面加載後閃爍存在。它工作正常,但我想加載鏈接以及DOM的其餘部分,並不會在頁面加載後出現。在整頁渲染之前運行Chrome擴展的jQuery

我試着加入"run_at": "document_start"manifest.json,但它阻止了隱藏我鏈接甚至渲染。

$('a.topictitle').after(" | <a class='hideMe'>Hide Me</a>"); 

$('.hideMe').on('click', function(){ 
    var thread = $(this).closest('li') 
    console.log(thread) 
    thread.remove() 
}); 

這是可能的,還是我只需要處理它發生的事實?

+1

使用MutationObserver。 – wOxxOm

+0

[是否有JavaScript/jQuery DOM更改偵聽器?](https://stackoverflow.com/questions/2844565/is-there-a-javascript-jquery-dom-change-listener) – Makyen

回答

0

根據this answer$(function(){})在DOM準備就緒時運行,所以試試看。

=編輯還有document.addEventListener("DOMContentLoaded", function(event)