Update ServerDetails.plugin.js

This commit is contained in:
Mirco Wittrien 2023-04-15 17:00:39 +02:00
parent 431828486b
commit b73d962ff9
1 changed files with 84 additions and 52 deletions

View File

@ -2,7 +2,7 @@
* @name ServerDetails * @name ServerDetails
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.1.4 * @version 1.1.5
* @description Shows Server Details in the Server List Tooltip * @description Shows Server Details in the Server List Tooltip
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -64,15 +64,20 @@ module.exports = (_ => {
this.state = {fetchedOwner: false, delayed: false, repositioned: false, forced: false}; this.state = {fetchedOwner: false, delayed: false, repositioned: false, forced: false};
} }
componentDidUpdate() { componentDidUpdate() {
let tooltip = BDFDB.DOMUtils.getParent(BDFDB.dotCN.tooltip, BDFDB.ReactUtils.findDOMNode(this));
if (tooltip) BDFDB.DOMUtils.addClass(tooltip, BDFDB.disCN._serverdetailstooltip);
else if (this.props.tooltipContainer && this.props.tooltipContainer.tooltip) BDFDB.DOMUtils.removeClass(this.props.tooltipContainer.tooltip.firstElementChild, BDFDB.disCN._serverdetailstooltip);
if (_this.settings.amounts.tooltipDelay && this.state.delayed && !this.state.repositioned) { if (_this.settings.amounts.tooltipDelay && this.state.delayed && !this.state.repositioned) {
this.state.repositioned = true; this.state.repositioned = true;
if (this.props.tooltipContainer && this.props.tooltipContainer.tooltip) this.props.tooltipContainer.tooltip.update(); if (this.props.tooltipContainer && this.props.tooltipContainer.tooltip) this.props.tooltipContainer.tooltip.update();
} }
} }
componentDidMount() {
BDFDB.DOMUtils.addClass(BDFDB.DOMUtils.getParent(BDFDB.dotCN.tooltip, BDFDB.ReactUtils.findDOMNode(this)), BDFDB.disCN._serverdetailstooltip);
}
render() { render() {
if (_this.settings.general.onlyShowOnShift) { if (_this.settings.general.onlyShowOnShift) {
let addListener = expanded => { let addListener = expanded => {
if (this.props.tooltipContainer && this.props.tooltipContainer.tooltip) BDFDB.DOMUtils.toggleClass(this.props.tooltipContainer.tooltip.firstElementChild, BDFDB.disCN._serverdetailstooltip, expanded);
let triggered = false, listener = event => { let triggered = false, listener = event => {
if (!this.updater.isMounted(this)) return document.removeEventListener(expanded ? "keyup" : "keydown", listener); if (!this.updater.isMounted(this)) return document.removeEventListener(expanded ? "keyup" : "keydown", listener);
if (triggered) return; if (triggered) return;
@ -102,57 +107,58 @@ module.exports = (_ => {
if (_this.settings.amounts.tooltipDelay && !this.state.delayed) { if (_this.settings.amounts.tooltipDelay && !this.state.delayed) {
BDFDB.TimeUtils.timeout(_ => { BDFDB.TimeUtils.timeout(_ => {
this.state.delayed = true; this.state.delayed = true;
if (this.props.tooltipContainer && this.props.tooltipContainer.tooltip) BDFDB.DOMUtils.addClass(this.props.tooltipContainer.tooltip.firstElementChild, BDFDB.disCN._serverdetailstooltip);
BDFDB.ReactUtils.forceUpdate(this); BDFDB.ReactUtils.forceUpdate(this);
}, this.state.forced ? 0 : (_this.settings.amounts.tooltipDelay * 1000)); }, this.state.forced ? 0 : (_this.settings.amounts.tooltipDelay * 1000));
return null; return null;
} }
let src = this.props.guild.getIconURL(4096, this.props.guild.icon && BDFDB.LibraryModules.IconUtils.isAnimatedIconHash(this.props.guild.icon)); else {
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, { let src = this.props.guild.getIconURL(4096, this.props.guild.icon && BDFDB.LibraryModules.IconUtils.isAnimatedIconHash(this.props.guild.icon));
direction: BDFDB.LibraryComponents.Flex.Direction.VERTICAL, return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
align: BDFDB.LibraryComponents.Flex.Align.CENTER, direction: BDFDB.LibraryComponents.Flex.Direction.VERTICAL,
children: [ align: BDFDB.LibraryComponents.Flex.Align.CENTER,
_this.settings.items.icon && (src ? BDFDB.ReactUtils.createElement("img", { children: [
className: BDFDB.disCN._serverdetailsicon, _this.settings.items.icon && (src ? BDFDB.ReactUtils.createElement("img", {
src: src className: BDFDB.disCN._serverdetailsicon,
}) : BDFDB.ReactUtils.createElement("div", { src: src
className: BDFDB.disCN._serverdetailsicon, }) : BDFDB.ReactUtils.createElement("div", {
children: this.props.guild.acronym className: BDFDB.disCN._serverdetailsicon,
})), children: this.props.guild.acronym
_this.settings.items.owner && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { })),
prefix: BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER, _this.settings.items.owner && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: `${owner ? owner.username : "Unknown"}#${owner ? owner.discriminator : "0000"}` prefix: BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER,
}), string: `${owner ? owner.username : "Unknown"}#${owner ? owner.discriminator : "0000"}`
_this.settings.items.creationDate && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { }),
prefix: _this.labels.creation_date, _this.settings.items.creationDate && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: BDFDB.LibraryComponents.DateInput.format(_this.settings.dates.tooltipDates, BDFDB.LibraryModules.TimestampUtils.extractTimestamp(this.props.guild.id)) prefix: _this.labels.creation_date,
}), string: BDFDB.LibraryComponents.DateInput.format(_this.settings.dates.tooltipDates, BDFDB.LibraryModules.TimestampUtils.extractTimestamp(this.props.guild.id))
_this.settings.items.joinDate && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { }),
prefix: _this.labels.join_date, _this.settings.items.joinDate && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: BDFDB.LibraryComponents.DateInput.format(_this.settings.dates.tooltipDates, this.props.guild.joinedAt) prefix: _this.labels.join_date,
}), string: BDFDB.LibraryComponents.DateInput.format(_this.settings.dates.tooltipDates, this.props.guild.joinedAt)
_this.settings.items.members && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { }),
prefix: BDFDB.LanguageUtils.LanguageStrings.MEMBERS, _this.settings.items.members && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: BDFDB.LibraryStores.GuildMemberCountStore.getMemberCount(this.props.guild.id) prefix: BDFDB.LanguageUtils.LanguageStrings.MEMBERS,
}), string: BDFDB.LibraryStores.GuildMemberCountStore.getMemberCount(this.props.guild.id)
_this.settings.items.boosts && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { }),
prefix: _this.labels.boosts, _this.settings.items.boosts && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: this.props.guild.premiumSubscriberCount prefix: _this.labels.boosts,
}), string: this.props.guild.premiumSubscriberCount
_this.settings.items.channels && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { }),
prefix: BDFDB.LanguageUtils.LanguageStrings.CHANNELS, _this.settings.items.channels && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: BDFDB.LibraryStores.GuildChannelStore.getChannels(this.props.guild.id).count prefix: BDFDB.LanguageUtils.LanguageStrings.CHANNELS,
}), string: BDFDB.LibraryStores.GuildChannelStore.getChannels(this.props.guild.id).count
_this.settings.items.roles && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { }),
prefix: BDFDB.LanguageUtils.LanguageStrings.ROLES, _this.settings.items.roles && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: Object.keys(this.props.guild.roles).length prefix: BDFDB.LanguageUtils.LanguageStrings.ROLES,
}), string: Object.keys(this.props.guild.roles).length
_this.settings.items.language && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, { }),
prefix: BDFDB.LanguageUtils.LanguageStrings.LANGUAGE, _this.settings.items.language && BDFDB.ReactUtils.createElement(GuildDetailsRowComponent, {
string: BDFDB.LanguageUtils.getName(BDFDB.LanguageUtils.languages[this.props.guild.preferredLocale]) || this.props.guild.preferredLocale prefix: BDFDB.LanguageUtils.LanguageStrings.LANGUAGE,
}) string: BDFDB.LanguageUtils.getName(BDFDB.LanguageUtils.languages[this.props.guild.preferredLocale]) || this.props.guild.preferredLocale
].flat(10).filter(n => n) })
}); ].flat(10).filter(n => n)
});
}
} }
}; };
@ -180,7 +186,7 @@ module.exports = (_ => {
onlyShowOnShift: {value: false, description: "Only show the Details Tooltip, while holding 'Shift'"} onlyShowOnShift: {value: false, description: "Only show the Details Tooltip, while holding 'Shift'"}
}, },
items: { items: {
icon: {value: true, description: "GUILD_CREATE_UPLOAD_ICON_LABEL"}, icon: {value: true, description: "icon"},
owner: {value: true, description: "GUILD_OWNER"}, owner: {value: true, description: "GUILD_OWNER"},
creationDate: {value: true, description: "creation_date"}, creationDate: {value: true, description: "creation_date"},
joinDate: {value: true, description: "join_date"}, joinDate: {value: true, description: "join_date"},
@ -251,7 +257,7 @@ module.exports = (_ => {
let settingsItems = []; let settingsItems = [];
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Settings", title: "General",
collapseStates: collapseStates, collapseStates: collapseStates,
children: Object.keys(this.defaults.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { children: Object.keys(this.defaults.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch", type: "Switch",
@ -351,7 +357,6 @@ module.exports = (_ => {
tooltipConfig: Object.assign({ tooltipConfig: Object.assign({
backgroundColor: this.settings.colors.tooltipColor backgroundColor: this.settings.colors.tooltipColor
}, children[index].props.tooltipConfig, { }, children[index].props.tooltipConfig, {
className: !this.settings.amounts.tooltipDelay && BDFDB.disCN._serverdetailstooltip,
type: "right", type: "right",
guild: e.instance.props.guild, guild: e.instance.props.guild,
list: true, list: true,
@ -371,162 +376,189 @@ module.exports = (_ => {
return { return {
boosts: "Бустери", boosts: "Бустери",
creation_date: "Дата на създаване", creation_date: "Дата на създаване",
icon: "Икона",
join_date: "Дата на присъединяване" join_date: "Дата на присъединяване"
}; };
case "da": // Danish case "da": // Danish
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Oprettelsesdato", creation_date: "Oprettelsesdato",
icon: "Ikon",
join_date: "Deltag i dato" join_date: "Deltag i dato"
}; };
case "de": // German case "de": // German
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Erstellungsdatum", creation_date: "Erstellungsdatum",
icon: "Symbol",
join_date: "Beitrittsdatum" join_date: "Beitrittsdatum"
}; };
case "el": // Greek case "el": // Greek
return { return {
boosts: "Ενισχυτές", boosts: "Ενισχυτές",
creation_date: "Ημερομηνία δημιουργίας", creation_date: "Ημερομηνία δημιουργίας",
icon: "Εικόνισμα",
join_date: "Ημερομηνία προσχώρησης" join_date: "Ημερομηνία προσχώρησης"
}; };
case "es": // Spanish case "es": // Spanish
return { return {
boosts: "Impulsores", boosts: "Impulsores",
creation_date: "Fecha de creación", creation_date: "Fecha de creación",
icon: "Icono",
join_date: "Fecha de Ingreso" join_date: "Fecha de Ingreso"
}; };
case "fi": // Finnish case "fi": // Finnish
return { return {
boosts: "Tehostimet", boosts: "Tehostimet",
creation_date: "Luomispäivä", creation_date: "Luomispäivä",
icon: "Kuvake",
join_date: "Liittymispäivä" join_date: "Liittymispäivä"
}; };
case "fr": // French case "fr": // French
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Date de création", creation_date: "Date de création",
icon: "Icône",
join_date: "Date d'inscription" join_date: "Date d'inscription"
}; };
case "hr": // Croatian case "hr": // Croatian
return { return {
boosts: "Pojačala", boosts: "Pojačala",
creation_date: "Datum stvaranja", creation_date: "Datum stvaranja",
icon: "Ikona",
join_date: "Datum pridruživanja" join_date: "Datum pridruživanja"
}; };
case "hu": // Hungarian case "hu": // Hungarian
return { return {
boosts: "Emlékeztetők", boosts: "Emlékeztetők",
creation_date: "Létrehozás dátuma", creation_date: "Létrehozás dátuma",
icon: "Ikon",
join_date: "Csatlakozás dátuma" join_date: "Csatlakozás dátuma"
}; };
case "it": // Italian case "it": // Italian
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Data di creazione", creation_date: "Data di creazione",
icon: "Icona",
join_date: "Data di iscrizione" join_date: "Data di iscrizione"
}; };
case "ja": // Japanese case "ja": // Japanese
return { return {
boosts: "ブースター", boosts: "ブースター",
creation_date: "作成日", creation_date: "作成日",
icon: "アイコン",
join_date: "参加日" join_date: "参加日"
}; };
case "ko": // Korean case "ko": // Korean
return { return {
boosts: "부스터", boosts: "부스터",
creation_date: "제작 일", creation_date: "제작 일",
icon: "상",
join_date: "가입 날짜" join_date: "가입 날짜"
}; };
case "lt": // Lithuanian case "lt": // Lithuanian
return { return {
boosts: "Stiprintuvai", boosts: "Stiprintuvai",
creation_date: "Sukūrimo data", creation_date: "Sukūrimo data",
icon: "Piktograma",
join_date: "Įstojimo data" join_date: "Įstojimo data"
}; };
case "nl": // Dutch case "nl": // Dutch
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Aanmaakdatum", creation_date: "Aanmaakdatum",
icon: "Icoon",
join_date: "Toetredingsdatum" join_date: "Toetredingsdatum"
}; };
case "no": // Norwegian case "no": // Norwegian
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Opprettelsesdato", creation_date: "Opprettelsesdato",
icon: "Ikon",
join_date: "Bli med på dato" join_date: "Bli med på dato"
}; };
case "pl": // Polish case "pl": // Polish
return { return {
boosts: "Boosty", boosts: "Boosty",
creation_date: "Data utworzenia", creation_date: "Data utworzenia",
icon: "Ikona",
join_date: "Data dołączenia" join_date: "Data dołączenia"
}; };
case "pt-BR": // Portuguese (Brazil) case "pt-BR": // Portuguese (Brazil)
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Data de criação", creation_date: "Data de criação",
icon: "Ícone",
join_date: "Data de afiliação" join_date: "Data de afiliação"
}; };
case "ro": // Romanian case "ro": // Romanian
return { return {
boosts: "Amplificatoare", boosts: "Amplificatoare",
creation_date: "Data crearii", creation_date: "Data crearii",
icon: "Pictogramă",
join_date: "Data înscrierii" join_date: "Data înscrierii"
}; };
case "ru": // Russian case "ru": // Russian
return { return {
boosts: "Бустеры", boosts: "Бустеры",
creation_date: "Дата создания", creation_date: "Дата создания",
icon: "Икона",
join_date: "Дате вступления" join_date: "Дате вступления"
}; };
case "sv": // Swedish case "sv": // Swedish
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Skapelsedagen", creation_date: "Skapelsedagen",
icon: "Ikon",
join_date: "Gå med datum" join_date: "Gå med datum"
}; };
case "th": // Thai case "th": // Thai
return { return {
boosts: "บูสเตอร์", boosts: "บูสเตอร์",
creation_date: "วันที่สร้าง", creation_date: "วันที่สร้าง",
icon: "ไอคอน",
join_date: "วันที่เข้าร่วม" join_date: "วันที่เข้าร่วม"
}; };
case "tr": // Turkish case "tr": // Turkish
return { return {
boosts: "Güçlendiriciler", boosts: "Güçlendiriciler",
creation_date: "Oluşturulma tarihi", creation_date: "Oluşturulma tarihi",
icon: "Simge",
join_date: "Üyelik Tarihi" join_date: "Üyelik Tarihi"
}; };
case "uk": // Ukrainian case "uk": // Ukrainian
return { return {
boosts: "Підсилювачі", boosts: "Підсилювачі",
creation_date: "Дата створення", creation_date: "Дата створення",
icon: "Піктограма",
join_date: "Дата приєднання" join_date: "Дата приєднання"
}; };
case "vi": // Vietnamese case "vi": // Vietnamese
return { return {
boosts: "Bộ tăng tốc", boosts: "Bộ tăng tốc",
creation_date: "Ngày thành lập", creation_date: "Ngày thành lập",
icon: "Biểu tượng",
join_date: "Ngày tham gia" join_date: "Ngày tham gia"
}; };
case "zh-CN": // Chinese (China) case "zh-CN": // Chinese (China)
return { return {
boosts: "助推器", boosts: "助推器",
creation_date: "创建日期", creation_date: "创建日期",
icon: "图标",
join_date: "参加日期" join_date: "参加日期"
}; };
case "zh-TW": // Chinese (Taiwan) case "zh-TW": // Chinese (Taiwan)
return { return {
boosts: "助推器", boosts: "助推器",
creation_date: "創建日期", creation_date: "創建日期",
icon: "圖示",
join_date: "參加日期" join_date: "參加日期"
}; };
default: // English default: // English
return { return {
boosts: "Boosts", boosts: "Boosts",
creation_date: "Creation Date", creation_date: "Creation Date",
icon: "Icon",
join_date: "Join Date" join_date: "Join Date"
}; };
} }