rDrama/files/assets/js/bottom.js

147 lines
4.4 KiB
JavaScript
Raw Normal View History

2022-12-30 12:14:18 +00:00
function execute(element, attr) {
2023-01-01 07:55:25 +00:00
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
return
}
2022-12-30 12:14:18 +00:00
const funcs = element.getAttribute(`data-${attr}`).split(';')
for (const func of funcs) {
if (func) {
const split = func.split('(')
const name = split[0]
2023-01-01 08:56:11 +00:00
const args = split[1].replace(/[')]/g, "").split(',').map(a => a.trim());
2022-12-30 12:14:18 +00:00
if (args[0] == 'this') args[0] = element
try {
window[name](...args);
}
catch (e) {
2022-12-30 12:52:59 +00:00
console.log(e)
2022-12-30 12:14:18 +00:00
console.log(name)
}
}
}
}
const onsubmit = document.querySelectorAll('[data-onsubmit]');
for (const element of onsubmit) {
2023-01-28 15:17:04 +00:00
element.addEventListener('submit', (event)=>{
2022-12-30 12:52:59 +00:00
event.preventDefault();
execute(element, 'onsubmit')
2023-01-28 15:17:04 +00:00
});
2022-12-30 12:14:18 +00:00
}
const onfocus = document.querySelectorAll('[data-onfocus]');
for (const element of onfocus) {
2023-01-28 15:17:04 +00:00
element.addEventListener('focus', () => {execute(element, 'onfocus')});
2022-12-30 12:14:18 +00:00
}
2023-01-01 09:45:46 +00:00
const onclick_submit = document.querySelectorAll('[onclick_submit]');
for (const element of onclick_submit) {
2023-01-01 07:55:25 +00:00
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
element.addEventListener('click', () => {element.form.submit()});
2022-12-30 12:14:18 +00:00
}
2023-01-01 09:45:46 +00:00
const onchange_submit = document.querySelectorAll('[onchange_submit]');
for (const element of onchange_submit) {
2023-01-01 07:55:25 +00:00
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
2023-01-28 15:17:04 +00:00
element.addEventListener('change', () => {element.form.submit()});
2022-12-30 12:14:18 +00:00
}
2023-01-01 02:17:46 +00:00
const undisable_element = document.querySelectorAll('[data-undisable_element]');
for (const element of undisable_element) {
2023-01-01 07:55:25 +00:00
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
2023-01-28 15:17:04 +00:00
element.addEventListener('input', () => {
2023-01-01 02:17:46 +00:00
document.getElementById(element.dataset.undisable_element).disabled = false;
2023-01-28 15:17:04 +00:00
});
2022-12-30 12:14:18 +00:00
}
const setting_switchs = document.getElementsByClassName('setting_switch');
for (const element of setting_switchs) {
2023-01-01 07:55:25 +00:00
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
2023-01-28 15:17:04 +00:00
element.addEventListener('change', () => {
2023-01-01 02:50:06 +00:00
postToastSwitch(element,`/settings/personal?${element.name}=${element.checked}`);
2023-01-28 15:17:04 +00:00
});
2022-12-30 12:14:18 +00:00
}
2023-01-01 14:19:25 +00:00
const setting_selects = document.getElementsByClassName('setting_select');
for (const element of setting_selects) {
2023-01-01 07:55:25 +00:00
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
2023-01-28 15:17:04 +00:00
element.addEventListener('change', () => {
2023-01-01 14:19:25 +00:00
if (element.dataset.reload)
postToastReload(element,`/settings/personal?${element.name}=${element.value}`);
else
postToast(element,`/settings/personal?${element.name}=${element.value}`);
2023-01-28 15:17:04 +00:00
});
2022-12-30 12:14:18 +00:00
}
2023-01-01 02:53:35 +00:00
const reload_page = document.getElementById('reload_page')
2023-01-01 07:55:25 +00:00
if (reload_page) {
reload_page.addEventListener('click', () => {location.reload()});
2023-01-28 09:55:55 +00:00
}
2023-01-28 10:38:14 +00:00
const TH = document.getElementsByTagName('th')
for (const element of TH) {
element.addEventListener('click', () => {sort_table(element)});
2023-01-28 10:38:14 +00:00
}
const toggleelement = document.querySelectorAll('[data-toggleelement]');
for (const element of toggleelement) {
element.addEventListener('click', () => {
2023-01-28 10:38:14 +00:00
document.getElementById(element.dataset.toggleelement).classList.toggle(element.dataset.toggleattr);
});
2023-01-01 07:55:25 +00:00
}
function register_new_elements(e) {
const showmores = document.getElementsByClassName('showmore')
for (const element of showmores) {
element.addEventListener('click', () => {showmore(element)});
2023-01-20 23:47:27 +00:00
}
2023-01-01 07:55:25 +00:00
const onclick = e.querySelectorAll('[data-onclick]');
for (const element of onclick) {
element.addEventListener('click', () => {execute(element, 'onclick')});
2023-01-01 07:55:25 +00:00
}
const oninput = e.querySelectorAll('[data-oninput]');
for (const element of oninput) {
2023-01-28 15:17:04 +00:00
element.addEventListener('input', () => {execute(element, 'oninput')});
2023-01-01 07:55:25 +00:00
}
const onmouseover = e.querySelectorAll('[data-onmouseover]');
for (const element of onmouseover) {
2023-01-28 15:17:04 +00:00
element.addEventListener('mouseover', () => {execute(element, 'onmouseover')});
2023-01-01 07:55:25 +00:00
}
const onchange = e.querySelectorAll('[data-onchange]');
for (const element of onchange) {
2023-01-28 15:17:04 +00:00
element.addEventListener('change', () => {execute(element, 'onchange')});
2023-01-01 07:55:25 +00:00
}
2023-01-27 16:36:11 +00:00
const popover_triggers = document.getElementsByClassName('user-name');
for (const element of popover_triggers) {
element.addEventListener('click', (e) => {popclick(e)});
2023-01-28 10:37:26 +00:00
}
2023-01-28 10:38:14 +00:00
const expandable = document.querySelectorAll('.in-comment-image, img[alt^="![]("]');
for (const element of expandable) {
element.addEventListener('click', () => {expandImage()});
2023-01-27 16:36:11 +00:00
}
2023-01-01 07:55:25 +00:00
}
register_new_elements(document);
bs_trigger(document);