BetterDiscordAddons/Plugins/EmojiStatistics/EmojiStatistics.plugin.js

479 lines
18 KiB
JavaScript
Raw Normal View History

2020-10-20 23:25:34 +02:00
/**
* @name EmojiStatistics
2021-03-05 13:26:41 +01:00
* @author DevilBro
2020-10-20 23:25:34 +02:00
* @authorId 278543574059057154
2021-05-27 19:01:15 +02:00
* @version 2.9.8
2021-03-05 13:26:41 +01:00
* @description Shows you an Overview of Emojis and Emoji Servers
2020-10-20 23:25:34 +02:00
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
* @patreon https://www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @website https://mwittrien.github.io/
* @source https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/EmojiStatistics/
2021-03-10 09:17:37 +01:00
* @updateUrl https://mwittrien.github.io/BetterDiscordAddons/Plugins/EmojiStatistics/EmojiStatistics.plugin.js
2020-10-20 23:25:34 +02:00
*/
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
module.exports = (_ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info": {
"name": "EmojiStatistics",
"author": "DevilBro",
2021-05-27 19:01:15 +02:00
"version": "2.9.8",
2021-03-04 12:15:46 +01:00
"description": "Shows you an Overview of Emojis and Emoji Servers"
2021-05-27 19:01:15 +02:00
},
"changeLog": {
"improved": {
"Swapped Position": "Swapped Position with the Diversity Selector"
}
2020-04-25 11:13:18 +02:00
}
2020-09-19 20:49:33 +02:00
};
2020-11-13 19:47:44 +01:00
2021-06-15 13:42:02 +02:00
return (window.Lightcord || window.LightCord) ? class {
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
getDescription () {return "Do not use LightCord!";}
load () {BdApi.alert("Attention!", "By using LightCord you are risking your Discord Account, due to using a 3rd Party Client. Switch to an official Discord Client (https://discord.com/) with the proper BD Injection (https://betterdiscord.app/)");}
start() {}
stop() {}
} : !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
2021-01-06 12:38:36 +01:00
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
2021-02-01 17:13:13 +01:00
getDescription () {return `The Library Plugin needed for ${config.info.name} is missing. Open the Plugin Settings to download it. \n\n${config.info.description}`;}
downloadLibrary () {
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
2021-03-05 13:14:18 +01:00
if (!e && b && r.statusCode == 200) require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => BdApi.showToast("Finished downloading BDFDB Library", {type: "success"}));
2021-03-06 14:59:48 +01:00
else BdApi.alert("Error", "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library");
2021-02-01 17:13:13 +01:00
});
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load () {
2020-11-19 16:51:14 +01:00
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []});
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
2021-01-14 16:14:44 +01:00
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${config.info.name} is missing. Please click "Download Now" to install it.`, {
2020-09-19 20:49:33 +02:00
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
2020-09-20 08:15:13 +02:00
onConfirm: _ => {
delete window.BDFDB_Global.downloadModal;
2021-02-01 17:13:13 +01:00
this.downloadLibrary();
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
});
2020-04-25 11:13:18 +02:00
}
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global.pluginQueue.includes(config.info.name)) window.BDFDB_Global.pluginQueue.push(config.info.name);
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start () {this.load();}
stop () {}
getSettingsPanel () {
2020-11-28 23:12:09 +01:00
let template = document.createElement("template");
2021-01-14 16:14:44 +01:00
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${config.info.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
2021-02-01 17:13:13 +01:00
template.content.firstElementChild.querySelector("a").addEventListener("click", this.downloadLibrary);
2020-11-28 23:12:09 +01:00
return template.content.firstElementChild;
}
2020-10-09 21:09:35 +02:00
} : (([Plugin, BDFDB]) => {
2020-09-19 20:49:33 +02:00
var emojiReplicaList;
2020-10-09 21:09:35 +02:00
return class EmojiStatistics extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad () {
2020-09-19 20:49:33 +02:00
this.patchedModules = {
after: {
EmojiPicker: "type"
}
};
2020-04-25 11:13:18 +02:00
2020-09-19 20:49:33 +02:00
this.css = `
.${this.name}-table ${BDFDB.dotCN._emojistatisticsiconcell} {
justify-content: center;
width: 48px;
padding: 0;
}
.${this.name}-table ${BDFDB.dotCN._emojistatisticsnamecell} {
width: 300px;
}
.${this.name}-table ${BDFDB.dotCN._emojistatisticsamountcell} {
width: 120px;
}
${BDFDB.dotCNS.emojipicker + BDFDB.dotCN.emojipickerheader} {
grid-template-columns: auto 24px 24px;
}
${BDFDB.dotCNS.emojipicker + BDFDB.dotCN._emojistatisticsstatisticsbutton} {
width: 24px;
height: 24px;
2021-05-27 19:01:15 +02:00
grid-column: 2/3;
}
${BDFDB.dotCNS.emojipicker + BDFDB.dotCN.emojipickerdiversityselector} {
2020-09-19 20:49:33 +02:00
grid-column: 3/4;
}
`;
}
2021-01-06 12:38:36 +01:00
onStart () {
2020-09-11 19:31:36 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
2020-04-25 11:13:18 +02:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop () {
2020-09-11 19:31:36 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
2020-04-25 11:13:18 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processEmojiPicker (e) {
this.loadEmojiList();
2020-11-19 16:51:14 +01:00
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "DiversitySelector"});
2021-05-27 19:01:15 +02:00
if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
2021-02-16 17:43:38 +01:00
text: this.labels.modal_header,
2020-09-19 20:49:33 +02:00
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
className: BDFDB.disCN._emojistatisticsstatisticsbutton,
children: BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.emojipickerdiversityemojiitemimage,
2021-02-16 17:43:38 +01:00
style: {backgroundImage: `url(${BDFDB.LibraryModules.EmojiStateUtils.getURL(BDFDB.LibraryModules.EmojiUtils.convertNameToSurrogate("mag_right"))})`}
2020-09-19 20:49:33 +02:00
})
}),
onClick: _ => {
this.showEmojiInformationModal();
e.instance.props.closePopout();
}
}));
}
2019-01-26 22:45:19 +01:00
2021-01-06 12:38:36 +01:00
loadEmojiList () {
2020-09-19 20:49:33 +02:00
emojiReplicaList = {};
let guilds = BDFDB.LibraryModules.GuildStore.getGuilds();
for (let id in guilds) for (let emoji of BDFDB.LibraryModules.GuildEmojiStore.getGuildEmoji(id)) {
if (emoji.managed) emojiReplicaList[emoji.name] = emojiReplicaList[emoji.name] != undefined;
2020-04-25 11:13:18 +02:00
}
2018-10-11 10:21:26 +02:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
showEmojiInformationModal () {
2020-09-19 20:49:33 +02:00
BDFDB.ModalUtils.open(this, {
size: "LARGE",
header: this.labels.modal_header,
2020-09-19 20:49:33 +02:00
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Table, {
className: `${this.name}-table`,
stickyHeader: true,
sortData: false,
2021-02-04 19:11:20 +01:00
columns: [
2021-02-16 17:43:38 +01:00
{key: "icon", cell: "icon", sortKey: "index"},
2021-02-04 19:11:20 +01:00
{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 => ({
key: data.sortKey || data.key,
2020-09-19 20:49:33 +02:00
sort: true,
reverse: data.reverse,
cellClassName: BDFDB.disCN[`_emojistatistics${data.cell}cell`],
2021-02-04 19:11:20 +01:00
renderHeader: _ => this.labels[`modal_titles${data.key}`],
render: item => {
2020-09-19 20:49:33 +02:00
if (data.key == "icon") return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.GuildComponents.Guild, {
2021-02-04 19:11:20 +01:00
guild: item.guild,
2020-09-19 20:49:33 +02:00
menu: false,
tooltip: false
});
else if (data.key == "name") return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, {
2021-02-04 19:11:20 +01:00
children: item.guild.name
2020-09-19 20:49:33 +02:00
});
2021-02-04 19:11:20 +01:00
else return item[data.key];
2020-09-19 20:49:33 +02:00
}
2021-02-04 19:11:20 +01:00
})),
data: BDFDB.LibraryModules.FolderStore.getFlattenedGuilds().map((guild, i) => {
let itemData = {
2020-09-19 20:49:33 +02:00
index: i,
2021-02-04 19:11:20 +01:00
guild: guild,
2020-09-19 20:49:33 +02:00
global: 0,
local: 0,
copies: 0
}
2021-02-16 17:43:38 +01:00
for (let emoji of BDFDB.LibraryModules.GuildEmojiStore.getGuildEmoji(guild.id)) {
2020-09-19 20:49:33 +02:00
if (emoji.managed) {
2021-02-04 19:11:20 +01:00
itemData.global++;
if (emojiReplicaList[emoji.name]) itemData.copies++;
2020-09-19 20:49:33 +02:00
}
2021-02-04 19:11:20 +01:00
else itemData.local++;
2020-04-25 11:13:18 +02:00
}
2021-02-04 19:11:20 +01:00
itemData.total = itemData.global + itemData.local;
return itemData;
2020-09-19 20:49:33 +02:00
})
2020-04-25 11:13:18 +02:00
})
2020-09-19 20:49:33 +02:00
});
2020-04-25 11:13:18 +02:00
}
2020-07-26 16:39:51 +02:00
2021-01-06 12:38:36 +01:00
setLabelsByLanguage () {
2020-09-19 20:49:33 +02:00
switch (BDFDB.LanguageUtils.getLanguage().id) {
case "bg": // Bulgarian
2020-09-19 20:49:33 +02:00
return {
modal_header: "Статистика на емотикони",
modal_titlescopies: "Копия",
modal_titlesglobal: "Глобален",
modal_titlesicon: "Икона",
modal_titleslocal: "Местен",
modal_titlesname: "Име на сървъра",
modal_titlestotal: "Обща сума"
2020-09-19 20:49:33 +02:00
};
case "da": // Danish
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistik over emojis",
modal_titlescopies: "Kopier",
modal_titlesglobal: "Global",
modal_titlesicon: "Ikon",
modal_titleslocal: "Lokal",
modal_titlesname: "Server navn",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
case "de": // German
2020-09-19 20:49:33 +02:00
return {
2021-02-16 17:43:38 +01:00
modal_header: "Emoji Statistiken",
modal_titlescopies: "Kopien",
modal_titlesglobal: "Global",
modal_titlesicon: "Symbol",
modal_titleslocal: "Lokal",
modal_titlesname: "Servername",
modal_titlestotal: "Gesamt"
2020-09-19 20:49:33 +02:00
};
case "el": // Greek
2020-09-19 20:49:33 +02:00
return {
modal_header: "Στατιστικά στοιχεία emoji",
modal_titlescopies: "Αντίγραφα",
modal_titlesglobal: "Παγκόσμια",
modal_titlesicon: "Εικόνισμα",
modal_titleslocal: "Τοπικός",
modal_titlesname: "Ονομα διακομιστή",
modal_titlestotal: "Σύνολο"
2020-09-19 20:49:33 +02:00
};
case "es": // Spanish
2020-09-19 20:49:33 +02:00
return {
modal_header: "Estadísticas de emojis",
modal_titlescopies: "Copias",
modal_titlesglobal: "Global",
modal_titlesicon: "Icono",
modal_titleslocal: "Local",
modal_titlesname: "Nombre del servidor",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
case "fi": // Finnish
2020-09-19 20:49:33 +02:00
return {
modal_header: "Emojien tilastot",
modal_titlescopies: "Kopiot",
modal_titlesglobal: "Maailmanlaajuinen",
modal_titlesicon: "Kuvake",
modal_titleslocal: "Paikallinen",
modal_titlesname: "Palvelimen nimi",
modal_titlestotal: "Kaikki yhteensä"
2020-09-19 20:49:33 +02:00
};
case "fr": // French
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistiques des emojis",
modal_titlescopies: "Copies",
modal_titlesglobal: "Global",
modal_titlesicon: "Icône",
modal_titleslocal: "Local",
modal_titlesname: "Nom du serveur",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
case "hr": // Croatian
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistika emojija",
modal_titlescopies: "Kopije",
modal_titlesglobal: "Globalno",
modal_titlesicon: "Ikona",
modal_titleslocal: "Lokalno",
modal_titlesname: "Ime poslužitelja",
modal_titlestotal: "Ukupno"
2020-09-19 20:49:33 +02:00
};
case "hu": // Hungarian
2020-09-19 20:49:33 +02:00
return {
modal_header: "A hangulatjelek statisztikája",
modal_titlescopies: "Másolatok",
modal_titlesglobal: "Globális",
modal_titlesicon: "Ikon",
modal_titleslocal: "Helyi",
modal_titlesname: "Szerver név",
modal_titlestotal: "Teljes"
2020-09-19 20:49:33 +02:00
};
case "it": // Italian
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistiche di emoji",
modal_titlescopies: "Copie",
modal_titlesglobal: "Globale",
modal_titlesicon: "Icona",
modal_titleslocal: "Locale",
modal_titlesname: "Nome del server",
modal_titlestotal: "Totale"
2020-09-19 20:49:33 +02:00
};
case "ja": // Japanese
2020-09-19 20:49:33 +02:00
return {
modal_header: "絵文字の統計",
modal_titlescopies: "コピー",
modal_titlesglobal: "グローバル",
modal_titlesicon: "アイコン",
modal_titleslocal: "地元",
modal_titlesname: "サーバーの名前",
modal_titlestotal: "合計"
2020-09-19 20:49:33 +02:00
};
case "ko": // Korean
2020-09-19 20:49:33 +02:00
return {
modal_header: "이모티콘 통계",
modal_titlescopies: "사본",
modal_titlesglobal: "글로벌",
modal_titlesicon: "상",
modal_titleslocal: "현지",
modal_titlesname: "서버 이름",
modal_titlestotal: "합계"
2020-09-19 20:49:33 +02:00
};
case "lt": // Lithuanian
2020-09-19 20:49:33 +02:00
return {
modal_header: "Emoji statistika",
modal_titlescopies: "Kopijos",
modal_titlesglobal: "Visuotinis",
modal_titlesicon: "Piktograma",
modal_titleslocal: "Vietinis",
modal_titlesname: "Serverio pavadinimas",
modal_titlestotal: "Iš viso"
2020-09-19 20:49:33 +02:00
};
case "nl": // Dutch
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistieken van emoji's",
modal_titlescopies: "Kopieën",
modal_titlesglobal: "Globaal",
modal_titlesicon: "Icoon",
modal_titleslocal: "Lokaal",
modal_titlesname: "Server naam",
modal_titlestotal: "Totaal"
2020-09-19 20:49:33 +02:00
};
case "no": // Norwegian
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistikk over emoji",
modal_titlescopies: "Kopier",
modal_titlesglobal: "Global",
modal_titlesicon: "Ikon",
modal_titleslocal: "Lokalt",
modal_titlesname: "Server navn",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
case "pl": // Polish
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statystyki emotikonów",
modal_titlescopies: "Kopie",
modal_titlesglobal: "Światowy",
modal_titlesicon: "Ikona",
modal_titleslocal: "Lokalny",
modal_titlesname: "Nazwa serwera",
modal_titlestotal: "Całkowity"
2020-09-19 20:49:33 +02:00
};
case "pt-BR": // Portuguese (Brazil)
2020-09-19 20:49:33 +02:00
return {
modal_header: "Estatísticas de emojis",
modal_titlescopies: "Cópias",
modal_titlesglobal: "Global",
modal_titlesicon: "Ícone",
modal_titleslocal: "Local",
modal_titlesname: "Nome do servidor",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
case "ro": // Romanian
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistici ale emoji-urilor",
modal_titlescopies: "Copii",
modal_titlesglobal: "Global",
modal_titlesicon: "Pictogramă",
modal_titleslocal: "Local",
modal_titlesname: "Numele serverului",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
case "ru": // Russian
2020-09-19 20:49:33 +02:00
return {
modal_header: "Статистика смайлов",
modal_titlescopies: "Копии",
modal_titlesglobal: "Глобальный",
modal_titlesicon: "Икона",
modal_titleslocal: "Местный",
modal_titlesname: "Название сервера",
modal_titlestotal: "Всего"
2020-09-19 20:49:33 +02:00
};
case "sv": // Swedish
2020-09-19 20:49:33 +02:00
return {
modal_header: "Statistik för emojis",
modal_titlescopies: "Kopior",
modal_titlesglobal: "Global",
modal_titlesicon: "Ikon",
modal_titleslocal: "Lokal",
modal_titlesname: "Server namn",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
case "th": // Thai
2020-09-19 20:49:33 +02:00
return {
modal_header: "สถิติของอิโมจิ",
modal_titlescopies: "สำเนา",
modal_titlesglobal: "ทั่วโลก",
modal_titlesicon: "ไอคอน",
modal_titleslocal: "ท้องถิ่น",
modal_titlesname: "ชื่อเซิร์ฟเวอร์",
modal_titlestotal: "รวม"
};
case "tr": // Turkish
return {
modal_header: "Emojilerin istatistikleri",
modal_titlescopies: "Kopya sayısı",
modal_titlesglobal: "Küresel",
modal_titlesicon: "Simge",
modal_titleslocal: "Yerel",
modal_titlesname: "Sunucu adı",
modal_titlestotal: "Toplam"
};
case "uk": // Ukrainian
return {
modal_header: "Статистика смайликів",
modal_titlescopies: "Копії",
modal_titlesglobal: "Глобальний",
modal_titlesicon: "Піктограма",
modal_titleslocal: "Місцеві",
modal_titlesname: "Ім'я сервера",
modal_titlestotal: "Разом"
};
case "vi": // Vietnamese
return {
modal_header: "Thống kê biểu tượng cảm xúc",
modal_titlescopies: "Bản sao",
modal_titlesglobal: "Toàn cầu",
modal_titlesicon: "Biểu tượng",
modal_titleslocal: "Địa phương",
modal_titlesname: "Tên máy chủ",
modal_titlestotal: "Toàn bộ"
};
2021-01-15 17:54:22 +01:00
case "zh-CN": // Chinese (China)
return {
modal_header: "表情符号统计",
modal_titlescopies: "份数",
modal_titlesglobal: "全球",
modal_titlesicon: "图标",
modal_titleslocal: "本地",
modal_titlesname: "服务器名称",
modal_titlestotal: "总"
};
2021-01-15 17:54:22 +01:00
case "zh-TW": // Chinese (Taiwan)
return {
modal_header: "表情符號統計",
modal_titlescopies: "份數",
modal_titlesglobal: "全球",
modal_titlesicon: "圖標",
modal_titleslocal: "本地",
modal_titlesname: "服務器名稱",
modal_titlestotal: "總"
};
default: // English
return {
2021-02-04 19:46:29 +01:00
modal_header: "Emoji Statistics",
modal_titlescopies: "Copies",
modal_titlesglobal: "Global",
modal_titlesicon: "Icon",
modal_titleslocal: "Local",
2021-02-04 19:46:29 +01:00
modal_titlesname: "Server Name",
modal_titlestotal: "Total"
2020-09-19 20:49:33 +02:00
};
}
}
};
2020-10-09 21:09:35 +02:00
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
2020-09-19 20:49:33 +02:00
})();