diff --git a/sn_translator/sn-translator.js b/sn_translator/sn-translator.js index c0a54c9..ff558e3 100644 --- a/sn_translator/sn-translator.js +++ b/sn_translator/sn-translator.js @@ -66,6 +66,21 @@ function addButtons() { } (async function () { - await sleep(1000); + // Sleep before running script on page load + // since else we might get overwritten by loading content. + const initialSleep = 1000; + await sleep(initialSleep); + + let pathname = window.location.pathname; + console.log(`Current location: ${pathname}`); addButtons(); + // Check if URL changed and rerun script + const scriptInterval = 1000; + setInterval(() => { + if (window.location.pathname !== pathname) { + pathname = window.location.pathname; + console.log(`New location detected: ${pathname}`); + addButtons(); + } + }, scriptInterval); })();