This commit is contained in:
Mirco Wittrien 2019-06-02 14:36:54 +02:00
parent 4cb5f44a54
commit 87549095d9
2 changed files with 59 additions and 34 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
class BadgesEverywhere {
getName () {return "BadgesEverywhere";}
getVersion () {return "1.2.7";}
getVersion () {return "1.2.8";}
getAuthor () {return "DevilBro";}
@ -11,7 +11,7 @@ class BadgesEverywhere {
initConstructor () {
this.changelog = {
"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"]]
"improved":[["Guild Boost","Changed the general guild boost badge in a way that it's displayed everywhere in all servers and added the option to add the badge for the boosting of the current server"]]
};
this.patchModules = {
@ -22,28 +22,36 @@ class BadgesEverywhere {
this.css = `
.BE-badge {
position: relative;
background-size: contain;
background-position: center;
background-repeat: no-repeat;
display: inline-block;
display: inline-flex;
align-items: center;
height: 17px !important;
margin: 0 2px !important;
}
.BE-badge.BE-badge-chat {
margin-bottom: -3px !important;
.BE-badge.BE-badge-list:not(.BE-badge-CurrentGuildBoost) {
top: 1px !important;
}
.BE-badge.BE-badge-list {
margin-bottom: -2px !important;
.BE-badge.BE-badge-chat:not(.BE-badge-CurrentGuildBoost) {
top: 3px !important;
}
.BE-badge.BE-badge-popout {
margin-bottom: -2px !important;
.BE-badge.BE-badge-popout:not(.BE-badge-CurrentGuildBoost) {
top: 3px !important;
}
.BE-badge.BE-badge:first-of-type {
.BE-badge.BE-badge-list.BE-badge-CurrentGuildBoost {
top: -2px !important;
}
.BE-badge:not(.BE-badge-settings):first-of-type {
margin-left: 5px !important;
}
.BE-badge.BE-badge:last-of-type {
.BE-badge:not(.BE-badge-settings):last-of-type {
margin-right: 5px !important;
}
${BDFDB.dotCN.userprofiletopsectionplaying} .BE-badge.BE-badge-CurrentGuildBoost svg {
color: white !important;
}
.BE-badge.BE-badge-Staff {width:17px !important; min-width:17px !important;}
.BE-badge.BE-badge-Partner {width:22px !important; min-width:22px !important;}
.BE-badge.BE-badge-HypeSquad {width:17px !important; min-width:17px !important;}
@ -53,11 +61,12 @@ 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-GuildSubscription {width:17px !important; min-width:17px !important;}
.BE-badge.BE-badge-settings {width:30px !important; min-width:30px !important;}
.BE-badge.BE-badge-NitroGuildBoost {width:17px !important; min-width:17px !important;}
.BE-badge.BE-badge-CurrentGuildBoost {width:14px !important; min-width:14px !important;}
.BE-badge.BE-badge-settings {width:30px !important;min-width:30px !important;}
${BDFDB.dotCNS.member + BDFDB.dotCN.memberpremiumicon} {display: none;}`;
${BDFDB.dotCNS.member + BDFDB.dotCN.memberpremiumicon}:not(.BE-badge-CurrentGuildBoost-inner) {display: none;}`;
this.requestedusers = {};
@ -69,7 +78,7 @@ class BadgesEverywhere {
showInChat: {value:true, description:"Show Badge in Chat Window."},
showInMemberList: {value:true, description:"Show Badge in Member List."},
useColoredVersion: {value:true, description:"Use colored version of the Badges for Chat and Members."},
showNitroDate: {value:true, description:"Show the subscription date for Nitro Badges"}
showNitroDate: {value:true, description:"Show the subscription date for Nitro/Boost Badges"}
},
badges: {
"STAFF": {value:true, name:"STAFF_BADGE_TOOLTIP", selector:"profileBadgeStaff"},
@ -82,10 +91,11 @@ class BadgesEverywhere {
"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"}
"NITRO": {value:true, name:"Nitro", selector:"profileBadgePremium"},
"GUILD_BOOST": {value:true, name:"Nitro Guild Boost", selector:"profileGuildSubscriberlvl", types:[1,2,3,4]},
},
boosts: {
"GUILD": {value:true, name:"Nitro Guild Boost", selector:"profileGuildSubscriberlvl", types:[1,2,3,4]},
indicators: {
"CURRENT_GUILD_BOOST": {value:true, name:"Current Nitro Guild Boost", markup:`<div class="BE-badge BE-badge-CurrentGuildBoost"><svg aria-label="Nitro boosting since May 31, 2019" name="PremiumGuildSubscriberBadge" class="BE-badge-CurrentGuildBoost-inner ${BDFDB.disCNS.memberpremiumicon + BDFDB.disCN.membericon}" aria-hidden="false" width="24" height="24" viewBox="0 0 8 12" style="margin: 0;"><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></div>`},
}
};
@ -98,6 +108,9 @@ class BadgesEverywhere {
this.nitroflag = Math.pow(2, Object.keys(UserFlags).length);
this.defaults.badges[this.nitroflag] = this.defaults.badges.NITRO;
delete this.defaults.badges.NITRO;
this.boostflag = Math.pow(2, Object.keys(UserFlags).length + 1);
this.defaults.badges[this.boostflag] = this.defaults.badges.GUILD_BOOST;
delete this.defaults.badges.GUILD_BOOST;
for (let flag in this.defaults.badges) if (!this.defaults.badges[flag].selector || isNaN(parseInt(flag))) delete this.defaults.badges[flag];
}
@ -105,26 +118,30 @@ class BadgesEverywhere {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
var settings = BDFDB.getAllData(this, "settings");
var badges = BDFDB.getAllData(this, "badges");
var boosts = BDFDB.getAllData(this, "boosts");
var indicators = BDFDB.getAllData(this, "indicators");
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>`;
}
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: 0 0 auto;">Display Badges:</h3></div><div class="BDFDB-settings-inner-list">`;
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>`;
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 BE-badges-settings ${BDFDB.disCN.userprofiletopsectionplaying}" style="all: unset !important;">`;
if (Array.isArray(this.defaults.badges[flag].types)) for (let type of this.defaults.badges[flag].types) settingshtml += `<div class="BE-badge BE-badge-GuildSubscription} ${this.BadgeClasses[this.defaults.badges[flag].selector + type]}"></div>`;
else settingshtml += `<div class="BE-badge ${this.BadgeClasses[this.defaults.badges[flag].selector]}"></div>`;
settingshtml += `</span><span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;">`
if (Array.isArray(this.defaults.badges[flag].types)) for (let type of this.defaults.badges[flag].types) settingshtml += `<div class="BE-badge BE-badge-GuildSubscription} ${this.BadgeClasses[this.defaults.badges[flag].selector + type]}"></div>`;
else settingshtml += `<div class="BE-badge ${this.BadgeClasses[this.defaults.badges[flag].selector]}"></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="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>`;
for (let flag in indicators) {
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.indicators[flag].name}</h3><span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionplaying}" style="all: unset !important;">${this.defaults.indicators[flag].markup}</span><span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;">${this.defaults.indicators[flag].markup}</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="indicators ${flag}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${indicators[flag] ? " checked" : ""}></div></div>`;
}
settingshtml += `</div></div></div>`;
let settingspanel = BDFDB.htmlToElement(settingshtml);
BDFDB.addClass(settingspanel.querySelectorAll(".BE-badge"), "BE-badge-settings");
BDFDB.initElements(settingspanel, this);
@ -229,6 +246,8 @@ class BadgesEverywhere {
let usercopy = Object.assign({},result.body.user);
if (result.body.premium_since) usercopy.flags += this.nitroflag;
usercopy.premium_since = result.body.premium_since;
if (result.body.premium_guild_since) usercopy.flags += this.boostflag;
usercopy.premium_guild_since = result.body.premium_guild_since;
this.loadedusers[info.id] = usercopy;
for (let queredobj of this.requestedusers[info.id]) this.addToWrapper(info, queredobj[0], queredobj[1]);
});
@ -244,22 +263,28 @@ 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 indicators = BDFDB.getAllData(this, "indicators");
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>`);
let badgewrapper = BDFDB.htmlToElement(`<span class="BE-badges BE-badges-${type} ${!settings.useColoredVersion || (header && !BDFDB.containsClass(header, BDFDB.disCN.userpopoutheadernormal)) ? BDFDB.disCN.userprofiletopsectionplaying : BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important; order: 9 !important;"></span>`);
for (let flag in this.defaults.badges) {
if ((this.loadedusers[info.id].flags | flag) == this.loadedusers[info.id].flags && badges[flag]) {
let badge = BDFDB.htmlToElement(`<div class="BE-badge BE-badge-${this.defaults.badges[flag].name.replace(/ /g, "")} BE-badge-${type} ${this.BadgeClasses[this.defaults.badges[flag].selector]}"></div>`);
let badge = BDFDB.htmlToElement(`<div class="BE-badge BE-badge-${this.defaults.badges[flag].name.replace(/ /g, "")} BE-badge-${type} ${this.BadgeClasses[this.defaults.badges[flag].selector + (flag == this.boostflag ? this.GuildBoostUtils.getUserLevel(this.loadedusers[info.id].premium_guild_since) : "")]}"></div>`);
badgewrapper.appendChild(badge);
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"});});
badge.addEventListener("mouseenter", () => {
let text = this.defaults.badges[flag].name;
if (flag == this.nitroflag && settings.showNitroDate) text = BDFDB.LanguageStringsFormat("PREMIUM_BADGE_TOOLTIP", new Date(this.loadedusers[info.id].premium_since));
else if (flag == this.boostflag && settings.showNitroDate) text = BDFDB.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(this.loadedusers[info.id].premium_guild_since));
BDFDB.createTooltip(text, 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>`);
if (indicators.CURRENT_GUILD_BOOST && member && member.premiumSince) {
let badge = BDFDB.htmlToElement(this.defaults.indicators.CURRENT_GUILD_BOOST.markup);
BDFDB.addClass(badge, `BE-badge-${type}`);
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"});});
badge.addEventListener("mouseenter", () => {BDFDB.createTooltip(settings.showNitroDate ? BDFDB.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(member.premiumSince)) : "Boosting current server", 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]"));
}