Rerun script on new page

This commit is contained in:
ekzyis 2022-12-25 02:56:39 +01:00
parent f03e98bceb
commit fb25d27e0d
1 changed files with 16 additions and 1 deletions

View File

@ -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);
})();