dcd-legacy/script.js

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-03-07 08:03:58 -06:00
const startPage = document.getElementById('internal__start-page');
const templatePage = document.getElementById('internal__template');
2024-03-07 07:43:25 -06:00
2024-03-08 01:27:24 -06:00
const wait = (time) => new Promise(resolve => setTimeout(resolve, time * 1000));
2024-03-07 08:03:58 -06:00
if (!startPage || !templatePage) {
alert("Base website template got corrupted! Can't find either start page or template page. Closing the window.");
window.close();
} else {
async function proceed() {
const input = document.querySelector('#internal__start-page > input');
const patches = DATA?.[input.value];
2024-03-07 07:43:25 -06:00
2024-03-07 08:03:58 -06:00
if (!patches) return alert('Bad access code!');
2024-03-07 08:39:56 -06:00
applyPatches(patches);
await fadeBlock();
2024-03-07 08:03:58 -06:00
}
function applyPatches(patches) {
for (const [key, func] of Object.entries(patches)) {
const element = document.querySelector(key);
if (!element) {
alert(`Bad data source template! No HTML element found for selector '${key}'.`);
continue;
}
2024-03-07 07:43:25 -06:00
2024-03-07 08:03:58 -06:00
func(element)
}
}
2024-03-07 07:43:25 -06:00
2024-03-07 08:03:58 -06:00
async function fadeBlock() {
startPage.style.opacity = 0;
await wait(0.2);
startPage.style.display = 'none';
await wait(0.2);
2024-03-07 08:39:56 -06:00
templatePage.style.display = 'block';
2024-03-07 08:03:58 -06:00
templatePage.style.opacity = 1;
2024-03-07 07:43:25 -06:00
}
2024-03-07 08:03:58 -06:00
internal__submit.addEventListener('click', async () => await proceed())
2024-03-08 01:27:24 -06:00
}