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-01-01 22:48:56 +01:00
} ;
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 : 48 px ;
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 : 300 px ;
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 : 120 px ;
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 : 28 px ;
height : 28 px ;
margin - right : 12 px ;
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 : 4 px ;
flex - shrink : 0 ;
2018-10-11 10:21:26 +02:00
width : 22 px ;
2019-11-05 00:05:22 +01:00
height : 22 px ;
background - repeat : no - repeat ;
background - position : 50 % ;
background - size : 22 px 22 px ;
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-01 22:48:56 +01:00
}
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 } ;
2019-01-01 22:48:56 +01:00
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
} ;
}
}
}