telegram: modularize, add to userpage
This commit is contained in:
@@ -35,10 +35,10 @@ interface formWindow extends Window {
|
||||
|
||||
declare var window: formWindow;
|
||||
|
||||
export interface DiscordConfiguration {
|
||||
export interface ServiceConfiguration {
|
||||
modal: Modal;
|
||||
pin: string;
|
||||
inviteURL: string;
|
||||
inviteURL?: string;
|
||||
pinURL: string;
|
||||
verifiedURL: string;
|
||||
invalidCodeError: string;
|
||||
@@ -52,16 +52,17 @@ export interface DiscordInvite {
|
||||
icon: string;
|
||||
}
|
||||
|
||||
export class Discord {
|
||||
private _conf: DiscordConfiguration;
|
||||
private _pinAcquired = false;
|
||||
private _modalClosed = false;
|
||||
private _waiting = document.getElementById("discord-waiting") as HTMLSpanElement;
|
||||
private _verified = false;
|
||||
export class ServiceLinker {
|
||||
protected _conf: ServiceConfiguration;
|
||||
protected _pinAcquired = false;
|
||||
protected _modalClosed = false;
|
||||
protected _waiting: HTMLSpanElement;
|
||||
protected _verified = false;
|
||||
protected _name: string;
|
||||
|
||||
get verified(): boolean { return this._verified; }
|
||||
|
||||
constructor(conf: DiscordConfiguration) {
|
||||
constructor(conf: ServiceConfiguration) {
|
||||
this._conf = conf;
|
||||
this._conf.modal.onclose = () => {
|
||||
this._modalClosed = true;
|
||||
@@ -69,24 +70,7 @@ export class Discord {
|
||||
};
|
||||
}
|
||||
|
||||
private _getInviteURL = () => _get(this._conf.inviteURL, null, (req: XMLHttpRequest) => {
|
||||
if (req.readyState != 4) return;
|
||||
const inv = req.response as DiscordInvite;
|
||||
const link = document.getElementById("discord-invite") as HTMLAnchorElement;
|
||||
link.href = inv.invite;
|
||||
link.target = "_blank";
|
||||
let innerHTML = `<span class="mr-2">${window.lang.strings("joinTheServer")}</span>`;
|
||||
if (inv.icon != "") {
|
||||
innerHTML += `<span class="img-circle lg mr-4"><img class="img-circle" src="${inv.icon}" width="64" height="64"></span>${window.discordServerName}`;
|
||||
} else {
|
||||
innerHTML += `
|
||||
<span class="shield mr-4 bg-discord"><i class="ri-discord-fill ri-xl text-white"></i></span>${window.discordServerName}
|
||||
`;
|
||||
}
|
||||
link.innerHTML = innerHTML;
|
||||
});
|
||||
|
||||
private _checkVerified = () => {
|
||||
protected _checkVerified = () => {
|
||||
if (this._modalClosed) return;
|
||||
if (!this._pinAcquired) {
|
||||
setTimeout(this._checkVerified, 1500);
|
||||
@@ -105,7 +89,7 @@ export class Discord {
|
||||
this._verified = true;
|
||||
this._waiting.classList.add("~positive");
|
||||
this._waiting.classList.remove("~info");
|
||||
window.notifications.customPositive("discordVerified", "", this._conf.successError);
|
||||
window.notifications.customPositive(this._name + "Verified", "", this._conf.successError);
|
||||
if (this._conf.successFunc) {
|
||||
this._conf.successFunc(false);
|
||||
}
|
||||
@@ -123,18 +107,14 @@ export class Discord {
|
||||
});
|
||||
};
|
||||
|
||||
onclick = () => {
|
||||
if (this._conf.inviteURL != "") {
|
||||
this._getInviteURL();
|
||||
}
|
||||
|
||||
onclick() {
|
||||
toggleLoader(this._waiting);
|
||||
|
||||
this._pinAcquired = false;
|
||||
if (this._conf.pin) {
|
||||
this._pinAcquired = true;
|
||||
this._conf.modal.modal.querySelector(".pin").textContent = this._conf.pin;
|
||||
} else {
|
||||
} else if (this._conf.pinURL) {
|
||||
_get(this._conf.pinURL, null, (req: XMLHttpRequest) => {
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
this._conf.pin = req.response["pin"];
|
||||
@@ -150,3 +130,45 @@ export class Discord {
|
||||
this._checkVerified();
|
||||
}
|
||||
}
|
||||
|
||||
export class Discord extends ServiceLinker {
|
||||
|
||||
constructor(conf: ServiceConfiguration) {
|
||||
super(conf);
|
||||
this._name = "discord";
|
||||
this._waiting = document.getElementById("discord-waiting") as HTMLSpanElement;
|
||||
}
|
||||
|
||||
private _getInviteURL = () => _get(this._conf.inviteURL, null, (req: XMLHttpRequest) => {
|
||||
if (req.readyState != 4) return;
|
||||
const inv = req.response as DiscordInvite;
|
||||
const link = document.getElementById("discord-invite") as HTMLSpanElement;
|
||||
(link.parentElement as HTMLAnchorElement).href = inv.invite;
|
||||
(link.parentElement as HTMLAnchorElement).target = "_blank";
|
||||
let innerHTML = ``;
|
||||
if (inv.icon != "") {
|
||||
innerHTML += `<span class="img-circle lg mr-4"><img class="img-circle" src="${inv.icon}" width="64" height="64"></span>${window.discordServerName}`;
|
||||
} else {
|
||||
innerHTML += `
|
||||
<span class="shield mr-4 bg-discord"><i class="ri-discord-fill ri-xl text-white"></i></span>${window.discordServerName}
|
||||
`;
|
||||
}
|
||||
link.innerHTML = innerHTML;
|
||||
});
|
||||
|
||||
onclick() {
|
||||
if (this._conf.inviteURL != "") {
|
||||
this._getInviteURL();
|
||||
}
|
||||
|
||||
super.onclick();
|
||||
}
|
||||
}
|
||||
|
||||
export class Telegram extends ServiceLinker {
|
||||
constructor(conf: ServiceConfiguration) {
|
||||
super(conf);
|
||||
this._name = "telegram";
|
||||
this._waiting = document.getElementById("telegram-waiting") as HTMLSpanElement;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user