I'm writing a Tampermonkey script and I set up a listener for hashchange
.
Inside that listener, I call a function that manipulates the DOM. The problem is that the function is called before the page is fully loaded.
The page is not completely reloading when switching from one section to another so on load
would only work once, that's why I'm listening for hashchange
instead of load
.
window.addEventListener('hashchange', function (e) {
if (!/step=view&ID=/.test(location.hash)) {
//TODO clean up if leaving active trade
return
}
console.log('hash changed', e)
setup()
});
function setup() {
//wait for page load here
$('.myclass').after(<span>foo</span>);
}
I tried adding on load
inside setup but that did nothing.
Edit:
Adding a listener for load
outside setup
would also work only once if going to the exact link, so that's not an option either.