2018-10-16 21:30:05 +02:00
|
|
|
//META{"name":"BadgesEverywhere"}*//
|
2018-10-16 21:33:23 +02:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
class BadgesEverywhere {
|
2019-01-11 18:57:49 +01:00
|
|
|
getName () {return "BadgesEverywhere";}
|
|
|
|
|
2019-01-17 23:48:29 +01:00
|
|
|
getVersion () {return "1.2.3";}
|
2019-01-11 18:57:49 +01:00
|
|
|
|
|
|
|
getAuthor () {return "DevilBro";}
|
|
|
|
|
|
|
|
getDescription () {return "Displays Badges (Nitro, HypeSquad, etc...) in the chat/memberlist/userpopout. Thanks for Zerebos' help.";}
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
initConstructor () {
|
2018-12-27 10:16:30 +01:00
|
|
|
this.patchModules = {
|
|
|
|
"NameTag":"componentDidMount",
|
2019-01-15 10:04:23 +01:00
|
|
|
"MessageUsername":"componentDidMount",
|
2018-12-27 10:16:30 +01:00
|
|
|
"StandardSidebarView":"componentWillUnmount"
|
|
|
|
};
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
this.css = `
|
|
|
|
.BE-badge {
|
|
|
|
display: inline-block;
|
2018-12-13 20:36:23 +01:00
|
|
|
height: 17px !important;
|
|
|
|
margin: 0 2px !important;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-13 20:36:23 +01:00
|
|
|
.BE-badge.BE-badge-chat {
|
|
|
|
margin-bottom: -3px !important;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-13 20:36:23 +01:00
|
|
|
.BE-badge.BE-badge-popout {
|
|
|
|
margin-bottom: -2px !important;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-13 20:36:23 +01:00
|
|
|
.BE-badge.BE-badge:first-of-type {
|
|
|
|
margin-left: 5px !important;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-13 20:36:23 +01:00
|
|
|
.BE-badge.BE-badge:last-of-type {
|
|
|
|
margin-right: 5px !important;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-11 20:27:40 +01:00
|
|
|
.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;}
|
|
|
|
.BE-badge.BE-badge-BugHunter {width:17px !important; min-width:17px !important;}
|
|
|
|
.BE-badge.BE-badge-HypeSquadBravery {width:17px !important; min-width:17px !important;}
|
|
|
|
.BE-badge.BE-badge-HypeSquadBrilliance {width:17px !important; min-width:17px !important;}
|
|
|
|
.BE-badge.BE-badge-HypeSquadBalance {width:17px !important; min-width:17px !important;}
|
|
|
|
.BE-badge.BE-badge-EarlySupporter {width:24px !important; min-width:24px !important;}
|
2019-01-11 18:57:49 +01:00
|
|
|
.BE-badge.BE-badge-Nitro {width:21px !important; min-width:21px !important;}
|
|
|
|
.BE-badge.BE-badge-settings {width:30px !important; min-width:30px !important;}`;
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
this.requestedusers = {};
|
|
|
|
this.loadedusers = {};
|
|
|
|
|
|
|
|
this.defaults = {
|
|
|
|
settings: {
|
2018-12-12 00:11:53 +01:00
|
|
|
showInPopout: {value:true, description:"Show Badge in User Popout."},
|
2018-10-11 10:21:26 +02:00
|
|
|
showInChat: {value:true, description:"Show Badge in Chat Window."},
|
|
|
|
showInMemberList: {value:true, description:"Show Badge in Member List."},
|
2018-12-12 00:11:53 +01:00
|
|
|
useColoredVersion: {value:true, description:"Use colored version of the Badges for Chat and Members."}
|
2019-01-11 18:57:49 +01:00
|
|
|
},
|
|
|
|
badges: {
|
|
|
|
1: {value:true, name:"Staff", selector:"profileBadgeStaff"},
|
|
|
|
2: {value:true, name:"Partner", selector:"profileBadgePartner"},
|
|
|
|
4: {value:true, name:"HypeSquad", selector:"profileBadgeHypesquad"},
|
|
|
|
8: {value:true, name:"BugHunter", selector:"profileBadgeBugHunter"},
|
|
|
|
16: {value:false, name:"MFASMS", selector:false},
|
|
|
|
32: {value:false, name:"PROMODISMISSED", selector:false},
|
|
|
|
64: {value:true, name:"HypeSquad Bravery", selector:"profileBadgeHypeSquadOnlineHouse1"},
|
|
|
|
128: {value:true, name:"HypeSquad Brilliance", selector:"profileBadgeHypeSquadOnlineHouse2"},
|
|
|
|
256: {value:true, name:"HypeSquad Balance", selector:"profileBadgeHypeSquadOnlineHouse3"},
|
|
|
|
512: {value:true, name:"Early Supporter", selector:"profileBadgeEarlySupporter"},
|
|
|
|
2048: {value:true, name:"Nitro", selector:"profileBadgePremium"}
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getSettingsPanel () {
|
2019-01-22 11:28:32 +01:00
|
|
|
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
2018-10-11 10:21:26 +02:00
|
|
|
var settings = BDFDB.getAllData(this, "settings");
|
2019-01-11 18:57:49 +01:00
|
|
|
var badges = BDFDB.getAllData(this, "badges");
|
2018-10-11 10:21:26 +02:00
|
|
|
var settingshtml = `<div class="${this.getName()}-settings DevilBro-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.getName()}</div><div class="DevilBro-settings-inner">`;
|
|
|
|
for (let key in settings) {
|
2019-01-11 18:57:49 +01:00
|
|
|
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>`;
|
2018-11-04 11:40:41 +01:00
|
|
|
}
|
|
|
|
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="DevilBro-settings-inner-list">`;
|
2019-01-11 18:57:49 +01:00
|
|
|
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>`;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-11-04 11:40:41 +01:00
|
|
|
|
|
|
|
settingshtml += `</div></div></div>`;
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2019-01-11 18:57:49 +01:00
|
|
|
let settingspanel = BDFDB.htmlToElement(settingshtml);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2019-01-11 18:57:49 +01:00
|
|
|
BDFDB.initElements(settingspanel, this);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
return settingspanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
//legacy
|
|
|
|
load () {}
|
|
|
|
|
|
|
|
start () {
|
2019-01-17 23:48:29 +01:00
|
|
|
var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
|
|
|
|
if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
|
2019-01-17 23:48:29 +01:00
|
|
|
libraryScript.setAttribute("date", performance.now());
|
|
|
|
libraryScript.addEventListener("load", () => {
|
|
|
|
BDFDB.loaded = true;
|
|
|
|
this.initialize();
|
|
|
|
});
|
2018-10-11 10:21:26 +02:00
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
2019-01-17 23:48:29 +01:00
|
|
|
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
2018-10-11 10:21:26 +02:00
|
|
|
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-22 11:05:54 +01:00
|
|
|
if (this.started) return;
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.loadMessage(this);
|
|
|
|
|
2018-12-20 22:54:42 +01:00
|
|
|
this.APIModule = BDFDB.WebModules.findByProperties("getAPIBaseURL");
|
|
|
|
this.DiscordConstants = BDFDB.WebModules.findByProperties("Permissions", "ActivityTypes", "StatusTypes");
|
|
|
|
this.BadgeClasses = BDFDB.WebModules.findByProperties("profileBadgeStaff","profileBadgePremium");
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2019-01-11 18:57:49 +01:00
|
|
|
for (let flag in this.defaults.badges) if (!this.defaults.badges[flag].selector) delete this.defaults.badges[flag];
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2018-12-27 10:16:30 +01:00
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2018-12-27 10:51:39 +01:00
|
|
|
BDFDB.removeEles(".BE-badges");
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.unloadMessage(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 18:57:49 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
// begin of own functions
|
2018-12-27 10:16:30 +01:00
|
|
|
|
|
|
|
processNameTag (instance, wrapper) {
|
|
|
|
if (!wrapper.classList || !instance || !instance.props) return;
|
2019-01-16 11:42:05 +01:00
|
|
|
else if (BDFDB.containsClass(wrapper, BDFDB.disCN.membernametag) && BDFDB.getData("showInMemberList", this, "settings")) {
|
2018-12-27 10:16:30 +01:00
|
|
|
this.addBadges(instance.props.user, wrapper, "list");
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-01-16 11:42:05 +01:00
|
|
|
else if (BDFDB.containsClass(wrapper, BDFDB.disCN.userpopoutheadertag) && BDFDB.getData("showInPopout", this, "settings")) {
|
|
|
|
wrapper = BDFDB.containsClass(wrapper, BDFDB.disCN.userpopoutheadertagwithnickname) && wrapper.previousSibling ? wrapper.previousSibling : wrapper;
|
2018-12-27 10:16:30 +01:00
|
|
|
this.addBadges(instance.props.user, wrapper, "popout");
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-27 10:16:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-15 10:04:23 +01:00
|
|
|
processMessageUsername (instance, wrapper) {
|
|
|
|
let message = BDFDB.getReactValue(instance, "props.message");
|
|
|
|
if (message) {
|
2018-12-27 10:16:30 +01:00
|
|
|
let username = wrapper.querySelector(BDFDB.dotCN.messageusername);
|
2019-01-15 10:04:23 +01:00
|
|
|
if (username && BDFDB.getData("showInChat", this, "settings")) this.addBadges(message.author, wrapper, "chat");
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 10:16:30 +01:00
|
|
|
processStandardSidebarView (instance, wrapper) {
|
2019-01-11 18:57:49 +01:00
|
|
|
if (this.SettingsUpdated) {
|
2019-01-11 19:02:20 +01:00
|
|
|
delete this.SettingsUpdated;
|
2018-12-27 10:16:30 +01:00
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 10:16:30 +01:00
|
|
|
addBadges (info, wrapper, type) {
|
|
|
|
if (!info || info.bot || !wrapper) return;
|
|
|
|
if (!this.requestedusers[info.id]) {
|
2019-01-11 19:01:49 +01:00
|
|
|
this.requestedusers[info.id] = [[wrapper,type]];
|
2018-12-27 10:16:30 +01:00
|
|
|
this.APIModule.get(this.DiscordConstants.Endpoints.USER_PROFILE(info.id)).then(result => {
|
|
|
|
let usercopy = Object.assign({},result.body.user);
|
|
|
|
if (result.body.premium_since) usercopy.flags += 2048;
|
|
|
|
this.loadedusers[info.id] = usercopy;
|
|
|
|
for (let queredobj of this.requestedusers[info.id]) this.addToWrapper(info, queredobj[0], queredobj[1]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (!this.loadedusers[info.id]) {
|
|
|
|
this.requestedusers[info.id].push([wrapper,type]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.addToWrapper(info, wrapper, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addToWrapper (info, wrapper, type) {
|
2019-01-16 11:42:05 +01:00
|
|
|
BDFDB.removeEles(wrapper.querySelectorAll(".BE-badges"));
|
2019-01-11 18:57:49 +01:00
|
|
|
let badges = BDFDB.getAllData(this, "badges");
|
2018-12-27 10:16:30 +01:00
|
|
|
let settings = BDFDB.getAllData(this, "settings");
|
|
|
|
let header = BDFDB.getParentEle(BDFDB.dotCN.userpopoutheader, wrapper);
|
2019-01-17 10:38:58 +01:00
|
|
|
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>`);
|
2019-01-11 18:57:49 +01:00
|
|
|
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>`);
|
2018-12-27 10:16:30 +01:00
|
|
|
badgewrapper.appendChild(badge);
|
2019-01-11 18:57:49 +01:00
|
|
|
badge.addEventListener("mouseenter", () => {BDFDB.createTooltip(this.defaults.badges[flag].name, badge, {"type":type == "list" ? "left" : "top"});});
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-17 10:38:58 +01:00
|
|
|
if (badgewrapper.firstChild) wrapper.insertBefore(badgewrapper, wrapper.querySelector(".owner-tag,.TRE-tag,svg[name=MobileDevice]"));
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-27 12:56:10 +01:00
|
|
|
}
|