2018-11-15 22:53:52 +00:00
|
|
|
/// <reference path="User.ts" />
|
2018-11-07 21:00:16 +00:00
|
|
|
/// <reference path="Colour.ts" />
|
|
|
|
/// <reference path="Support.ts" />
|
2018-11-15 22:53:52 +00:00
|
|
|
/// <reference path="Permissions.ts" />
|
2019-06-05 14:56:37 +00:00
|
|
|
/// <reference path="Comments.tsx" />
|
2018-12-09 03:42:38 +00:00
|
|
|
/// <reference path="Common.ts" />
|
2018-12-10 23:43:50 +00:00
|
|
|
/// <reference path="FormUtilities.ts" />
|
2018-12-30 22:07:32 +00:00
|
|
|
/// <reference path="UserRelations.ts" />
|
2019-01-30 09:19:35 +00:00
|
|
|
/// <reference path="Forum/Posting.ts" />
|
2019-02-28 23:06:28 +00:00
|
|
|
/// <reference path="UrlRegistry.ts" />
|
2019-04-17 23:59:33 +00:00
|
|
|
/// <reference path="Forum/Polls.ts" />
|
2018-12-30 22:07:32 +00:00
|
|
|
|
2018-11-06 22:55:05 +00:00
|
|
|
declare const timeago: any;
|
|
|
|
declare const hljs: any;
|
|
|
|
|
2018-11-07 21:00:16 +00:00
|
|
|
let loginFormAvatarTimeout: number = 0;
|
|
|
|
|
2019-06-05 14:56:37 +00:00
|
|
|
function mszCreateElement(type: string, properties: {} = {}, children: any[] = []): HTMLElement {
|
|
|
|
const element: HTMLElement = document.createElement(type);
|
|
|
|
|
|
|
|
if(!Array.isArray(children))
|
|
|
|
children = [children];
|
|
|
|
|
|
|
|
if(arguments.length > 3)
|
|
|
|
for(let i = 3; i < arguments.length; i++)
|
|
|
|
children.push(arguments[i]);
|
|
|
|
|
|
|
|
if(properties)
|
|
|
|
for(let prop in properties) {
|
|
|
|
switch(typeof properties[prop]) {
|
|
|
|
case 'function':
|
|
|
|
element.addEventListener(
|
|
|
|
prop.substring(0, 2) === 'on'
|
|
|
|
? prop.substring(2).toLowerCase()
|
|
|
|
: prop,
|
|
|
|
properties[prop]
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
element.setAttribute(prop, properties[prop]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(children)
|
|
|
|
for(let child in children as []) {
|
|
|
|
switch(typeof children[child]) {
|
|
|
|
case 'string':
|
|
|
|
element.appendChild(document.createTextNode(children[child]));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(children[child] instanceof Element)
|
|
|
|
element.appendChild(children[child]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2018-11-06 22:55:05 +00:00
|
|
|
// Initialisation process.
|
|
|
|
window.addEventListener('load', () => {
|
2019-02-28 23:06:28 +00:00
|
|
|
console.log("%c __ ____\n / |/ (_)______ ______ __ __\n / /|_/ / / ___/ / / /_ / / / / /\n / / / / (__ ) /_/ / / /_/ /_/ /\n/_/ /_/_/____/\\__,_/ /___/\\__,_/\nhttps://github.com/flashwave/misuzu", 'color: #8559a5');
|
|
|
|
|
2019-04-10 18:31:31 +00:00
|
|
|
timeago.render(document.querySelectorAll('time'));
|
2018-11-06 22:55:05 +00:00
|
|
|
hljs.initHighlighting();
|
|
|
|
|
2018-12-10 23:43:50 +00:00
|
|
|
initCSRF();
|
2019-02-28 23:06:28 +00:00
|
|
|
urlRegistryInit();
|
2018-11-15 22:53:52 +00:00
|
|
|
userInit();
|
2018-12-30 22:07:32 +00:00
|
|
|
userRelationsInit();
|
2018-11-07 21:00:16 +00:00
|
|
|
|
|
|
|
const changelogChangeAction: HTMLDivElement = document.querySelector('.changelog__change__action') as HTMLDivElement;
|
|
|
|
|
2019-06-10 17:04:53 +00:00
|
|
|
if(changelogChangeAction && !Support.sidewaysText) {
|
2018-11-07 21:00:16 +00:00
|
|
|
changelogChangeAction.title = "This is supposed to be sideways, but your browser doesn't support that.";
|
|
|
|
}
|
2018-11-06 22:55:05 +00:00
|
|
|
|
2018-11-15 22:02:57 +00:00
|
|
|
const loginForms: HTMLCollectionOf<HTMLFormElement> = document.getElementsByClassName('js-login-form') as HTMLCollectionOf<HTMLFormElement>;
|
2018-11-06 22:55:05 +00:00
|
|
|
|
2019-06-10 17:04:53 +00:00
|
|
|
if(loginForms.length > 0) {
|
|
|
|
for(let i = 0; i < loginForms.length; i++) {
|
2018-11-15 22:02:57 +00:00
|
|
|
const loginForm: HTMLFormElement = loginForms[i],
|
|
|
|
loginAvatar: HTMLElement = loginForm.getElementsByClassName('js-login-avatar')[0] as HTMLElement,
|
|
|
|
loginUsername: HTMLInputElement = loginForm.getElementsByClassName('js-login-username')[0] as HTMLInputElement;
|
2018-11-07 21:00:16 +00:00
|
|
|
|
2018-11-15 22:02:57 +00:00
|
|
|
// Initial bump, in case anything is prefilled.
|
|
|
|
loginFormUpdateAvatar(loginAvatar, loginUsername, true);
|
2018-11-07 21:00:16 +00:00
|
|
|
|
2018-11-15 22:02:57 +00:00
|
|
|
loginUsername.addEventListener('keyup', () => loginFormUpdateAvatar(loginAvatar, loginUsername));
|
|
|
|
}
|
2018-11-07 21:00:16 +00:00
|
|
|
}
|
2018-11-15 22:53:52 +00:00
|
|
|
|
2019-04-10 18:43:33 +00:00
|
|
|
const ctrlSubmit: HTMLCollectionOf<HTMLInputElement> = document.getElementsByClassName('js-ctrl-enter-submit') as HTMLCollectionOf<HTMLInputElement>;
|
|
|
|
|
2019-06-10 17:04:53 +00:00
|
|
|
if(ctrlSubmit.length > 0) {
|
|
|
|
for(let i = 0; i < ctrlSubmit.length; i++) {
|
2019-04-10 18:43:33 +00:00
|
|
|
ctrlSubmit[i].addEventListener('keydown', ev => {
|
2019-06-10 17:04:53 +00:00
|
|
|
if(ev.code === 'Enter' /* i hate this fucking language so much */
|
2019-04-10 18:43:33 +00:00
|
|
|
&& ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
|
2019-06-05 15:28:02 +00:00
|
|
|
// for a hackjob
|
|
|
|
forumPostingCloseOK = true;
|
|
|
|
|
2019-04-10 18:43:33 +00:00
|
|
|
ctrlSubmit[i].form.submit();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:53:52 +00:00
|
|
|
commentsInit();
|
2019-01-30 09:19:35 +00:00
|
|
|
forumPostingInit();
|
2019-04-17 23:59:33 +00:00
|
|
|
forumPollsInit();
|
2018-11-06 22:55:05 +00:00
|
|
|
});
|
2018-11-07 21:00:16 +00:00
|
|
|
|
|
|
|
function loginFormUpdateAvatar(avatarElement: HTMLElement, usernameElement: HTMLInputElement, force: boolean = false): void {
|
2019-06-10 17:04:53 +00:00
|
|
|
if(!force) {
|
|
|
|
if(loginFormAvatarTimeout)
|
2018-11-07 21:00:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
loginFormAvatarTimeout = setTimeout(() => {
|
|
|
|
loginFormUpdateAvatar(avatarElement, usernameElement, true);
|
|
|
|
clearTimeout(loginFormAvatarTimeout);
|
|
|
|
loginFormAvatarTimeout = 0;
|
|
|
|
}, 750);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const xhr: XMLHttpRequest = new XMLHttpRequest;
|
|
|
|
xhr.addEventListener('readystatechange', () => {
|
2019-06-10 17:04:53 +00:00
|
|
|
if(xhr.readyState !== 4)
|
2018-11-07 21:00:16 +00:00
|
|
|
return;
|
|
|
|
|
2019-03-25 20:11:31 +00:00
|
|
|
avatarElement.style.backgroundImage = "url('{0}')".replace('{0}', urlFormat('user-avatar', [
|
|
|
|
{ name: 'user', value: xhr.responseText },
|
|
|
|
{ name: 'res', value: 100 },
|
|
|
|
]));
|
2018-11-07 21:00:16 +00:00
|
|
|
});
|
2019-03-08 00:35:53 +00:00
|
|
|
xhr.open('GET', urlFormat('auth-resolve-user', [{name: 'username', value: encodeURIComponent(usernameElement.value)}]));
|
2018-11-07 21:00:16 +00:00
|
|
|
xhr.send();
|
|
|
|
}
|
2019-01-22 16:38:20 +00:00
|
|
|
|
|
|
|
interface MessageBoxButton {
|
|
|
|
text: string;
|
|
|
|
callback: Function;
|
|
|
|
}
|
|
|
|
|
2019-02-12 16:38:42 +00:00
|
|
|
function messageBox(text: string, title: string = null, buttons: MessageBoxButton[] = []): boolean {
|
2019-06-10 17:04:53 +00:00
|
|
|
if(document.querySelector('.messagebox')) {
|
2019-01-22 16:38:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const element = document.createElement('div');
|
|
|
|
element.className = 'messagebox';
|
|
|
|
|
|
|
|
const container = element.appendChild(document.createElement('div'));
|
|
|
|
container.className = 'container messagebox__container';
|
|
|
|
|
|
|
|
const titleElement = container.appendChild(document.createElement('div')),
|
|
|
|
titleBackground = titleElement.appendChild(document.createElement('div')),
|
|
|
|
titleText = titleElement.appendChild(document.createElement('div'));
|
|
|
|
|
|
|
|
titleElement.className = 'container__title';
|
|
|
|
titleBackground.className = 'container__title__background';
|
|
|
|
titleText.className = 'container__title__text';
|
|
|
|
titleText.textContent = title || 'Information';
|
|
|
|
|
|
|
|
const textElement = container.appendChild(document.createElement('div'));
|
|
|
|
textElement.className = 'container__content';
|
|
|
|
textElement.textContent = text;
|
|
|
|
|
|
|
|
const buttonsContainer = container.appendChild(document.createElement('div'));
|
|
|
|
buttonsContainer.className = 'messagebox__buttons';
|
|
|
|
|
2019-02-12 16:38:42 +00:00
|
|
|
let firstButton = null;
|
|
|
|
|
2019-06-10 17:04:53 +00:00
|
|
|
if(buttons.length < 1) {
|
2019-02-12 16:38:42 +00:00
|
|
|
firstButton = buttonsContainer.appendChild(document.createElement('button'));
|
|
|
|
firstButton.className = 'input__button';
|
|
|
|
firstButton.textContent = 'OK';
|
|
|
|
firstButton.addEventListener('click', () => element.remove());
|
2019-01-22 16:38:20 +00:00
|
|
|
} else {
|
2019-06-10 17:04:53 +00:00
|
|
|
for(let i = 0; i < buttons.length; i++) {
|
2019-01-22 16:38:20 +00:00
|
|
|
let button = buttonsContainer.appendChild(document.createElement('button'));
|
|
|
|
button.className = 'input__button';
|
|
|
|
button.textContent = buttons[i].text;
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
element.remove();
|
|
|
|
buttons[i].callback();
|
|
|
|
});
|
2019-02-12 16:38:42 +00:00
|
|
|
|
2019-06-10 17:04:53 +00:00
|
|
|
if(firstButton === null)
|
2019-02-12 16:38:42 +00:00
|
|
|
firstButton = button;
|
2019-01-22 16:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.appendChild(element);
|
2019-02-12 16:38:42 +00:00
|
|
|
firstButton.focus();
|
|
|
|
return true;
|
|
|
|
}
|