Skip to content

Commit

Permalink
Delete all the timers even after they've been cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
NightScript370 committed Sep 5, 2024
1 parent c79b5a7 commit 98444e4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
4 changes: 3 additions & 1 deletion assets/js/shul-wall/pageFlip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ if (!('timers' in window))

const swap = () => {
// @ts-ignore
if ('timers' in window && 'swapTime' in window.timers)
if ('timers' in window && 'swapTime' in window.timers) {
// @ts-ignore
clearTimeout(window.timers.swapTime)
delete window.timers.swapTime
}

const container = document.getElementById("content");

Expand Down
86 changes: 43 additions & 43 deletions assets/js/shul-wall/reload.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
// @ts-check

export async function reload() {
window.location.reload();
window.location.reload();

await waitFor(6000);
sleep();
await waitFor(6000);
sleep();

const pageFetch = await fetch(window.location.href);
const pageText = await pageFetch.text();
const pageFetch = await fetch(window.location.href);
const pageText = await pageFetch.text();

if ('timers' in window) {
Object.values(window.timers).forEach(clearTimeout);
window.timers = {};
}
if ('timers' in window) {
Object.values(window.timers).forEach(timeout => {clearTimeout(timeout); delete window.timers[timeout]});
window.timers = {};
}

var newDoc = new DOMParser().parseFromString(pageText, "text/html");
const newScrs = [];
for (const script of newDoc.querySelectorAll('script')) {
console.log(script);
var newDoc = new DOMParser().parseFromString(pageText, "text/html");
const newScrs = [];
for (const script of newDoc.querySelectorAll('script')) {
console.log(script);

const newScript = document.createElement('script');
if (script.type)
newScript.type = script.type;
const newScript = document.createElement('script');
if (script.type)
newScript.type = script.type;

if (script.src) {
const scrUrl = new URL(script.src);
scrUrl.searchParams.delete('v')
scrUrl.searchParams.append('v', getRandomIntInclusive(1, 99999).toString());
if (script.src) {
const scrUrl = new URL(script.src);
scrUrl.searchParams.delete('v')
scrUrl.searchParams.append('v', getRandomIntInclusive(1, 99999).toString());

newScript.src = scrUrl.href;
}
newScript.src = scrUrl.href;
}

if (script.innerHTML) {
newScript.innerHTML = '// ' + new Date().toString() + '\n' + script.innerHTML
}
newScrs.push(newScript);
if (script.innerHTML) {
newScript.innerHTML = '// ' + new Date().toString() + '\n' + script.innerHTML
}
newScrs.push(newScript);

script.remove();
}
script.remove();
}

document.replaceChild(
document.importNode(newDoc.documentElement, true),
document.documentElement
);
document.replaceChild(
document.importNode(newDoc.documentElement, true),
document.documentElement
);

/* for (const child of document.documentElement.childNodes)
child.remove();
/* for (const child of document.documentElement.childNodes)
child.remove();
await waitFor(2000);
await waitFor(2000);
document.documentElement.insertAdjacentHTML('afterbegin', pageText); */
document.documentElement.insertAdjacentHTML('afterbegin', pageText); */

await waitFor(200);
for (const newScr of newScrs)
document.head.appendChild(newScr)
await waitFor(200);
for (const newScr of newScrs)
document.head.appendChild(newScr)
}

/** @param {number} delay */
function waitFor (delay) { return new Promise(resolve => setTimeout(resolve, delay)) }
async function sleep() {
return new Promise(requestAnimationFrame);
return new Promise(requestAnimationFrame);
}

/**
* @param {number} min
* @param {number} max
*/
function getRandomIntInclusive(min, max) {
const minCeiled = Math.ceil(min);
const maxFloored = Math.floor(max);
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // The maximum is inclusive and the minimum is inclusive
const minCeiled = Math.ceil(min);
const maxFloored = Math.floor(max);
return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled); // The maximum is inclusive and the minimum is inclusive
}

0 comments on commit 98444e4

Please sign in to comment.