Update BadgesEverywhere.plugin.js

This commit is contained in:
Mirco Wittrien 2019-05-31 10:31:01 +02:00
parent 17debffff7
commit 073c22c7e1
1 changed files with 47 additions and 16 deletions

View File

@ -3,7 +3,7 @@
class BadgesEverywhere {
getName () {return "BadgesEverywhere";}
getVersion () {return "1.2.6";}
getVersion () {return "1.2.7";}
getAuthor () {return "DevilBro";}
@ -11,7 +11,7 @@ class BadgesEverywhere {
initConstructor () {
this.changelog = {
"improved":[["Nitro","Nitro badge now shows the subscription date instead of the name (can be turned off)"]]
"added":[["Guild Boost","Now shows the Guild Boost badge for people who boosted on the current server and also shows the actual tier in the member list instead of the general boost badge"]]
};
this.patchModules = {
@ -19,6 +19,8 @@ class BadgesEverywhere {
"MessageUsername":"componentDidMount",
"StandardSidebarView":"componentWillUnmount"
};
this.chatBoostBadge = `<svg name="PremiumGuildSubscriberBadge" class="BE-badge BE-badge-GuildSubscriptionChat ${BDFDB.disCNS.memberpremiumicon + BDFDB.disCN.membericon}" aria-hidden="false" width="24" height="24" viewBox="0 0 8 12"><path d="M4 0L0 4V8L4 12L8 8V4L4 0ZM7 7.59L4 10.59L1 7.59V4.41L4 1.41L7 4.41V7.59Z" fill="currentColor"></path><path d="M2 4.83V7.17L4 9.17L6 7.17V4.83L4 2.83L2 4.83Z" fill="currentColor"></path></svg>`;
this.css = `
.BE-badge {
@ -32,6 +34,9 @@ class BadgesEverywhere {
.BE-badge.BE-badge-chat {
margin-bottom: -3px !important;
}
.BE-badge.BE-badge-list {
margin-bottom: -2px !important;
}
.BE-badge.BE-badge-popout {
margin-bottom: -2px !important;
}
@ -50,7 +55,11 @@ class BadgesEverywhere {
.BE-badge.BE-badge-HypeSquadBalance {width:17px !important; min-width:17px !important;}
.BE-badge.BE-badge-EarlySupporter {width:24px !important; min-width:24px !important;}
.BE-badge.BE-badge-Nitro {width:21px !important; min-width:21px !important;}
.BE-badge.BE-badge-settings {width:30px !important; min-width:30px !important;}`;
.BE-badge.BE-badge-GuildSubscription {width:17px !important; min-width:17px !important;}
.BE-badge.BE-badge-settings {width:30px !important; min-width:30px !important;}
${BDFDB.dotCNS.member + BDFDB.dotCN.memberpremiumicon} {display: none;}`;
this.requestedusers = {};
@ -65,22 +74,26 @@ class BadgesEverywhere {
showNitroDate: {value:true, description:"Show the subscription date for Nitro Badges"}
},
badges: {
"STAFF1": {value:true, name:"Staff", selector:"profileBadgeStaff"},
"PARTNER": {value:true, name:"Partner", selector:"profileBadgePartner"},
"HYPESQUAD": {value:true, name:"HypeSquad", selector:"profileBadgeHypesquad"},
"BUG_HUNTER": {value:true, name:"BugHunter", selector:"profileBadgeBugHunter"},
"MFA_SMS": {value:false, name:"MFASMS", selector:false},
"PREMIUM_PROMO_DISMISSED": {value:false, name:"PROMODISMISSED", selector:false},
"HYPESQUAD_ONLINE_HOUSE_1": {value:true, name:"HypeSquad Bravery", selector:"profileBadgeHypeSquadOnlineHouse1"},
"HYPESQUAD_ONLINE_HOUSE_2": {value:true, name:"HypeSquad Brilliance", selector:"profileBadgeHypeSquadOnlineHouse2"},
"HYPESQUAD_ONLINE_HOUSE_3": {value:true, name:"HypeSquad Balance", selector:"profileBadgeHypeSquadOnlineHouse3"},
"PREMIUM_EARLY_SUPPORTER": {value:true, name:"Early Supporter", selector:"profileBadgeEarlySupporter"},
"NITRO": {value:true, name:"Nitro", selector:"profileBadgePremium"}
"STAFF": {value:true, name:"STAFF_BADGE_TOOLTIP", selector:"profileBadgeStaff"},
"PARTNER": {value:true, name:"PARTNER_BADGE_TOOLTIP", selector:"profileBadgePartner"},
"HYPESQUAD": {value:true, name:"HYPESQUAD_BADGE_TOOLTIP", selector:"profileBadgeHypesquad"},
"BUG_HUNTER": {value:true, name:"BUG_HUNTER_BADGE_TOOLTIP", selector:"profileBadgeBugHunter"},
"MFA_SMS": {value:false, name:null, selector:false},
"PREMIUM_PROMO_DISMISSED": {value:false, name:null, selector:false},
"HYPESQUAD_ONLINE_HOUSE_1": {value:true, name:"HypeSquad Bravery", selector:"profileBadgeHypeSquadOnlineHouse1"},
"HYPESQUAD_ONLINE_HOUSE_2": {value:true, name:"HypeSquad Brilliance", selector:"profileBadgeHypeSquadOnlineHouse2"},
"HYPESQUAD_ONLINE_HOUSE_3": {value:true, name:"HypeSquad Balance", selector:"profileBadgeHypeSquadOnlineHouse3"},
"PREMIUM_EARLY_SUPPORTER": {value:true, name:"EARLY_SUPPORTER_TOOLTIP", selector:"profileBadgeEarlySupporter"},
"NITRO": {value:true, name:"Nitro", selector:"profileBadgePremium"}
},
boosts: {
"GUILD": {value:true, name:"Nitro Guild Boost", selector:"profileGuildSubscriberlvl", types:[1,2,3,4]},
}
};
var UserFlags = BDFDB.WebModules.findByProperties("UserFlags").UserFlags;
for (let flagname in UserFlags) if (this.defaults.badges[flagname]) {
if (BDFDB.LanguageStringsCheck[this.defaults.badges[flagname].name]) this.defaults.badges[flagname].name = BDFDB.LanguageStrings[this.defaults.badges[flagname].name];
this.defaults.badges[UserFlags[flagname]] = this.defaults.badges[flagname];
delete this.defaults.badges[flagname];
}
@ -92,8 +105,9 @@ class BadgesEverywhere {
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
var settings = BDFDB.getAllData(this, "settings");
var badges = BDFDB.getAllData(this, "badges");
var settings = BDFDB.getAllData(this, "settings");
var badges = BDFDB.getAllData(this, "badges");
var boosts = BDFDB.getAllData(this, "boosts");
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
for (let key in settings) {
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + 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>`;
@ -102,6 +116,13 @@ class BadgesEverywhere {
for (let flag in badges) {
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.badges[flag].name}</h3><span class="BE-badges ${BDFDB.disCN.userprofiletopsectionplaying}" style="all: unset !important;"><div class="BE-badge BE-badge-${this.defaults.badges[flag].name.replace(/ /g, "")} BE-badge-settings ${this.BadgeClasses[this.defaults.badges[flag].selector]}"></div></span><span class="BE-badges ${BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;"><div class="BE-badge BE-badge-${this.defaults.badges[flag].name.replace(/ /g, "")} BE-badge-settings ${this.BadgeClasses[this.defaults.badges[flag].selector]}"></div></span><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="badges ${flag}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${badges[flag] ? " checked" : ""}></div></div>`;
}
for (let flag in boosts) {
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.boosts[flag].name}</h3><span class="BE-badges ${BDFDB.disCN.userprofiletopsectionplaying}" style="all: unset !important;">`;
if (Array.isArray(this.defaults.boosts[flag].types)) for (let type of this.defaults.boosts[flag].types) settingshtml += `<div class="BE-badge BE-badge-GuildSubscription} BE-badge-settings ${this.BadgeClasses[this.defaults.boosts[flag].selector + type]}"></div>`;
settingshtml += `</span><span class="BE-badges ${BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;">`
if (Array.isArray(this.defaults.boosts[flag].types)) for (let type of this.defaults.boosts[flag].types) settingshtml += `<div class="BE-badge BE-badge-GuildSubscription} BE-badge-settings ${this.BadgeClasses[this.defaults.boosts[flag].selector + type]}"></div>`;
settingshtml += `</span><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="boosts ${flag}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${boosts[flag] ? " checked" : ""}></div></div>`;
}
settingshtml += `</div></div></div>`;
@ -152,6 +173,9 @@ class BadgesEverywhere {
if (this.started) return;
BDFDB.loadMessage(this);
this.MemberUtils = BDFDB.WebModules.findByProperties("getMembers", "getMember");
this.GuildBoostUtils = BDFDB.WebModules.findByProperties("getTierName", "getUserLevel");
this.LastGuildStore = BDFDB.WebModules.findByProperties("getLastSelectedGuildId");
this.APIModule = BDFDB.WebModules.findByProperties("getAPIBaseURL");
this.DiscordConstants = BDFDB.WebModules.findByProperties("Permissions", "ActivityTypes", "StatusTypes");
this.BadgeClasses = BDFDB.WebModules.findByProperties("profileBadgeStaff","profileBadgePremium");
@ -222,6 +246,7 @@ class BadgesEverywhere {
addToWrapper (info, wrapper, type) {
BDFDB.removeEles(wrapper.querySelectorAll(".BE-badges"));
let badges = BDFDB.getAllData(this, "badges");
let boosts = BDFDB.getAllData(this, "boosts");
let settings = BDFDB.getAllData(this, "settings");
let header = BDFDB.getParentEle(BDFDB.dotCN.userpopoutheader, wrapper);
let badgewrapper = BDFDB.htmlToElement(`<span class="BE-badges ${!settings.useColoredVersion || (header && !BDFDB.containsClass(header, BDFDB.disCN.userpopoutheadernormal)) ? BDFDB.disCN.userprofiletopsectionplaying : BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important; order: 9 !important;"></span>`);
@ -232,6 +257,12 @@ class BadgesEverywhere {
badge.addEventListener("mouseenter", () => {BDFDB.createTooltip(flag == this.nitroflag && settings.showNitroDate ? BDFDB.LanguageStringsFormat("PREMIUM_BADGE_TOOLTIP", new Date(this.loadedusers[info.id].premium_since)) : this.defaults.badges[flag].name, badge, {type:"top", style:"white-space: nowrap; max-width: unset"});});
}
}
let member = this.MemberUtils.getMember(this.LastGuildStore.getGuildId(), info.id);
if (boosts.GUILD && member && member.premiumSince) {
let badge = BDFDB.htmlToElement(`<div class="BE-badge BE-badge-GuildSubscription BE-badge-${type} ${this.BadgeClasses["profileGuildSubscriberlvl" + this.GuildBoostUtils.getUserLevel(member.premiumSince)]}"></div>`);
badgewrapper.appendChild(badge);
badge.addEventListener("mouseenter", () => {BDFDB.createTooltip(BDFDB.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(member.premiumSince)), badge, {type:"top", style:"white-space: nowrap; max-width: unset"});});
}
if (badgewrapper.firstChild) wrapper.insertBefore(badgewrapper, wrapper.querySelector(".owner-tag,.TRE-tag,svg[name=MobileDevice]"));
}
}