2019-09-20 22:32:52 +02:00
|
|
|
//META{"name":"TopRoleEverywhere","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/TopRoleEverywhere","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/TopRoleEverywhere/TopRoleEverywhere.plugin.js"}*//
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
class TopRoleEverywhere {
|
2019-01-15 10:04:23 +01:00
|
|
|
getName () {return "TopRoleEverywhere";}
|
|
|
|
|
2019-09-26 10:08:49 +02:00
|
|
|
getVersion () {return "2.9.0";}
|
2019-01-15 10:04:23 +01:00
|
|
|
|
|
|
|
getAuthor () {return "DevilBro";}
|
|
|
|
|
|
|
|
getDescription () {return "Adds the highest role of a user as a tag.";}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-09-04 12:34:02 +02:00
|
|
|
constructor () {
|
2019-07-18 12:18:54 +02:00
|
|
|
this.changelog = {
|
2019-09-26 10:08:49 +02:00
|
|
|
"fixed":[["Padding in Memberlist","Fixed the padding in the memberlist"]]
|
2019-07-18 12:18:54 +02:00
|
|
|
};
|
2019-09-04 12:34:02 +02:00
|
|
|
|
2019-01-02 11:51:56 +01:00
|
|
|
this.patchModules = {
|
2019-08-18 22:15:35 +02:00
|
|
|
"MemberListItem":"componentDidMount",
|
2019-01-15 10:04:23 +01:00
|
|
|
"MessageUsername":"componentDidMount",
|
2019-01-02 11:51:56 +01:00
|
|
|
"StandardSidebarView":"componentWillUnmount"
|
|
|
|
};
|
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-09-12 22:57:39 +02:00
|
|
|
${BDFDB.dotCNS.member + BDFDB.dotCN.namecontainercontent} {
|
|
|
|
overflow: visible;
|
|
|
|
}
|
2019-08-07 09:24:44 +02:00
|
|
|
.TRE-tag {
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
2019-07-27 23:14:00 +02:00
|
|
|
.TRE-tag .role-inner {
|
2019-08-07 09:24:44 +02:00
|
|
|
display: block;
|
2019-07-27 23:14:00 +02:00
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
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: {
|
|
|
|
showInChat: {value:true, description:"Show Tag in Chat Window."},
|
|
|
|
showInMemberList: {value:true, description:"Show Tag in Member List."},
|
|
|
|
useOtherStyle: {value:false, description:"Use other Tagstyle."},
|
|
|
|
includeColorless: {value:false, description:"Include colorless roles."},
|
|
|
|
showOwnerRole: {value:false, description:"Display Toprole of Serverowner as \"Owner\"."},
|
|
|
|
disableForBots: {value:false, description:"Disable Toprole for Bots."},
|
2019-01-17 10:38:58 +01:00
|
|
|
addUserID: {value:false, description:"Add the UserID as a Tag to the Chat Window."},
|
|
|
|
darkIdTag: {value:false, description:"Use a dark version for the UserID-Tag."}
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
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;
|
2019-09-04 12:34:02 +02:00
|
|
|
let settings = BDFDB.getAllData(this, "settings");
|
2019-09-18 10:19:56 +02:00
|
|
|
let settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
|
2018-10-11 10:21:26 +02:00
|
|
|
for (let key in settings) {
|
2019-10-08 11:51:41 +02:00
|
|
|
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + 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-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
settingshtml += `</div></div>`;
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-01-15 10:04:23 +01:00
|
|
|
let settingspanel = BDFDB.htmlToElement(settingshtml);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2019-01-15 10:04:23 +01:00
|
|
|
BDFDB.initElements(settingspanel, this);
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
return settingspanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
//legacy
|
|
|
|
load () {}
|
|
|
|
|
|
|
|
start () {
|
2019-02-04 09:13:15 +01:00
|
|
|
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
|
|
|
|
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
|
2019-05-26 13:55:26 +02:00
|
|
|
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
|
|
|
|
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");
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
|
2019-01-17 23:48:29 +01:00
|
|
|
libraryScript.setAttribute("date", performance.now());
|
2019-05-26 13:55:26 +02: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
|
|
|
this.libLoadTimeout = setTimeout(() => {
|
|
|
|
libraryScript.remove();
|
2019-09-11 12:14:43 +02:00
|
|
|
BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js", (error, response, body) => {
|
2019-05-26 13:55:26 +02:00
|
|
|
if (body) {
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("date", performance.now());
|
|
|
|
libraryScript.innerText = body;
|
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
|
|
|
this.initialize();
|
|
|
|
});
|
|
|
|
}, 15000);
|
|
|
|
}
|
|
|
|
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-22 11:05:54 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (this.started) return;
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.loadMessage(this);
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-01-02 11:51:56 +01:00
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-02-12 21:56:34 +01:00
|
|
|
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 () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-02 11:51:56 +01:00
|
|
|
BDFDB.removeEles(".TRE-tag");
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.unloadMessage(this);
|
|
|
|
}
|
|
|
|
}
|
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-09-11 12:14:43 +02:00
|
|
|
processMemberListItem (instance, wrapper, returnvalue) {
|
2019-07-18 12:18:54 +02:00
|
|
|
if (instance.props && BDFDB.getData("showInMemberList", this, "settings")) {
|
2019-10-09 11:23:07 +02:00
|
|
|
this.addRoleTag(instance.props.user, wrapper.querySelector(BDFDB.dotCN.namecontainername), "list", BDFDB.disCN.bottagmember);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-01-02 11:51:56 +01:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-09-11 12:14:43 +02:00
|
|
|
processMessageUsername (instance, wrapper, returnvalue) {
|
2019-01-15 10:04:23 +01:00
|
|
|
let message = BDFDB.getReactValue(instance, "props.message");
|
|
|
|
if (message) {
|
2019-01-02 11:51:56 +01:00
|
|
|
let username = wrapper.querySelector(BDFDB.dotCN.messageusername);
|
2019-08-06 13:12:31 +02:00
|
|
|
if (username && BDFDB.getData("showInChat", this, "settings")) {
|
|
|
|
let messagegroup = BDFDB.getParentEle(BDFDB.dotCN.messagegroup, wrapper);
|
|
|
|
this.addRoleTag(message.author, username, "chat", BDFDB.containsClass(messagegroup, BDFDB.disCN.messagegroupcozy) ? BDFDB.disCN.bottagmessagecozy : BDFDB.disCN.bottagmessagecompact);
|
|
|
|
}
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-09-11 12:14:43 +02:00
|
|
|
processStandardSidebarView (instance, wrapper, returnvalue) {
|
2019-01-15 10:04:23 +01:00
|
|
|
if (this.SettingsUpdated) {
|
|
|
|
delete this.SettingsUpdated;
|
2019-01-02 11:51:56 +01:00
|
|
|
BDFDB.removeEles(".TRE-tag");
|
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
|
|
|
}
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-08-06 13:12:31 +02:00
|
|
|
addRoleTag (info, username, type, selector) {
|
2019-01-16 11:42:05 +01:00
|
|
|
if (!info || !username) return;
|
|
|
|
BDFDB.removeEles(username.parentElement.querySelectorAll(".TRE-tag"));
|
2019-09-11 12:14:43 +02:00
|
|
|
let guild = BDFDB.LibraryModules.GuildStore.getGuild(BDFDB.LibraryModules.LastGuildStore.getGuildId());
|
2019-01-02 11:51:56 +01:00
|
|
|
let settings = BDFDB.getAllData(this, "settings");
|
|
|
|
if (!guild || info.bot && settings.disableForBots) return;
|
2019-09-11 12:44:02 +02:00
|
|
|
let role = BDFDB.LibraryModules.PermissionRoleUtils.getHighestRole(guild, info.id);
|
2019-01-02 11:51:56 +01:00
|
|
|
if ((role && (role.colorString || settings.includeColorless)) || info.id == 278543574059057154) {
|
|
|
|
let roleColor = role && role.colorString ? BDFDB.colorCONVERT(role.colorString, "RGBCOMP") : [255,255,255];
|
|
|
|
let roleName = role ? role.name : "";
|
|
|
|
let oldwidth;
|
2019-01-17 23:48:29 +01:00
|
|
|
if (type == "list") oldwidth = BDFDB.getRects(username).width;
|
2019-08-06 13:12:31 +02:00
|
|
|
let tag = BDFDB.htmlToElement(`<span class="TRE-tag ${BDFDB.disCN.bottagregular + (selector ? (" " + selector) : "")}"><span class="role-inner"></span></span>`);
|
2019-01-17 10:38:58 +01:00
|
|
|
username.parentElement.insertBefore(tag, username.parentElement.querySelector("svg[name=MobileDevice]"));
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2019-01-02 11:51:56 +01:00
|
|
|
let borderColor = "rgba(" + roleColor[0] + ", " + roleColor[1] + ", " + roleColor[2] + ", 0.5)";
|
|
|
|
let textColor = "rgb(" + roleColor[0] + ", " + roleColor[1] + ", " + roleColor[2] + ")";
|
|
|
|
let bgColor = "rgba(" + roleColor[0] + ", " + roleColor[1] + ", " + roleColor[2] + ", 0.1)";
|
|
|
|
let bgInner = "none";
|
|
|
|
let roleText = roleName;
|
|
|
|
if (settings.useOtherStyle) {
|
|
|
|
borderColor = "transparent";
|
2019-01-16 11:42:05 +01:00
|
|
|
bgColor = "rgb(" + roleColor[0] + ", " + roleColor[1] + ", " + roleColor[2] + ")";
|
2019-01-02 11:51:56 +01:00
|
|
|
textColor = roleColor[0] > 180 && roleColor[1] > 180 && roleColor[2] > 180 ? "black" : "white";
|
|
|
|
}
|
|
|
|
if (info.id == 278543574059057154) {
|
|
|
|
bgColor = "linear-gradient(to right, rgba(255,0,0,0.1), rgba(255,127,0,0.1) , rgba(255,255,0,0.1), rgba(127,255,0,0.1), rgba(0,255,0,0.1), rgba(0,255,127,0.1), rgba(0,255,255,0.1), rgba(0,127,255,0.1), rgba(0,0,255,0.1), rgba(127,0,255,0.1), rgba(255,0,255,0.1), rgba(255,0,127,0.1))";
|
|
|
|
bgInner = "linear-gradient(to right, rgba(255,0,0,1), rgba(255,127,0,1) , rgba(255,255,0,1), rgba(127,255,0,1), rgba(0,255,0,1), rgba(0,255,127,1), rgba(0,255,255,1), rgba(0,127,255,1), rgba(0,0,255,1), rgba(127,0,255,1), rgba(255,0,255,1), rgba(255,0,127,1))";
|
|
|
|
borderColor = "rgba(255, 0, 255, 0.5)";
|
|
|
|
textColor = "transparent";
|
|
|
|
roleText = "Plugin Creator";
|
2018-10-11 10:21:26 +02:00
|
|
|
if (settings.useOtherStyle) {
|
2019-01-02 11:51:56 +01:00
|
|
|
bgColor = "linear-gradient(to right, rgba(180,0,0,1), rgba(180,90,0,1) , rgba(180,180,0,1), rgba(90,180,0,1), rgba(0,180,0,1), rgba(0,180,90,1), rgba(0,180,180,1), rgba(0,90,180,1), rgba(0,0,180,1), rgba(90,0,180,1), rgba(180,0,180,1), rgba(180,0,90,1))";
|
2018-10-11 10:21:26 +02:00
|
|
|
borderColor = "transparent";
|
2019-01-02 11:51:56 +01:00
|
|
|
textColor = "white";
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-17 23:48:29 +01:00
|
|
|
else if (settings.showOwnerRole && info.id == guild.ownerId) roleText = "Owner";
|
|
|
|
BDFDB.addClass(tag, type + "-tag");
|
2019-08-06 18:15:27 +02:00
|
|
|
if (!settings.useOtherStyle) tag.style.setProperty("border", "1px solid " + borderColor, "important");
|
|
|
|
tag.style.setProperty("background", bgColor, "important");
|
2019-08-06 18:16:05 +02:00
|
|
|
tag.style.setProperty("order", 11, "important");
|
2019-01-02 11:51:56 +01:00
|
|
|
let inner = tag.querySelector(".role-inner");
|
2019-08-06 18:15:27 +02:00
|
|
|
inner.style.setProperty("color", textColor, "important");
|
|
|
|
inner.style.setProperty("background-image", bgInner, "important");
|
|
|
|
inner.style.setProperty("-webkit-background-clip", "text", "important");
|
2019-01-02 11:51:56 +01:00
|
|
|
inner.textContent = roleText;
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-01-17 23:48:29 +01:00
|
|
|
if (oldwidth && oldwidth < 100 && BDFDB.getRects(username).width < 100) {
|
2019-09-11 12:44:02 +02:00
|
|
|
tag.style.setProperty("max-width", (BDFDB.getRects(BDFDB.getParentEle(BDFDB.dotCN.namecontainerlayout, username)).width - oldwidth - 15) + "px");
|
2019-01-02 11:51:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == "chat" && settings.addUserID) {
|
2019-01-16 11:42:05 +01:00
|
|
|
let idtag = BDFDB.htmlToElement(this.tagMarkup);
|
2019-01-17 10:02:26 +01:00
|
|
|
username.parentElement.insertBefore(idtag, username.parentElement.querySelector("svg[name=MobileDevice]"));
|
2019-01-02 11:51:56 +01:00
|
|
|
let idColor = settings.darkIdTag ? [33,33,33] : [222,222,222];
|
2019-01-16 11:42:05 +01:00
|
|
|
let idBorderColor = "rgba(" + idColor[0] + ", " + idColor[1] + ", " + idColor[2] + ", 0.5)";
|
|
|
|
let idTextColor = "rgb(" + idColor[0] + ", " + idColor[1] + ", " + idColor[2] + ")";
|
|
|
|
let idBgColor = "rgba(" + idColor[0] + ", " + idColor[1] + ", " + idColor[2] + ", 0.1)";
|
|
|
|
let idBgInner = "none";
|
2019-01-02 11:51:56 +01:00
|
|
|
if (settings.useOtherStyle) {
|
2019-01-16 11:42:05 +01:00
|
|
|
idBorderColor = "transparent";
|
|
|
|
idBgColor = "rgb(" + idColor[0] + ", " + idColor[1] + ", " + idColor[2] + ")";
|
|
|
|
idTextColor = settings.darkIdTag ? "white" : "black";
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-01-17 23:48:29 +01:00
|
|
|
BDFDB.addClass(idtag, "id-tag");
|
2019-08-06 18:15:27 +02:00
|
|
|
idtag.style.setProperty("border", "1px solid " + idBorderColor, "important");
|
|
|
|
idtag.style.setProperty("background", idBgColor, "important");
|
2019-01-17 10:38:58 +01:00
|
|
|
idtag.style.setProperty("order", 12, "important");
|
2019-01-02 11:51:56 +01:00
|
|
|
let idinner = idtag.querySelector(".role-inner");
|
2019-08-06 18:15:27 +02:00
|
|
|
idinner.style.setProperty("color", idTextColor, "important");
|
2019-09-04 12:34:02 +02:00
|
|
|
idinner.style.setProperty("background-image", idBgInner, "important");
|
2019-08-06 18:15:27 +02:00
|
|
|
idinner.style.setProperty("-webkit-background-clip", "text", "important");
|
2019-01-02 11:51:56 +01:00
|
|
|
idinner.textContent = info.id;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|