BetterDiscordAddons/Plugins/EmojiStatistics/EmojiStatistics.plugin.js

428 lines
15 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"EmojiStatistics","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/EmojiStatistics","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/EmojiStatistics/EmojiStatistics.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class EmojiStatistics {
2019-01-17 23:48:29 +01:00
getName () {return "EmojiStatistics";}
2020-01-22 14:06:39 +01:00
getVersion () {return "2.9.1";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
getDescription () {return "Adds some helpful options to show you more information about emojis and emojiservers.";}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor () {
2019-05-24 15:32:58 +02:00
this.changelog = {
2019-11-28 12:26:23 +01:00
"improved":[["Hover Tooltip","Removed due to discords native ability to display the name and server of an emoji in the new emojipicker"],["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
2019-05-24 15:32:58 +02:00
};
2019-09-04 12:34:02 +02:00
2019-11-14 17:56:26 +01:00
this.patchedModules = {
after: {
EmojiPicker: "render"
}
};
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 = `
2019-11-28 12:26:23 +01:00
.${this.name}-table ${BDFDB.dotCN._emojistatisticsiconcell} {
2019-11-05 00:05:22 +01:00
justify-content: center;
width: 48px;
padding: 0;
2019-05-28 10:41:04 +02:00
}
2019-11-28 12:26:23 +01:00
.${this.name}-table ${BDFDB.dotCN._emojistatisticsnamecell} {
2019-05-28 10:41:04 +02:00
width: 300px;
2018-10-11 10:21:26 +02:00
}
2019-11-28 12:26:23 +01:00
.${this.name}-table ${BDFDB.dotCN._emojistatisticsamountcell} {
2019-11-05 00:05:22 +01:00
width: 120px;
2019-09-18 10:19:56 +02:00
}
2019-01-26 22:45:19 +01:00
2019-11-28 12:26:23 +01:00
${BDFDB.dotCN._emojistatisticsstatisticsbutton} {
2019-11-05 00:05:22 +01:00
width: 28px;
height: 28px;
margin-right: 12px;
2018-10-11 10:21:26 +02:00
cursor: pointer;
2019-11-05 00:05:22 +01:00
}
2019-11-28 18:28:19 +01:00
${BDFDB.dotCNS._emojistatisticsstatisticsbutton + BDFDB.dotCN.emojipickeritem} {
2019-11-05 00:05:22 +01:00
padding: 4px;
flex-shrink: 0;
2018-10-11 10:21:26 +02:00
width: 22px;
2019-11-05 00:05:22 +01:00
height: 22px;
background-repeat: no-repeat;
background-position: 50%;
background-size: 22px 22px;
cursor: pointer;
2018-10-11 10:21:26 +02:00
}`;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.defaults = {
settings: {
enableEmojiStatisticsButton: {value:true, description:"Add a Button in the Emojipicker to open the Statistics Overview."}
}
};
}
getSettingsPanel () {
2020-01-17 19:50:31 +01:00
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
2019-10-22 23:04:35 +02:00
let settings = BDFDB.DataUtils.get(this, "settings");
2019-12-18 16:45:08 +01:00
let settingspanel, settingsitems = [];
2019-11-05 00:05:22 +01:00
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
className: BDFDB.disCN.marginbottom8,
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
2019-12-18 16:45:08 +01:00
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
2018-10-11 10:21:26 +02:00
}
//legacy
load () {}
start () {
2020-01-17 19:50:31 +01:00
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
2020-01-21 12:56:26 +01:00
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
2019-05-26 13:55:26 +02:00
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());
2020-01-14 00:06:07 +01:00
libraryScript.addEventListener("load", _ => {this.initialize();});
2018-10-11 10:21:26 +02:00
document.head.appendChild(libraryScript);
2019-05-26 13:55:26 +02:00
}
2020-01-17 19:50:31 +01:00
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2020-01-14 00:06:07 +01:00
this.startTimeout = setTimeout(_ => {
2019-11-01 10:27:07 +01:00
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
2018-10-11 10:21:26 +02:00
}
initialize () {
2020-01-17 19:50:31 +01:00
if (window.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-11-05 00:05:22 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.forceAllUpdates(this);
2018-10-11 10:21:26 +02:00
}
2019-11-01 10:14:50 +01: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 () {
2020-01-17 19:50:31 +01:00
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-11-05 00:05:22 +01:00
BDFDB.ModuleUtils.forceAllUpdates(this);
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-11-05 00:05:22 +01:00
processEmojiPicker (e) {
this.loadEmojiList();
let settings = BDFDB.DataUtils.get(this, "settings");
if (settings.enableEmojiStatisticsButton) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"DiversitySelector"});
if (index > -1) children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: "Emoji Statistics",
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
2019-11-28 12:26:23 +01:00
className: BDFDB.disCN._emojistatisticsstatisticsbutton,
2019-11-05 00:05:22 +01:00
children: BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.emojipickeritem,
style: {
backgroundImage: "url(/assets/5e9d1e5a1536cf6e2fcaf05f3eaf64dc.svg)"
}
})
}),
onClick: _ => {
2019-02-27 11:20:13 +01:00
this.showEmojiInformationModal();
2019-11-05 00:05:22 +01:00
e.instance.props.closePopout();
}
}));
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
loadEmojiList () {
this.emojiReplicaList = {};
this.emojiToServerList = {};
2019-11-05 00:12:53 +01:00
let guilds = BDFDB.LibraryModules.GuildStore.getGuilds();
for (let id in guilds) {
for (let emoji of BDFDB.LibraryModules.GuildEmojiStore.getGuildEmoji(id)) {
this.emojiToServerList[emoji.url] = {emoji:emoji.allNamesString, server:guilds[id].name};
if (emoji.managed) this.emojiReplicaList[emoji.name] = this.emojiReplicaList[emoji.name] != undefined;
2018-10-11 10:21:26 +02:00
}
}
}
2019-11-05 00:05:22 +01:00
2018-10-11 10:21:26 +02:00
showEmojiInformationModal () {
2019-11-05 00:05:22 +01:00
BDFDB.ModalUtils.open(this, {
size: "LARGE",
header: this.labels.modal_header_text,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Table, {
className: `${this.name}-table`,
stickyHeader: true,
sortData: false,
columns: [{key:"icon", sortkey:"index", cell:"icon"}, {key:"name", cell:"name"}, {key:"total", cell:"amount", reverse:true}, {key:"global", cell:"amount", reverse:true}, {key:"local", cell:"amount", reverse:true}, {key:"copies", cell:"amount", reverse:true}].map(data => {return {
key: data.sortkey || data.key,
sort: true,
reverse: data.reverse,
2020-01-22 14:06:39 +01:00
cellClassName: BDFDB.disCN[`_emojistatistics${data.cell}cell`],
2019-11-05 00:05:22 +01:00
renderHeader: _ => {
return this.labels[`modal_titles${data.key}_text`]
},
render: guilddata => {
if (data.key == "icon") return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.GuildComponents.Guild, {
guild: guilddata[data.key],
menu: false,
tooltip: false
});
else if (data.key == "name") return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, {
children: guilddata[data.key]
});
else return guilddata[data.key]
}
}}),
data: BDFDB.GuildUtils.getAll().map((info, i) => {
let data = {
index: i,
icon: info,
name: info.name,
global: 0,
local: 0,
copies: 0
}
for (let emoji of BDFDB.LibraryModules.GuildEmojiStore.getGuildEmoji(info.id)) {
if (emoji.managed) {
data.global++;
if (this.emojiReplicaList[emoji.name]) data.copies++;
}
else data.local++;
}
data.total = data.global + data.local;
return data;
})
})
2019-01-17 23:48:29 +01:00
});
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
setLabelsByLanguage () {
2019-10-24 11:47:57 +02:00
switch (BDFDB.LanguageUtils.getLanguage().id) {
2018-10-11 10:21:26 +02:00
case "hr": //croatian
return {
modal_header_text: "Statistike o emojima",
modal_titlesicon_text: "Ikona",
modal_titlesname_text: "Naziv poslužitelja",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Cjelokupni",
modal_titlesglobal_text: "Globalno",
modal_titleslocal_text: "Kokalne",
modal_titlescopies_text: "Kopije"
2018-10-11 10:21:26 +02:00
};
case "da": //danish
return {
modal_header_text: "Statistikker af emojis",
modal_titlesicon_text: "Icon",
modal_titlesname_text: "Servernavn",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Total",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Lokal",
modal_titlescopies_text: "Copies"
2018-10-11 10:21:26 +02:00
};
case "de": //german
return {
modal_header_text: "Statistiken über Emojis",
modal_titlesicon_text: "Icon",
modal_titlesname_text: "Servername",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Gesamt",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Lokal",
modal_titlescopies_text: "Kopien"
2018-10-11 10:21:26 +02:00
};
case "es": //spanish
return {
modal_header_text: "Estadísticas de emojis",
modal_titlesicon_text: "Icono",
modal_titlesname_text: "Nombre del servidor",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Total",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Local",
modal_titlescopies_text: "Copias"
2018-10-11 10:21:26 +02:00
};
case "fr": //french
return {
modal_header_text: "Statistiques des emojis",
modal_titlesicon_text: "Icône",
modal_titlesname_text: "Nom du serveur",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Total",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Local",
modal_titlescopies_text: "Copies"
2018-10-11 10:21:26 +02:00
};
case "it": //italian
return {
modal_header_text: "Statistiche di emojis",
modal_titlesicon_text: "Icona",
modal_titlesname_text: "Nome del server",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Totale",
modal_titlesglobal_text: "Globale",
modal_titleslocal_text: "Locale",
modal_titlescopies_text: "Copie"
2018-10-11 10:21:26 +02:00
};
case "nl": //dutch
return {
modal_header_text: "Statistieken van emojis",
modal_titlesicon_text: "Icoon",
modal_titlesname_text: "Servernaam",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Totaal",
modal_titlesglobal_text: "Globaal",
modal_titleslocal_text: "Lokaal",
modal_titlescopies_text: "Kopieën"
2018-10-11 10:21:26 +02:00
};
case "no": //norwegian
return {
modal_header_text: "Statistikk av emojis",
modal_titlesicon_text: "Ikon",
modal_titlesname_text: "Servernavn",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Total",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Lokal",
modal_titlescopies_text: "Kopier"
2018-10-11 10:21:26 +02:00
};
case "pl": //polish
return {
modal_header_text: "Statystyki emoji",
modal_titlesicon_text: "Ikona",
modal_titlesname_text: "Nazwa",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Całkowity",
modal_titlesglobal_text: "Światowy",
modal_titleslocal_text: "Lokalny",
modal_titlescopies_text: "Kopie"
2018-10-11 10:21:26 +02:00
};
case "pt-BR": //portuguese (brazil)
return {
modal_header_text: "Estatísticas de emojis",
modal_titlesicon_text: "Ícone",
modal_titlesname_text: "Nome do servidor",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Total",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Local",
modal_titlescopies_text: "Cópias"
2018-10-11 10:21:26 +02:00
};
case "fi": //finnish
return {
modal_header_text: "Tilastot emojista",
modal_titlesicon_text: "Ikoni",
modal_titlesname_text: "Palvelimen nimi",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Koko",
modal_titlesglobal_text: "Globaali",
modal_titleslocal_text: "Paikallinen",
modal_titlescopies_text: "Kopiot"
2018-10-11 10:21:26 +02:00
};
case "sv": //swedish
return {
modal_header_text: "Statistik för emojis",
modal_titlesicon_text: "Ikon",
modal_titlesname_text: "Servernamn",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Total",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Lokal",
modal_titlescopies_text: "Kopior"
2018-10-11 10:21:26 +02:00
};
case "tr": //turkish
return {
modal_header_text: "Emojis istatistikleri",
modal_titlesicon_text: "Icon",
modal_titlesname_text: "Sunucuadı",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Toplam",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Yerel",
modal_titlescopies_text: "Kopya"
2018-10-11 10:21:26 +02:00
};
case "cs": //czech
return {
modal_header_text: "Statistiky emojis",
modal_titlesicon_text: "Ikona",
modal_titlesname_text: "Název serveru",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Celkový",
modal_titlesglobal_text: "Globální",
modal_titleslocal_text: "Místní",
modal_titlescopies_text: "Kopie"
2018-10-11 10:21:26 +02:00
};
case "bg": //bulgarian
return {
modal_header_text: "Статистика на емотис",
modal_titlesicon_text: "Икона",
modal_titlesname_text: "Име на сървъра",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Oбщо",
modal_titlesglobal_text: "Cветовен",
modal_titleslocal_text: "Mестен",
modal_titlescopies_text: "Копия"
2018-10-11 10:21:26 +02:00
};
case "ru": //russian
return {
modal_header_text: "Статистика emojis",
modal_titlesicon_text: "Значок",
modal_titlesname_text: "Имя сервера",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Всего",
modal_titlesglobal_text: "Mировой",
modal_titleslocal_text: "Местный",
modal_titlescopies_text: "Копии"
2018-10-11 10:21:26 +02:00
};
case "uk": //ukrainian
return {
modal_header_text: "Статистика емідій",
modal_titlesicon_text: "Ікона",
modal_titlesname_text: "Ім'я сервера",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Всього",
modal_titlesglobal_text: "Cвітовий",
modal_titleslocal_text: "Місцевий",
modal_titlescopies_text: "Копії"
2018-10-11 10:21:26 +02:00
};
case "ja": //japanese
return {
modal_header_text: "エモジスの統計",
modal_titlesicon_text: "アイコン",
modal_titlesname_text: "サーバーの名前",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "合計",
modal_titlesglobal_text: "グローバル",
modal_titleslocal_text: "地元",
modal_titlescopies_text: "コピー"
2018-10-11 10:21:26 +02:00
};
case "zh-TW": //chinese (traditional)
return {
modal_header_text: "表情統計",
modal_titlesicon_text: "圖標",
modal_titlesname_text: "服務器名稱",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "總",
modal_titlesglobal_text: "全球",
modal_titleslocal_text: "本地",
modal_titlescopies_text: "副本"
2018-10-11 10:21:26 +02:00
};
case "ko": //korean
return {
modal_header_text: "그림 이모티콘의 통계",
modal_titlesicon_text: "상",
modal_titlesname_text: "서버 이름",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "합계",
modal_titlesglobal_text: "글로벌",
modal_titleslocal_text: "지방의",
modal_titlescopies_text: "사본"
2018-10-11 10:21:26 +02:00
};
default: //default: english
return {
modal_header_text: "Statistics of emojis",
modal_titlesicon_text: "Icon",
modal_titlesname_text: "Servername",
2019-11-05 00:05:22 +01:00
modal_titlestotal_text: "Total",
modal_titlesglobal_text: "Global",
modal_titleslocal_text: "Local",
modal_titlescopies_text: "Copies"
2018-10-11 10:21:26 +02:00
};
}
}
}