Rerun script on new page
This commit is contained in:
parent
f03e98bceb
commit
fb25d27e0d
@ -66,6 +66,21 @@ function addButtons() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(async function () {
|
(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();
|
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);
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user