0

I'm working on a chrome extension that allows you to hide threads from a message board. I have it working, but the "Hide Me" link flickers into existence after the page loads. It works fine, but I'd like to load the link along with the rest of the DOM and not appear after the page load.

I tried adding "run_at": "document_start" to manifest.json, but it prevented the Hide Me link from even rendering.

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

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

Is this possible, or do I just have to deal with it happening after the fact?

metersk
  • 11,803
  • 21
  • 63
  • 100
  • 1
    Use MutationObserver. – wOxxOm Oct 28 '17 at 20:28
  • Possible duplicate of [Is there a JavaScript/jQuery DOM change listener?](https://stackoverflow.com/questions/2844565/is-there-a-javascript-jquery-dom-change-listener) – Makyen Oct 28 '17 at 21:51

1 Answers1

0

According to this answer, $(function(){}) runs when the DOM is ready, so try that out.

=edit There's also document.addEventListener("DOMContentLoaded", function(event)

TKoL
  • 13,158
  • 3
  • 39
  • 73