retvrn to document-wide event listener to fix the barrage of bugs that won't stop

master
Aevann 2023-03-12 01:40:08 +02:00
parent 305fa9e052
commit fedc723a7c
1 changed files with 35 additions and 66 deletions

View File

@ -137,76 +137,45 @@ function register_new_elements(e) {
input.onchange = () => {handle_files(input, input.files)};
}
const showmores = document.getElementsByClassName('showmore')
for (const element of showmores) {
if (element.classList.contains('registered:showmores')) continue
element.addEventListener('click', () => {showmore(element)});
element.classList.add('registered:showmores');
}
const onclick = e.querySelectorAll('[data-onclick]');
for (const element of onclick) {
if (element.classList.contains('registered:onclick')) continue
element.addEventListener('click', () => {execute(element, 'onclick')});
element.classList.add('registered:onclick');
}
const popover_triggers = document.getElementsByClassName('user-name');
for (const element of popover_triggers) {
if (element.classList.contains('registered:popover_triggers')) continue
element.addEventListener('click', (e) => {
if (!(e.ctrlKey || e.metaKey || e.shiftKey || e.altKey))
e.preventDefault();
});
element.classList.add('registered:popover_triggers');
}
const expandable = document.querySelectorAll('.in-comment-image, img[alt^="![]("]');
for (const element of expandable) {
if (element.classList.contains('registered:expandable')) continue
element.addEventListener('click', () => {expandImage()});
element.classList.add('registered:expandable');
}
const toggleelement = e.querySelectorAll('[data-toggleelement]');
for (const element of toggleelement) {
if (element.classList.contains('registered:toggleelement')) continue
element.addEventListener('click', () => {
document.querySelector(element.dataset.toggleelement).classList.toggle(element.dataset.toggleattr);
});
element.classList.add('registered:toggleelement');
}
const remove_files = document.querySelectorAll('button.remove-files')
for (const element of remove_files) {
if (element.classList.contains('registered:remove_files')) continue
element.addEventListener('click', () => {cancel_files(element)});
element.classList.add('registered:remove_files');
}
const data_url = document.querySelectorAll('[data-url]');
for (const element of data_url) {
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
if (element.classList.contains('registered:data_url')) continue
element.addEventListener('click', () => {
document.getElementById('giveaward').dataset.action = element.dataset.url
});
element.classList.add('registered:data_url');
}
const btns_to_disable = document.querySelectorAll('[type="submit"]')
for (const element of btns_to_disable) {
if (element.classList.contains('registered:btns_to_disable')) continue
element.addEventListener('click', () => {disable_btn(element)})
element.classList.add('registered:btns_to_disable');
element.onclick = () => {execute(element, 'onclick')};
}
}
register_new_elements(document);
bs_trigger(document);
document.addEventListener("click", function(e){
const element = e.target
if (element instanceof HTMLImageElement && (element.alt.startsWith('![](')) || element.classList.contains('in-comment-image')) {
expandImage()
}
else if (element.classList.contains('showmore')) {
showmore(element)
}
else if (element.parentElement.classList.contains('user-name')) {
if (!(e.ctrlKey || e.metaKey || e.shiftKey || e.altKey))
e.preventDefault();
}
else if (element.classList.contains('remove-files')) {
cancel_files(element)
}
else if (element.dataset.url) {
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
return
}
document.getElementById('giveaward').dataset.action = element.dataset.url
}
if (element.getAttribute('type') == 'submit') {
disable_btn(element)
}
if (element.dataset.toggleelement) {
document.querySelector(element.dataset.toggleelement).classList.toggle(element.dataset.toggleattr);
}
});