BetterDiscordAddons/Plugins/CreationDate/CreationDate.plugin.js

360 lines
19 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"CreationDate","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CreationDate","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CreationDate/CreationDate.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class CreationDate {
2019-01-17 23:48:29 +01:00
getName () {return "CreationDate";}
2019-09-24 09:48:01 +02:00
getVersion () {return "1.3.1";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
getDescription () {return "Displays the Creation Date of an Account in the UserPopout and UserModal.";}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor () {
2019-02-22 21:39:10 +01:00
this.changelog = {
2019-09-24 09:48:01 +02:00
"fixed":[["Milliseconds","Milliseconds are now properlly formatted when leading zeros is enabled (9 => 009, 12 => 012)"]]
2019-02-22 21:39:10 +01:00
};
2019-09-04 12:34:02 +02:00
2018-10-11 10:21:26 +02:00
this.labels = {};
2019-01-26 22:45:19 +01:00
this.patchModules = {
"UserPopout":"componentDidMount",
"UserProfile":"componentDidMount"
};
2019-09-04 12:34:02 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
initConstructor () {
2018-10-11 10:21:26 +02:00
this.css = `
2018-11-23 16:58:59 +01:00
${BDFDB.dotCNS.userpopout + BDFDB.dotCN.nametag} {
margin-bottom: 4px;
}
${BDFDB.dotCN.userprofile} .creationDate {
margin-right: 20px;
}
2018-10-11 10:21:26 +02:00
${BDFDB.dotCNS.themelight + BDFDB.dotCN.userpopoutheadernormal} .creationDate {
2019-09-04 12:34:02 +02:00
color: #b9bbbe;
2018-10-11 10:21:26 +02:00
}
2019-01-22 12:22:17 +01:00
${BDFDB.dotCNS.themelight + BDFDB.dotCN.userpopoutheader + BDFDB.notCN.userpopoutheadernormal} .creationDate,
2018-10-11 10:21:26 +02:00
${BDFDB.dotCNS.themedark + BDFDB.dotCN.userpopoutheader} .creationDate {
color: hsla(0,0%,100%,.6);
}
${BDFDB.dotCNS.themelight + BDFDB.dotCN.userprofiletopsectionnormal} .creationDate {
2019-09-04 12:34:02 +02:00
color: hsla(216,4%,74%,.6);
2018-10-11 10:21:26 +02:00
}
2019-01-22 12:22:17 +01:00
${BDFDB.dotCN.themelight} [class*='topSection']${BDFDB.notCN.userprofiletopsectionnormal} .creationDate,
2018-10-11 10:21:26 +02:00
${BDFDB.dotCN.themedark} [class*='topSection'] .creationDate {
color: hsla(0,0%,100%,.6);
}`;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.defaults = {
settings: {
addInUserPopout: {value:true, description:"Add in User Popouts:"},
2019-03-31 09:54:48 +02:00
addInUserProfil: {value:true, description:"Add in User Profile Modal:"},
2019-02-22 21:39:10 +01:00
displayTime: {value:true, description:"Display the Time in the Timestamp:"},
displayDate: {value:true, description:"Display the Date in the Timestamp:"},
cutSeconds: {value:false, description:"Cut off Seconds of the Time:"},
forceZeros: {value:false, description:"Force leading Zeros:"},
otherOrder: {value:false, description:"Show the Time before the Date:"}
2018-10-11 10:21:26 +02:00
},
choices: {
creationDateLang: {value:"$discord", description:"Creation Date Format:"}
2019-02-22 21:39:10 +01:00
},
formats: {
ownFormat: {value:"$hour:$minute:$second, $day.$month.$year", description:"Own Format:"}
2018-10-11 10:21:26 +02:00
}
};
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
getSettingsPanel () {
2019-01-22 11:28:32 +01:00
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
2019-10-22 19:49:57 +02:00
let settings = BDFDB.DataUtils.get(this, "settings");
let choices = BDFDB.DataUtils.get(this, "choices");
let formats = BDFDB.DataUtils.get(this, "formats");
2019-10-09 14:18:28 +02:00
let settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.titlesize18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
2018-10-11 10:21:26 +02:00
for (let key in settings) {
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="settings ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${settings[key] ? " checked" : ""}></div></div>`;
2018-10-11 10:21:26 +02:00
}
for (let key in choices) {
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCN.flexchild}" style="flex: 0 0 30%;">${this.defaults.choices[key].description}</h3>${BDFDB.createSelectMenu(this.createSelectChoice(choices[key]), choices[key], key)}</div>`;
2019-02-22 21:39:10 +01:00
}
for (let key in formats) {
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCN.flexchild}" style="flex: 0 0 30%;">${this.defaults.formats[key].description}</h3><div class="${BDFDB.disCNS.inputwrapper + BDFDB.disCNS.vertical + BDFDB.disCNS.flex2 + BDFDB.disCN.directioncolumn}" style="flex: 1 1 auto;"><input type="text" option="${key}" value="${formats[key]}" placeholder="${this.defaults.formats[key].value}" class="${BDFDB.disCNS.inputdefault + BDFDB.disCNS.input + BDFDB.disCN.titlesize16}"></div></div>`;
2018-10-11 10:21:26 +02:00
}
2019-10-22 20:16:05 +02:00
let infoHidden = BDFDB.DataUtils.load(this, "hideInfo", "hideInfo");
2019-10-08 11:51:41 +02:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCNS.cursorpointer} toggle-info" style="flex: 1 1 auto;"><svg class="toggle-infoarrow${infoHidden ? (" " + BDFDB.disCN.directionright) : ""}" width="12" height="12" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M7 10L12 15 17 10"></path></svg><div class="toggle-infotext" style="flex: 1 1 auto;">Information</div></div>`;
2019-04-18 09:28:20 +02:00
settingshtml += `<div class="BDFDB-settings-inner-list info-container" ${infoHidden ? "style='display:none;'" : ""}>`;
2019-02-22 21:39:10 +01:00
settingshtml += `<div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$hour will be replaced with the current hour</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$minute will be replaced with the current minutes</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$second will be replaced with the current seconds</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$msecond will be replaced with the current milliseconds</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$timemode will change $hour to a 12h format and will be replaced with AM/PM</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$year will be replaced with the current year</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$month will be replaced with the current month</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$day will be replaced with the current day</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$monthnameL will be replaced with the monthname in long format based on the Discord Language</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$monthnameS will be replaced with the monthname in short format based on the Discord Language</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$weekdayL will be replaced with the weekday in long format based on the Discord Language</div><div class="${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">$weekdayS will be replaced with the weekday in short format based on the Discord Language</div>`;
2018-10-11 10:21:26 +02:00
settingshtml += `</div></div>`;
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
2018-10-11 10:21:26 +02:00
2019-01-17 23:48:29 +01:00
BDFDB.initElements(settingspanel, this);
2018-10-11 10:21:26 +02:00
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".settings-switch", () => {setImmediate(() => {this.updateSettingsPanel(settingspanel);})});
BDFDB.ListenerUtils.add(this, settingspanel, "keyup", BDFDB.dotCN.input, () => {this.saveInputs(settingspanel);});
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".toggle-info", e => {this.toggleInfo(e.currentTarget);});
BDFDB.ListenerUtils.add(this, settingspanel, "click", BDFDB.dotCN.selectcontrol, e => {
2019-09-24 12:48:53 +02:00
BDFDB.openDropdownMenu(e, this.saveSelectChoice.bind(this), this.createSelectChoice.bind(this), this.languages);
2019-04-27 18:45:01 +02:00
});
2018-10-11 10:21:26 +02:00
return settingspanel;
}
//legacy
load () {}
start () {
2019-02-04 09:13:15 +01:00
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
2019-05-26 13:55:26 +02:00
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
2018-10-11 10:21:26 +02:00
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
2019-05-26 13:55:26 +02:00
libraryScript.setAttribute("id", "BDFDBLibraryScript");
2018-10-11 10:21:26 +02:00
libraryScript.setAttribute("type", "text/javascript");
2019-10-18 10:56:41 +02:00
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
2019-01-17 23:48:29 +01:00
libraryScript.setAttribute("date", performance.now());
2019-05-26 13:55:26 +02:00
libraryScript.addEventListener("load", () => {this.initialize();});
2018-10-11 10:21:26 +02:00
document.head.appendChild(libraryScript);
}
2019-01-17 23:48:29 +01:00
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2018-10-11 10:21:26 +02:00
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
}
initialize () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-01-22 11:05:54 +01:00
if (this.started) return;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.init(this);
2019-09-04 12:34:02 +02:00
2019-10-22 18:55:25 +02:00
this.languages = Object.assign({"own":{name:"Own",id:"own",integrated:false,dic:false}}, BDFDB.LanguageUtils.languages);
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.forceAllUpdates(this);
2018-10-11 10:21:26 +02:00
}
2019-10-22 18:55:25 +02:00
else console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
2018-10-11 10:21:26 +02:00
}
stop () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(".creationDate");
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.clear(this);
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2019-02-22 21:39:10 +01:00
saveInputs (settingspanel) {
let formats = {};
for (let input of settingspanel.querySelectorAll(BDFDB.dotCN.input)) {
formats[input.getAttribute("option")] = input.value;
}
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.save(formats, this, "formats");
2019-02-22 21:39:10 +01:00
this.updateSettingsPanel(settingspanel);
}
updateSettingsPanel (settingspanel) {
2019-10-22 19:49:57 +02:00
let choices = BDFDB.DataUtils.get(this, "choices");
2019-02-22 21:39:10 +01:00
for (let key in choices) {
settingspanel.querySelector(`${BDFDB.dotCN.select}[type='${key}'] .languageTimestamp`).innerText = this.getTimestamp(this.languages[choices[key]].id);
}
}
toggleInfo (ele) {
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.toggleClass(ele.querySelector("svg"), BDFDB.disCN.directionright);
BDFDB.DOMUtils.toggle(ele.nextElementSibling);
BDFDB.DataUtils.save(BDFDB.DOMUtils.isHidden(ele.nextElementSibling), this, "hideInfo", "hideInfo");
2019-02-22 21:39:10 +01:00
}
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
saveSelectChoice (selectWrap, type, choice) {
if (type && choice) {
selectWrap.querySelector(".languageName").innerText = this.languages[choice].name;
selectWrap.querySelector(".languageTimestamp").innerText = this.getTimestamp(this.languages[choice].id);
2019-10-22 20:16:05 +02:00
BDFDB.DataUtils.save(choice, this, "choices", type);
2018-10-11 10:21:26 +02:00
}
2019-04-27 18:45:01 +02:00
}
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
createSelectChoice (choice) {
2019-09-11 12:14:43 +02:00
return `<div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCNS.weightnormal + BDFDB.disCN.cursorpointer} languageName" style="flex: 1 1 42%; padding: 0;">${this.languages[choice].name}</div><div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCNS.weightlight + BDFDB.disCN.cursorpointer} languageTimestamp" style="flex: 1 1 58%; padding: 0;">${this.getTimestamp(this.languages[choice].id)}</div>`;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processUserPopout (instance, wrapper, returnvalue) {
2019-10-22 20:16:05 +02:00
if (instance.props && instance.props.user && BDFDB.DataUtils.get(this, "settings", "addInUserPopout")) {
this.addCreationDate(instance.props.user, wrapper.querySelector(BDFDB.dotCN.userpopoutheadertext), wrapper.parentElement);
}
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processUserProfile (instance, wrapper, returnvalue) {
2019-10-22 20:16:05 +02:00
if (instance.props && instance.props.user && BDFDB.DataUtils.get(this, "settings", "addInUserProfil")) {
this.addCreationDate(instance.props.user, wrapper.querySelector(BDFDB.dotCN.userprofileheaderinfo), null);
}
}
2019-01-26 22:45:19 +01:00
addCreationDate (info, container, popout) {
2018-12-30 14:25:55 +01:00
if (!info || !container || container.querySelector(".creationDate")) return;
2019-06-20 10:39:11 +02:00
let addTimestamp = (timestamp) => {
if (document.contains(container)) {
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(container.querySelectorAll(".creationDate"));
2019-10-22 18:55:25 +02:00
if (BDFDB.ObjectUtils.is(container.CreationDateObserver)) container.CreationDateObserver.disconnect();
2019-10-22 20:16:05 +02:00
let choice = BDFDB.DataUtils.get(this, "choices", "creationDateLang");
2019-06-20 10:39:11 +02:00
let nametag = container.querySelector(BDFDB.dotCN.nametag);
2019-10-23 11:10:01 +02:00
container.insertBefore(BDFDB.DOMUtils.create(`<div class="creationDate BDFDB-textscrollwrapper ${BDFDB.disCN.textrow}" style="max-width: ${BDFDB.DOMUtils.getRects(BDFDB.DOMUtils.getParent(popout ? BDFDB.dotCN.userpopoutheader : BDFDB.dotCN.userprofileheaderinfo, container)).width - 20}px !important; order: 8 !important;"><div class="BDFDB-textscroll">${this.labels.createdat_text.replace("{{time}}", this.getTimestamp(this.languages[choice].id, timestamp))}</div></div>`), nametag ? nametag.nextSibling : null);
2019-06-20 10:39:11 +02:00
BDFDB.initElements(container, this);
if (popout && popout.style.transform.indexOf("translateY(-1") == -1) {
2019-10-23 11:10:01 +02:00
let arect = BDFDB.DOMUtils.getRects(document.querySelector(BDFDB.dotCN.appmount)), prect = BDFDB.DOMUtils.getRects(popout);
2019-06-20 10:39:11 +02:00
popout.style.setProperty("top", (prect.y + prect.height > arect.height ? (arect.height - prect.height) : prect.y) + "px");
}
container.CreationDateObserver = new MutationObserver((changes, _) => {changes.forEach((change, i) => {change.addedNodes.forEach((node) => {
2019-10-23 11:10:01 +02:00
if (node && BDFDB.DOMUtils.containsClass(node, BDFDB.disCN.nametag)) addTimestamp(timestamp);
2019-06-20 10:39:11 +02:00
});});});
container.CreationDateObserver.observe(container, {childList: true, subtree:true});
}
};
addTimestamp(info.createdAt);
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-02-22 21:39:10 +01:00
getTimestamp (languageid, time) {
let timeobj = time ? time : new Date();
if (typeof time == "string") timeobj = new Date(time);
if (timeobj.toString() == "Invalid Date") timeobj = new Date(parseInt(time));
if (timeobj.toString() == "Invalid Date") return;
2019-10-22 19:49:57 +02:00
let settings = BDFDB.DataUtils.get(this, "settings"), timestring = "";
2019-02-22 21:39:10 +01:00
if (languageid != "own") {
let timestamp = [];
if (settings.displayDate) timestamp.push(timeobj.toLocaleDateString(languageid));
if (settings.displayTime) timestamp.push(settings.cutSeconds ? this.cutOffSeconds(timeobj.toLocaleTimeString(languageid)) : timeobj.toLocaleTimeString(languageid));
if (settings.otherOrder) timestamp.reverse();
timestring = timestamp.length > 1 ? timestamp.join(", ") : (timestamp.length > 0 ? timestamp[0] : "");
if (timestring && settings.forceZeros) timestring = this.addLeadingZeros(timestring);
}
else {
2019-10-22 20:16:05 +02:00
let ownformat = BDFDB.DataUtils.get(this, "formats", "ownFormat");
2019-02-22 21:39:10 +01:00
languageid = BDFDB.getDiscordLanguage().id;
let hour = timeobj.getHours(), minute = timeobj.getMinutes(), second = timeobj.getSeconds(), msecond = timeobj.getMilliseconds(), day = timeobj.getDate(), month = timeobj.getMonth()+1, timemode = "";
if (ownformat.indexOf("$timemode") > -1) {
timemode = hour >= 12 ? "PM" : "AM";
hour = hour % 12;
hour = hour ? hour : 12;
}
timestring = ownformat
.replace("$hour", settings.forceZeros && hour < 10 ? "0" + hour : hour)
.replace("$minute", minute < 10 ? "0" + minute : minute)
.replace("$second", second < 10 ? "0" + second : second)
2019-09-24 09:48:01 +02:00
.replace("$msecond", settings.forceZeros ? (msecond < 10 ? "00" + msecond : (msecond < 100 ? "0" + msecond : msecond)) : msecond)
2019-02-22 21:39:10 +01:00
.replace("$timemode", timemode)
.replace("$weekdayL", timeobj.toLocaleDateString(languageid,{weekday: "long"}))
.replace("$weekdayS", timeobj.toLocaleDateString(languageid,{weekday: "short"}))
.replace("$monthnameL", timeobj.toLocaleDateString(languageid,{month: "long"}))
.replace("$monthnameS", timeobj.toLocaleDateString(languageid,{month: "short"}))
.replace("$day", settings.forceZeros && day < 10 ? "0" + day : day)
.replace("$month", settings.forceZeros && month < 10 ? "0" + month : month)
.replace("$year", timeobj.getFullYear());
}
2018-10-11 10:21:26 +02:00
return timestring;
}
2019-01-26 22:45:19 +01:00
2019-02-22 21:39:10 +01:00
cutOffSeconds (timestring) {
return timestring.replace(/(.*):(.*):(.{2})(.*)/, "$1:$2$4");
}
2018-10-11 10:21:26 +02:00
addLeadingZeros (timestring) {
let chararray = timestring.split("");
let numreg = /[0-9]/;
for (let i = 0; i < chararray.length; i++) {
2018-10-11 10:21:26 +02:00
if (!numreg.test(chararray[i-1]) && numreg.test(chararray[i]) && !numreg.test(chararray[i+1])) chararray[i] = "0" + chararray[i];
}
2019-02-22 21:39:10 +01:00
2018-10-11 10:21:26 +02:00
return chararray.join("");
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
setLabelsByLanguage () {
switch (BDFDB.getDiscordLanguage().id) {
case "hr": //croatian
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Izrađen {{time}}"
2018-10-11 10:21:26 +02:00
};
case "da": //danish
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Oprettet den {{time}}"
2018-10-11 10:21:26 +02:00
};
case "de": //german
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Erstellt am {{time}}"
2018-10-11 10:21:26 +02:00
};
case "es": //spanish
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Creado el {{time}}"
2018-10-11 10:21:26 +02:00
};
case "fr": //french
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Créé le {{time}}"
2018-10-11 10:21:26 +02:00
};
case "it": //italian
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Creato il {{time}}"
2018-10-11 10:21:26 +02:00
};
case "nl": //dutch
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Gemaakt op {{time}}"
2018-10-11 10:21:26 +02:00
};
case "no": //norwegian
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Opprettet på {{time}}"
2018-10-11 10:21:26 +02:00
};
case "pl": //polish
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Utworzono {{time}}"
2018-10-11 10:21:26 +02:00
};
case "pt-BR": //portuguese (brazil)
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Criado em {{time}}"
2018-10-11 10:21:26 +02:00
};
case "fi": //finnish
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Luotu {{time}}"
2018-10-11 10:21:26 +02:00
};
case "sv": //swedish
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Skapat den {{time}}"
2018-10-11 10:21:26 +02:00
};
case "tr": //turkish
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Oluşturma tarihi {{time}}"
2018-10-11 10:21:26 +02:00
};
case "cs": //czech
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Vytvořeno dne {{time}}"
2018-10-11 10:21:26 +02:00
};
case "bg": //bulgarian
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Създадена на {{time}}"
2018-10-11 10:21:26 +02:00
};
case "ru": //russian
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Создано {{time}}"
2018-10-11 10:21:26 +02:00
};
case "uk": //ukrainian
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Створено {{time}}"
2018-10-11 10:21:26 +02:00
};
case "ja": //japanese
return {
2019-04-04 21:16:49 +02:00
createdat_text: "{{time}} 作成日"
2018-10-11 10:21:26 +02:00
};
case "zh-TW": //chinese (traditional)
return {
2019-04-04 21:16:49 +02:00
createdat_text: "創建於 {{time}}"
2018-10-11 10:21:26 +02:00
};
case "ko": //korean
return {
2019-04-04 21:16:49 +02:00
createdat_text: "{{time}} 생성 일"
2018-10-11 10:21:26 +02:00
};
default: //default: english
return {
2019-04-04 21:16:49 +02:00
createdat_text: "Created on {{time}}"
2018-10-11 10:21:26 +02:00
};
}
}
}