various js fixes

pull/83/head
Aevann 2023-01-01 09:55:25 +02:00
parent dce00a0d3f
commit e032596c77
6 changed files with 63 additions and 31 deletions

View File

@ -172,7 +172,10 @@ function giveaward(t) {
const data_url = document.querySelectorAll('[data-url]');
for (const element of data_url) {
if (element.dataset.nonce != nonce) continue
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
element.onclick = () => {
document.getElementById('giveaward').dataset.action = element.dataset.url
};

View File

@ -1,5 +1,8 @@
function execute(element, attr) {
if (element.dataset.nonce != nonce) return
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
return
}
const funcs = element.getAttribute(`data-${attr}`).split(';')
for (const func of funcs) {
if (func) {
@ -36,26 +39,6 @@ document.addEventListener("click", function(e){
}
});
const onclick = document.querySelectorAll('[data-onclick]');
for (const element of onclick) {
element.onclick = ()=>{execute(element, 'onclick')};
}
const oninput = document.querySelectorAll('[data-oninput]');
for (const element of oninput) {
element.oninput = ()=>{execute(element, 'oninput')};
}
const onmouseover = document.querySelectorAll('[data-onmouseover]');
for (const element of onmouseover) {
element.onmouseover = ()=>{execute(element, 'onmouseover')};
}
const onchange = document.querySelectorAll('[data-onchange]');
for (const element of onchange) {
element.onchange = ()=>{execute(element, 'onchange')};
}
const onsubmit = document.querySelectorAll('[data-onsubmit]');
for (const element of onsubmit) {
element.onsubmit = (event)=>{
@ -71,19 +54,28 @@ for (const element of onfocus) {
const click_submit = document.querySelectorAll('[click_submit]');
for (const element of click_submit) {
if (element.dataset.nonce != nonce) continue
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
element.onclick = () => {element.form.submit()};
}
const change_submit = document.querySelectorAll('[change_submit]');
for (const element of change_submit) {
if (element.dataset.nonce != nonce) continue
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
element.onchange = () => {element.form.submit()};
}
const undisable_element = document.querySelectorAll('[data-undisable_element]');
for (const element of undisable_element) {
if (element.dataset.nonce != nonce) continue
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
element.oninput = () => {
document.getElementById(element.dataset.undisable_element).disabled = false;
};
@ -91,7 +83,10 @@ for (const element of undisable_element) {
const setting_switchs = document.getElementsByClassName('setting_switch');
for (const element of setting_switchs) {
if (element.dataset.nonce != nonce) continue
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
element.onchange = () => {
postToastSwitch(element,`/settings/personal?${element.name}=${element.checked}`);
};
@ -99,12 +94,41 @@ for (const element of setting_switchs) {
const setting_reloads = document.getElementsByClassName('setting_reload');
for (const element of setting_reloads) {
if (element.dataset.nonce != nonce) continue
if (element.dataset.nonce != nonce) {
console.log("Nonce check failed!")
continue
}
element.onchange = () => {
postToastReload(element,`/settings/personal?${element.name}=${element.value}`);
};
}
const reload_page = document.getElementById('reload_page')
if (reload_page)
if (reload_page) {
reload_page.onclick = ()=>{location.reload()};
}
function register_new_elements(e) {
const onclick = e.querySelectorAll('[data-onclick]');
for (const element of onclick) {
element.onclick = ()=>{execute(element, 'onclick')};
}
const oninput = e.querySelectorAll('[data-oninput]');
for (const element of oninput) {
element.oninput = ()=>{execute(element, 'oninput')};
}
const onmouseover = e.querySelectorAll('[data-onmouseover]');
for (const element of onmouseover) {
element.onmouseover = ()=>{execute(element, 'onmouseover')};
}
const onchange = e.querySelectorAll('[data-onchange]');
for (const element of onchange) {
element.onchange = ()=>{execute(element, 'onchange')};
}
}
register_new_elements(document);
bs_trigger(document);

View File

@ -135,6 +135,7 @@ function post_reply(id){
comments.insertAdjacentHTML('beforeend', comment);
register_new_elements(comments);
bs_trigger(comments);
btn.disabled = false;
@ -181,7 +182,10 @@ function comment_edit(id){
commentForm=document.getElementById('comment-text-'+id);
commentForm.innerHTML = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '').replace(/data-nonce=".*?"/g, `data-nonce="${nonce}"`)
document.getElementById('cancel-edit-'+id).click()
register_new_elements(commentForm);
bs_trigger(commentForm);
document.getElementById('filename-edit-reply-' + id).innerHTML = '<i class="fas fa-file"></i>';
document.getElementById('comment-edit-body-' + id).value = data["body"];
document.getElementById('file-edit-reply-'+id).value = null;
@ -234,6 +238,7 @@ function postComment(fullname, hide){
comments.insertAdjacentHTML('afterbegin', comment);
register_new_elements(comments);
bs_trigger(comments);
btn.disabled = false;

View File

@ -254,8 +254,6 @@ function bs_trigger(e) {
}
}
bs_trigger(document);
function escapeHTML(unsafe) {
return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}

View File

@ -12,6 +12,7 @@ function more_comments(cid, sort) {
if (xhr.status==200) {
let e = document.getElementById(`replies-of-c_${cid}`)
e.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '').replace(/data-nonce=".*?"/g, `data-nonce="${nonce}"`);
register_new_elements(e);
bs_trigger(e)
highlight_unread("old-comment-counts")

View File

@ -10,8 +10,9 @@ function view_more(pid,sort,offset,ids) {
if (xhr.status==200) {
let e = document.getElementById(`view_more-${offset}`);
e.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '').replace(/data-nonce=".*?"/g, `data-nonce="${nonce}"`);
register_new_elements(e);
bs_trigger(e)
highlight_unread("old-comment-counts")
}
btn.disabled = false;