2023-02-01 15:30:42 +00:00
|
|
|
|
|
|
|
function execute(element, attr) {
|
|
|
|
if (element.dataset.nonce != nonce) {
|
2023-02-21 18:29:32 +00:00
|
|
|
console.error("Nonce check failed!")
|
2023-02-01 15:30:42 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
const funcs = element.getAttribute(`data-${attr}`).split(';')
|
|
|
|
for (const func of funcs) {
|
|
|
|
if (func) {
|
|
|
|
const split = func.split('(')
|
|
|
|
const name = split[0]
|
|
|
|
const args = split[1].replace(/[')]/g, "").split(',').map(a => a.trim());
|
|
|
|
if (args[0] == 'this') args[0] = element
|
|
|
|
try {
|
|
|
|
window[name](...args);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2023-02-21 18:29:32 +00:00
|
|
|
console.error(e)
|
|
|
|
console.error(name)
|
2023-02-01 15:30:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const onsubmit = document.querySelectorAll('[data-onsubmit]');
|
|
|
|
for (const element of onsubmit) {
|
|
|
|
element.addEventListener('submit', (event)=>{
|
|
|
|
event.preventDefault();
|
|
|
|
execute(element, 'onsubmit')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const onfocus = document.querySelectorAll('[data-onfocus]');
|
|
|
|
for (const element of onfocus) {
|
|
|
|
element.addEventListener('focus', () => {execute(element, 'onfocus')});
|
|
|
|
}
|
|
|
|
|
|
|
|
const onclick_submit = document.querySelectorAll('[onclick_submit]');
|
|
|
|
for (const element of onclick_submit) {
|
|
|
|
if (element.dataset.nonce != nonce) {
|
|
|
|
console.log("Nonce check failed!")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
element.addEventListener('click', () => {element.form.submit()});
|
|
|
|
}
|
|
|
|
|
|
|
|
const onchange_submit = document.querySelectorAll('[onchange_submit]');
|
|
|
|
for (const element of onchange_submit) {
|
|
|
|
if (element.dataset.nonce != nonce) {
|
|
|
|
console.log("Nonce check failed!")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
element.addEventListener('change', () => {element.form.submit()});
|
|
|
|
}
|
|
|
|
|
|
|
|
const undisable_element = document.querySelectorAll('[data-undisable_element]');
|
|
|
|
for (const element of undisable_element) {
|
|
|
|
if (element.dataset.nonce != nonce) {
|
|
|
|
console.log("Nonce check failed!")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
element.addEventListener('input', () => {
|
|
|
|
document.getElementById(element.dataset.undisable_element).disabled = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-12 10:54:10 +00:00
|
|
|
function handleSettingSwitch(t) {
|
|
|
|
postToast(t, `/settings/personal?${t.name}=${t.checked}`,
|
|
|
|
{},
|
|
|
|
() => {
|
|
|
|
if (["slurreplacerswitch", "profanityreplacerswitch"].includes(t.id)) {
|
|
|
|
document.getElementById(
|
|
|
|
`${t.id.replace("switch", "")}-perma-link`
|
|
|
|
).hidden = !t.checked;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
t.checked = !t.checked;
|
|
|
|
},
|
|
|
|
);
|
2023-08-06 20:01:59 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 15:30:42 +00:00
|
|
|
const setting_switchs = document.getElementsByClassName('setting_switch');
|
|
|
|
for (const element of setting_switchs) {
|
|
|
|
if (element.dataset.nonce != nonce) {
|
|
|
|
console.log("Nonce check failed!")
|
|
|
|
continue
|
|
|
|
}
|
2023-08-12 10:54:10 +00:00
|
|
|
element.addEventListener('change', () => {handleSettingSwitch(element)});
|
2023-02-01 15:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const setting_selects = document.getElementsByClassName('setting_select');
|
|
|
|
for (const element of setting_selects) {
|
|
|
|
if (element.dataset.nonce != nonce) {
|
|
|
|
console.log("Nonce check failed!")
|
|
|
|
continue
|
|
|
|
}
|
2023-10-07 14:37:05 +00:00
|
|
|
element.dataset.current = element.selectedIndex;
|
2023-02-01 15:30:42 +00:00
|
|
|
element.addEventListener('change', () => {
|
2023-06-27 21:56:23 +00:00
|
|
|
if (element.id == "changing-house") {
|
2023-10-04 16:58:10 +00:00
|
|
|
if (confirm(`Are you sure you want to change houses?\nIt will cost you ${element.dataset.cost} coins or marseybux!`)) {
|
2023-10-07 14:37:05 +00:00
|
|
|
postToast(element,`/settings/personal?${element.name}=${element.value}`);
|
|
|
|
element.dataset.current = element.selectedIndex;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
element.selectedIndex = element.dataset.current;
|
2023-06-27 21:56:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (element.dataset.reload)
|
2023-02-01 15:30:42 +00:00
|
|
|
postToastReload(element,`/settings/personal?${element.name}=${element.value}`);
|
|
|
|
else
|
|
|
|
postToast(element,`/settings/personal?${element.name}=${element.value}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const TH = document.getElementsByTagName('th')
|
|
|
|
for (const element of TH) {
|
2023-02-06 02:07:39 +00:00
|
|
|
if (element.classList.contains("disable-sort-click"))
|
2023-05-05 21:46:24 +00:00
|
|
|
continue;
|
2023-02-06 02:07:39 +00:00
|
|
|
|
2023-02-01 15:30:42 +00:00
|
|
|
element.addEventListener('click', () => {sort_table(element)});
|
|
|
|
}
|
|
|
|
|
|
|
|
function register_new_elements(e) {
|
|
|
|
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')};
|
|
|
|
}
|
|
|
|
|
2023-03-10 23:47:50 +00:00
|
|
|
const file_inputs = document.querySelectorAll('input[multiple="multiple"]')
|
|
|
|
for (const input of file_inputs) {
|
|
|
|
input.onchange = () => {handle_files(input, input.files)};
|
|
|
|
}
|
|
|
|
|
|
|
|
const onclick = e.querySelectorAll('[data-onclick]');
|
|
|
|
for (const element of onclick) {
|
2023-04-29 15:52:50 +00:00
|
|
|
element.onclick = () => {execute(element, 'onclick')};
|
2023-03-10 23:47:50 +00:00
|
|
|
}
|
2023-03-12 14:09:43 +00:00
|
|
|
|
|
|
|
const textareas = e.getElementsByTagName('textarea')
|
|
|
|
for (const element of textareas) {
|
|
|
|
autoExpand(element)
|
|
|
|
element.addEventListener('input', () => {
|
|
|
|
autoExpand(element)
|
|
|
|
});
|
2023-03-14 08:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const popover_triggers = document.getElementsByClassName('user-name');
|
|
|
|
for (const element of popover_triggers) {
|
|
|
|
element.onclick = (e) => {
|
|
|
|
if (!(e.ctrlKey || e.metaKey || e.shiftKey || e.altKey))
|
|
|
|
e.preventDefault();
|
|
|
|
};
|
|
|
|
}
|
2023-03-11 23:40:08 +00:00
|
|
|
}
|
2023-03-10 23:47:50 +00:00
|
|
|
|
2023-03-11 23:40:08 +00:00
|
|
|
register_new_elements(document);
|
|
|
|
bs_trigger(document);
|
2023-02-01 15:30:42 +00:00
|
|
|
|
2023-02-06 02:07:18 +00:00
|
|
|
|
2023-10-02 14:24:09 +00:00
|
|
|
const negative_awards = document.querySelectorAll("[data-positive=False]")
|
|
|
|
|
2023-04-29 13:27:21 +00:00
|
|
|
document.addEventListener("click", function (e) {
|
2023-04-29 13:02:01 +00:00
|
|
|
let element = e.target
|
|
|
|
if (element.tagName == "I")
|
|
|
|
element = element.parentElement
|
2023-02-27 15:02:35 +00:00
|
|
|
|
2023-08-03 07:05:24 +00:00
|
|
|
if (!element) return
|
|
|
|
|
2023-10-17 12:50:39 +00:00
|
|
|
if (element instanceof HTMLImageElement && (element.alt.startsWith('![](') || element.classList.contains('img'))) {
|
2023-03-11 23:40:08 +00:00
|
|
|
expandImage()
|
2023-02-27 15:02:35 +00:00
|
|
|
}
|
2023-03-11 23:40:08 +00:00
|
|
|
else if (element.classList.contains('showmore')) {
|
|
|
|
showmore(element)
|
|
|
|
}
|
|
|
|
else if (element.dataset.url) {
|
2023-02-27 15:19:28 +00:00
|
|
|
if (element.dataset.nonce != nonce) {
|
|
|
|
console.log("Nonce check failed!")
|
2023-03-11 23:40:08 +00:00
|
|
|
return
|
2023-02-27 15:19:28 +00:00
|
|
|
}
|
2023-12-01 15:44:53 +00:00
|
|
|
document.getElementById('giveaward').dataset.url = element.dataset.url
|
|
|
|
document.getElementById('buyandgiveaward').dataset.url = element.dataset.url
|
2023-08-12 17:55:51 +00:00
|
|
|
|
2023-10-10 20:34:35 +00:00
|
|
|
const currently_picked = document.getElementById("awardModal").getElementsByClassName('picked')[0]
|
|
|
|
if (currently_picked && currently_picked.id == 'emoji') {
|
|
|
|
if (element.dataset.url.startsWith('/award/post/'))
|
|
|
|
document.getElementById('emoji_behavior_section').classList.remove("d-none")
|
|
|
|
else
|
|
|
|
document.getElementById('emoji_behavior_section').classList.add("d-none")
|
|
|
|
}
|
|
|
|
|
2023-08-12 17:55:51 +00:00
|
|
|
const effect_author_tab = document.getElementById('effect-author-tab')
|
|
|
|
const effect_content_tab = document.getElementById('effect-content-tab')
|
|
|
|
const effect_author_section = document.getElementById('effect-author-section')
|
|
|
|
const effect_content_section = document.getElementById('effect-content-section')
|
|
|
|
if (element.dataset.ghost == 'True') {
|
|
|
|
effect_author_tab.classList.add('disabled')
|
|
|
|
effect_author_tab.classList.remove('active')
|
|
|
|
effect_author_section.classList.add('d-none')
|
|
|
|
effect_content_tab.classList.add('active')
|
|
|
|
effect_content_section.classList.remove('d-none')
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
effect_author_tab.classList.remove('disabled')
|
|
|
|
}
|
2023-10-02 14:24:09 +00:00
|
|
|
|
|
|
|
if (element.dataset.immune == 'True') {
|
|
|
|
for (const award of negative_awards) {
|
|
|
|
award.classList.add('disabled')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (const award of negative_awards) {
|
|
|
|
award.classList.remove('disabled')
|
|
|
|
}
|
|
|
|
}
|
2023-03-07 00:21:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 15:30:42 +00:00
|
|
|
|
2023-03-11 23:40:08 +00:00
|
|
|
if (element.dataset.toggleelement) {
|
2023-07-01 00:13:57 +00:00
|
|
|
if (element.dataset.toggleelement.startsWith('#reply-'))
|
2024-01-12 05:18:24 +00:00
|
|
|
close_inline_emoji_modal();
|
2023-07-01 00:13:57 +00:00
|
|
|
|
2023-03-18 06:36:56 +00:00
|
|
|
const toggling = document.querySelector(element.dataset.toggleelement)
|
|
|
|
const attr = element.dataset.toggleattr;
|
|
|
|
|
|
|
|
toggling.classList.toggle(attr);
|
2023-03-11 23:40:08 +00:00
|
|
|
}
|
2023-03-21 19:11:02 +00:00
|
|
|
|
|
|
|
if (!element.classList.contains("areyousure")) {
|
|
|
|
document.querySelectorAll(".areyousure").forEach(i => {
|
2023-10-10 17:09:48 +00:00
|
|
|
if (element.dataset.bsTarget == "#awardModal" && i.classList.contains('awardbtn'))
|
|
|
|
return
|
|
|
|
|
2023-03-21 19:11:02 +00:00
|
|
|
i.classList.remove("areyousure")
|
2023-05-05 21:45:25 +00:00
|
|
|
|
2023-03-21 19:11:02 +00:00
|
|
|
if (i.dataset.oldvalue)
|
|
|
|
i.value = i.dataset.oldvalue
|
|
|
|
else
|
|
|
|
i.innerHTML = i.dataset.oldhtml
|
|
|
|
|
|
|
|
i.setAttribute("data-onclick", "areyousure(this)");
|
2023-05-05 21:45:25 +00:00
|
|
|
|
2023-03-21 19:11:02 +00:00
|
|
|
if (i.dataset.dismiss)
|
|
|
|
i.removeAttribute("data-bs-dismiss")
|
|
|
|
});
|
|
|
|
}
|
2023-03-11 23:40:08 +00:00
|
|
|
});
|
2023-03-12 14:45:52 +00:00
|
|
|
|
|
|
|
const inputs = document.querySelectorAll('input[type="number"]')
|
|
|
|
for (const input of inputs) {
|
|
|
|
input.onkeyup = () => {
|
|
|
|
if (parseInt(input.value) > parseInt(input.max)) input.value = input.max;
|
|
|
|
};
|
|
|
|
}
|
2023-06-29 18:09:27 +00:00
|
|
|
|
2023-06-29 19:09:33 +00:00
|
|
|
if (!('serviceWorker' in navigator && 'PushManager' in window) || (gbrowser == 'iphone' && !is_pwa)) {
|
2023-06-29 19:05:24 +00:00
|
|
|
let e = document.getElementById("enable-push-nav-item");
|
2023-06-29 18:09:27 +00:00
|
|
|
if (e) {
|
2023-06-29 19:05:24 +00:00
|
|
|
e.classList.add('d-none')
|
2023-06-29 18:09:27 +00:00
|
|
|
}
|
2023-06-29 19:14:09 +00:00
|
|
|
e = document.getElementById("enable-push-nav-item-mobile");
|
2023-06-29 19:12:29 +00:00
|
|
|
if (e) {
|
|
|
|
e.classList.add('d-none')
|
|
|
|
}
|
2023-06-29 19:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gbrowser == 'iphone' && !is_pwa) {
|
2023-06-29 19:14:34 +00:00
|
|
|
const e = document.getElementById("enable-push-nav-item-iphone");
|
2023-06-29 19:05:24 +00:00
|
|
|
if (e) {
|
|
|
|
e.classList.remove('d-none')
|
|
|
|
}
|
|
|
|
}
|
2023-07-01 01:05:28 +00:00
|
|
|
|
|
|
|
if (is_pwa) {
|
|
|
|
const e = document.getElementById("mobile-app-nav-item");
|
2023-07-25 18:45:59 +00:00
|
|
|
e.remove();
|
2023-07-01 01:05:28 +00:00
|
|
|
}
|