paranormal-activities/script.js

92 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2024-05-20 09:05:08 -05:00
// basic functions/variables
const wait = (time) => new Promise(resolve => setTimeout(resolve, time))
const language = localStorage.getItem('language') || 'pl-PL';
// admin message
const ADMIN_MESSAGE = {
author: 'Franek',
message: {
"pl-PL": "Aby zmienić język, wciśnij kombinację klawiszy Shift + L. Niestety, ze względu na limity, język jest ustawiany tylko na aktualną stronę.",
"pl-SL": "Aby zmienić język, wciśnij kombinacyjo klawiszy Shift + L. Niestety, ze względu na limity, język je ustawiany ino na aktualno strōna.",
"en": "To change the language, press the key combination Shift + L. Unfortunately, due to limitations, the language is set only for the current page.",
"de": "Um die Sprache zu ändern, drücken Sie die Tastenkombination Shift + L. Leider wird die Sprache aufgrund von Beschränkungen nur für die aktuelle Seite festgelegt."
},
enabled: true
}
function initializeAdminMessage() {
if (!ADMIN_MESSAGE.enabled) return;
header.style.display = 'unset';
header.textContent = `${ADMIN_MESSAGE.message[language]} ~ ${ADMIN_MESSAGE.author}`
}
// redirects
const redirects = document.querySelectorAll('[data-redirect-to]')
Array.from(redirects).forEach(item => item.addEventListener('click', async e => {
e.preventDefault();
fadeOut(document.body)
await wait(300)
const a = document.createElement("a")
a.href = item.dataset.redirectTo
a.click()
}))
// opacity transitions
async function fadeIn(block) {
block.style.opacity = 0;
await wait(1000);
block.style.opacity = 1;
}
async function fadeOut(block) {
block.style.opacity = 0;
await wait(300);
}
// prevent context menu
const elements = document.querySelectorAll('*');
elements.forEach(el => el.addEventListener('contextmenu', e => e.preventDefault()))
window.addEventListener('hashchange', () => {
fadeIn(document.body);
});
// language support
const translatable = document.querySelectorAll('[data-translatable]');
Array.from(translatable).forEach(item => {
const key = item.dataset.translatable;
const resource = TRANSLATIONS[key];
if (!resource) {
item.textContent = key;
return;
}
item.textContent = resource[language] || key;
})
// shift + l support
document.addEventListener('keydown', e => {
if (e.key === 'L' && e.shiftKey) {
const languagePrompt = prompt([
TRANSLATIONS['choose_language'][language],
Object.keys(TRANSLATIONS['choose_language']).join(', ')
].join(' '));
if (typeof TRANSLATIONS['choose_language'][languagePrompt] === 'undefined') {
alert(TRANSLATIONS['invalid_language'][language]);
return;
}
localStorage.setItem('language', languagePrompt);
location.reload();
}
})
fadeIn(document.body)
initializeAdminMessage()