misuzu/assets/misuzu.js/main.js

91 lines
2.8 KiB
JavaScript
Raw Normal View History

2024-01-24 21:53:26 +00:00
#include utility.js
#include embed/embed.js
#include events/christmas2019.js
#include events/events.js
#include ext/sakuya.js
#include forum/editor.jsx
2024-01-30 23:47:02 +00:00
#include messages/messages.js
2023-07-17 20:14:21 +00:00
2024-01-24 21:53:26 +00:00
(async () => {
const initLoginPage = async () => {
const forms = Array.from($qa('.js-login-form'));
if(forms.length < 1)
return;
2022-09-13 13:14:49 +00:00
2024-01-24 21:53:26 +00:00
const updateForm = async (avatar, userName) => {
if(!(avatar instanceof Element) || !(userName instanceof Element))
return;
2023-01-29 01:51:54 +00:00
2024-01-24 21:53:26 +00:00
const result = (await $x.get(`/auth/login.php?resolve=1&name=${encodeURIComponent(userName.value)}`, { type: 'json' })).body();
2023-01-29 01:51:54 +00:00
2024-01-24 21:53:26 +00:00
avatar.src = result.avatar;
if(result.name.length > 0)
userName.value = result.name;
};
2024-01-24 21:53:26 +00:00
for(const form of forms) {
const avatar = form.querySelector('.js-login-avatar');
const userName = form.querySelector('.js-login-username');
let timeOut;
2024-01-24 21:53:26 +00:00
await updateForm(avatar, userName);
2024-01-24 21:53:26 +00:00
userName.addEventListener('input', function() {
if(timeOut !== undefined)
return;
2024-01-24 21:53:26 +00:00
timeOut = setTimeout(() => {
updateForm(avatar, userName)
.finally(() => {
clearTimeout(timeOut);
timeOut = undefined;
});
}, 750);
});
}
};
2024-01-24 21:53:26 +00:00
const initQuickSubmit = () => {
const elems = Array.from($qa('.js-quick-submit, .js-ctrl-enter-submit'));
if(elems.length < 1)
return;
for(const elem of elems)
elem.addEventListener('keydown', ev => {
if((ev.code === 'Enter' || ev.code === 'NumpadEnter') && ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
// hack: prevent forum editor from screaming when using this keycombo
// can probably be done in a less stupid manner
MszForumEditorAllowClose = true;
elem.form.submit();
2024-01-24 21:53:26 +00:00
ev.preventDefault();
}
});
};
2024-01-24 22:14:42 +00:00
try {
MszSakuya.trackElements($qa('time'));
hljs.highlightAll();
2024-01-24 22:14:42 +00:00
MszEmbed.init(`${location.protocol}//uiharu.${location.host}`);
2024-01-24 22:14:42 +00:00
// only used by the forum posting form
initQuickSubmit();
const forumPostingForm = $q('.js-forum-posting');
if(forumPostingForm !== null)
MszForumEditor(forumPostingForm);
2024-01-24 21:53:26 +00:00
2024-01-24 22:14:42 +00:00
const events = new MszSeasonalEvents;
events.add(new MszChristmas2019EventInfo);
events.dispatch();
2024-01-24 21:53:26 +00:00
2024-01-24 22:14:42 +00:00
await initLoginPage();
2024-01-24 21:53:26 +00:00
2024-01-30 23:47:02 +00:00
MszMessages();
2024-01-24 22:14:42 +00:00
MszEmbed.handle($qa('.js-msz-embed-media'));
} catch(ex) {
console.error(ex);
}
2024-01-24 21:53:26 +00:00
})();