fixes
This commit is contained in:
parent
e448cd338f
commit
cdeaac0705
File diff suppressed because one or more lines are too long
|
@ -1,355 +1,363 @@
|
|||
//META{"name":"BadgesEverywhere","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BadgesEverywhere","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/BadgesEverywhere/BadgesEverywhere.plugin.js"}*//
|
||||
|
||||
class BadgesEverywhere {
|
||||
getName () {return "BadgesEverywhere";}
|
||||
|
||||
getVersion () {return "1.5.1";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Displays Badges (Nitro, HypeSquad, etc...) in the chat/memberlist/userpopout.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Bug Hunter Badgess & Boost Ranks","Fixed badges for the new rans for the bug hunter badge and guild boost badge"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MemberListItem: "render",
|
||||
MessageUsername: "render",
|
||||
UserPopout: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
.BE-badge {
|
||||
position: relative;
|
||||
background-size: contain;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 2px;
|
||||
}
|
||||
.BE-badge.BE-badge-popout {
|
||||
margin-top: 6px;
|
||||
}
|
||||
.BE-badge.BE-badge-popout:not(.BE-badge-CurrentGuildBoost) {
|
||||
top: 3px;
|
||||
}
|
||||
.BE-badge.BE-badge-popout.BE-badge-CurrentGuildBoost {
|
||||
top: 1px;
|
||||
}
|
||||
.BE-badge.BE-badge-list:not(.BE-badge-CurrentGuildBoost) {
|
||||
top: 1px;
|
||||
}
|
||||
.BE-badge.BE-badge-chat:not(.BE-badge-CurrentGuildBoost) {
|
||||
top: 2px;
|
||||
}
|
||||
.BE-badge.BE-badge-chat.BE-badge-CurrentGuildBoost {
|
||||
top: 1px;
|
||||
}
|
||||
${BDFDB.dotCN.userprofiletopsectionplaying} .BE-badge.BE-badge-CurrentGuildBoost svg {
|
||||
color: white !important;
|
||||
}
|
||||
.BE-badge {height:17px !important;}
|
||||
.BE-badge.BE-size-17 {width:17px !important; min-width:17px !important;}
|
||||
.BE-badge.BE-size-21 {width:21px !important; min-width:21px !important;}
|
||||
.BE-badge.BE-size-22 {width:22px !important; min-width:22px !important;}
|
||||
.BE-badge.BE-size-24 {width:24px !important; min-width:24px !important;}
|
||||
.BE-badge.BE-badge-mini {height:14px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-17 {width:14px !important; min-width:14px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-21 {width:18px !important; min-width:18px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-22 {width:18px !important; min-width:18px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-24 {width:19px !important; min-width:19px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-badge-CurrentGuildBoost {height:12px !important;}
|
||||
var BadgesEverywhere = (_ => {
|
||||
var badgeClasses, requestedUsers = {}, loadedUsers = {}, requestQueue = {queue:[], running:false, timeout:null};
|
||||
var nitroflag, boostflag;
|
||||
|
||||
.BE-badge.BE-badge-mini:first-of-type {
|
||||
margin-left: 5px;
|
||||
}
|
||||
.BE-badge.BE-badge-mini:last-of-type {
|
||||
margin-right: 0;
|
||||
}
|
||||
return class BadgesEverywhere {
|
||||
getName () {return "BadgesEverywhere";}
|
||||
|
||||
.BE-badge.BE-badge-CurrentGuildBoost {height:14px !important; width:14px !important; min-width:14px !important;}
|
||||
getVersion () {return "1.5.2";}
|
||||
|
||||
#app-mount .BE-badge.BE-badge-settings {width:30px !important;min-width:30px !important;}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
${BDFDB.dotCNS.member + BDFDB.dotCN.memberpremiumicon}:not(.BE-badge-CurrentGuildBoost-inner) {display: none;}`;
|
||||
getDescription () {return "Displays Badges (Nitro, HypeSquad, etc...) in the chat/memberlist/userpopout.";}
|
||||
|
||||
this.requestedusers = {};
|
||||
this.loadedusers = {};
|
||||
this.RequestQueue = {queue:[], running:false, timeout:null};
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showInPopout: {value:true, description:"Show Badge in User Popout."},
|
||||
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/Boost Badges"}
|
||||
},
|
||||
badges: {
|
||||
"STAFF": {value:true, id:"Staff", name:"STAFF_BADGE_TOOLTIP", icon:"profileBadgeStaff", px:17},
|
||||
"PARTNER": {value:true, id:"Partner", name:"PARTNER_BADGE_TOOLTIP", icon:"profileBadgePartner", px:22},
|
||||
"HYPESQUAD": {value:true, id:"HypeSquad", name:"HYPESQUAD_BADGE_TOOLTIP", icon:"profileBadgeHypesquad", px:17},
|
||||
"BUG_HUNTER_LEVEL_1": {value:true, id:"BugHunter1", name:"BUG_HUNTER_BADGE_TOOLTIP", icon:"profileBadgeBugHunterLevel1", px:17, suffix: "Level 1"},
|
||||
"BUG_HUNTER_LEVEL_2": {value:true, id:"BugHunter2", name:"BUG_HUNTER_BADGE_TOOLTIP", icon:"profileBadgeBugHunterLevel2", px:17, suffix: "Level 2"},
|
||||
"MFA_SMS": {value:false, id:null, name:null, icon:false, px:0},
|
||||
"PREMIUM_PROMO_DISMISSED": {value:false, id:null, name:null, icon:false, px:0},
|
||||
"HYPESQUAD_ONLINE_HOUSE_1": {value:true, id:"HypeSquad1", name:"HypeSquad Bravery", icon:"profileBadgeHypeSquadOnlineHouse1", px:17},
|
||||
"HYPESQUAD_ONLINE_HOUSE_2": {value:true, id:"HypeSquad2", name:"HypeSquad Brilliance", icon:"profileBadgeHypeSquadOnlineHouse2", px:17},
|
||||
"HYPESQUAD_ONLINE_HOUSE_3": {value:true, id:"HypeSquad3", name:"HypeSquad Balance", icon:"profileBadgeHypeSquadOnlineHouse3", px:17},
|
||||
"PREMIUM_EARLY_SUPPORTER": {value:true, id:"EarlySupporter", name:"EARLY_SUPPORTER_TOOLTIP", icon:"profileBadgeEarlySupporter", px:24},
|
||||
"NITRO": {value:true, id:"Nitro", name:"Nitro", icon:"profileBadgePremium", px:21},
|
||||
"SYSTEM": {value:false, id:null, name:null, icon:null, px:0},
|
||||
"HAS_UNREAD_URGENT_MESSAGES": {value:false, id:null, name:null, icon:null, px:0},
|
||||
"GUILD_BOOST": {value:true, id:"NitroGuildBoost", name:"Nitro Guild Boost", icon:"profileGuildSubscriberlvl", px:17, types:[1,2,3,4,5,6,7,8,9]},
|
||||
},
|
||||
indicators: {
|
||||
"CURRENT_GUILD_BOOST": {value:true, id:"CurrentGuildBoost", name:"Current Nitro Guild Boost", inner:`<svg 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>`},
|
||||
}
|
||||
};
|
||||
|
||||
for (let flagname in BDFDB.DiscordConstants.UserFlags) if (this.defaults.badges[flagname]) {
|
||||
if (BDFDB.LanguageUtils.LanguageStringsCheck[this.defaults.badges[flagname].name]) this.defaults.badges[flagname].name = BDFDB.LanguageUtils.LanguageStrings[this.defaults.badges[flagname].name];
|
||||
this.defaults.badges[BDFDB.DiscordConstants.UserFlags[flagname]] = this.defaults.badges[flagname];
|
||||
delete this.defaults.badges[flagname];
|
||||
}
|
||||
this.nitroflag = Math.max(...BDFDB.ObjectUtils.toArray(BDFDB.DiscordConstants.UserFlags)) * 2;
|
||||
this.defaults.badges[this.nitroflag] = this.defaults.badges.NITRO;
|
||||
delete this.defaults.badges.NITRO;
|
||||
this.boostflag = this.nitroflag * 2;
|
||||
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].icon || isNaN(parseInt(flag))) delete this.defaults.badges[flag];
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let badges = BDFDB.DataUtils.get(this, "badges");
|
||||
let indicators = BDFDB.DataUtils.get(this, "indicators");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
for (let flag in badges) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["badges", flag],
|
||||
label: this.defaults.badges[flag].name + (this.defaults.badges[flag].suffix ? ` ${this.defaults.badges[flag].suffix}` : ""),
|
||||
value: badges[flag],
|
||||
labelchildren: this.createSettingsBadges(flag)
|
||||
}));
|
||||
for (let flag in indicators) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["indicators", flag],
|
||||
label: this.defaults.indicators[flag].name + (this.defaults.indicators[flag].suffix ? ` ${this.defaults.indicators[flag].suffix}` : ""),
|
||||
value: indicators[flag],
|
||||
labelchildren: this.createSettingsBadges(flag)
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "Display Badges:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
this.BadgeClasses = BDFDB.ModuleUtils.findByProperties("profileBadgeStaff", "profileBadgePremium");
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.TimeUtils.clear(this.RequestQueue.timeout);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
}
|
||||
|
||||
processMemberListItem (e) {
|
||||
if (e.instance.props.user && BDFDB.DataUtils.get(this, "settings", "showInMemberList")) {
|
||||
this.injectBadges(e.instance, BDFDB.ReactUtils.getValue(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, "list");
|
||||
}
|
||||
}
|
||||
|
||||
processMessageUsername (e) {
|
||||
let user = BDFDB.ReactUtils.getValue(e.instance, "props.message.author");
|
||||
if (user && typeof e.returnvalue.props.children == "function" && BDFDB.DataUtils.get(this, "settings", "showInChat")) {
|
||||
let renderChildren = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
this.injectBadges(e.instance, renderedChildren.props.children, user, "chat");
|
||||
return renderedChildren;
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
processUserPopout (e) {
|
||||
if (e.instance.props.user && BDFDB.DataUtils.get(this, "settings", "showInPopout")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "CustomStatus"});
|
||||
if (index > -1) this.injectBadges(e.instance, children, e.instance.props.user, "popout", e.instance.props.activity && e.instance.props.activity.type != BDFDB.DiscordConstants.ActivityTypes.CUSTOM_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
injectBadges (instance, children, user, type, colored) {
|
||||
if (!BDFDB.ArrayUtils.is(children) || !user || user.bot) return;
|
||||
if (!BDFDB.ArrayUtils.is(this.requestedusers[user.id])) {
|
||||
this.requestedusers[user.id] = [instance];
|
||||
var queue = _ => {
|
||||
this.RequestQueue.queue.push(user.id);
|
||||
runqueue();
|
||||
};
|
||||
var runqueue = _ => {
|
||||
if (!this.RequestQueue.running) request(this.RequestQueue.queue.shift());
|
||||
};
|
||||
var request = id => {
|
||||
if (id) {
|
||||
this.RequestQueue.running = true;
|
||||
BDFDB.TimeUtils.clear(this.RequestQueue.timeout);
|
||||
this.RequestQueue.timeout = BDFDB.TimeUtils.timeout(_ => {
|
||||
this.RequestQueue.running = false;
|
||||
runqueue();
|
||||
}, 30000);
|
||||
BDFDB.LibraryModules.APIUtils.get(BDFDB.DiscordConstants.Endpoints.USER_PROFILE(id)).then(result => {
|
||||
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[id] = usercopy;
|
||||
for (let queredinstance of this.requestedusers[id]) BDFDB.ReactUtils.forceUpdate(queredinstance);
|
||||
this.RequestQueue.running = false;
|
||||
BDFDB.TimeUtils.timeout(_ => {runqueue();}, 1000);
|
||||
});
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MemberListItem: "render",
|
||||
MessageHeader: "default",
|
||||
UserPopout: "render"
|
||||
}
|
||||
};
|
||||
queue();
|
||||
}
|
||||
else if (!this.loadedusers[user.id]) this.requestedusers[user.id].push(instance);
|
||||
else children.push(this.createBadges(user, type, colored));
|
||||
}
|
||||
|
||||
createBadges (user, type, uncolored) {
|
||||
let badges = BDFDB.DataUtils.get(this, "badges");
|
||||
let indicators = BDFDB.DataUtils.get(this, "indicators");
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (uncolored == undefined) uncolored = !settings.useColoredVersion;
|
||||
let badgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-${type} ${uncolored ? BDFDB.disCN.userprofiletopsectionplaying : BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;"></span>`));
|
||||
badgewrapper.props.children = [];
|
||||
for (let flag in badges) if ((this.loadedusers[user.id].flags | flag) == this.loadedusers[user.id].flags && badges[flag]) {
|
||||
badgewrapper.props.children.push(this.createBadge(settings.showNitroDate ? this.getTimeString(user.id, flag) : null, type, flag, flag == this.boostflag ? BDFDB.LibraryModules.GuildBoostUtils.getUserLevel(this.loadedusers[user.id].premium_guild_since) : null));
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
.BE-badge {
|
||||
position: relative;
|
||||
background-size: contain;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 2px;
|
||||
}
|
||||
.BE-badge.BE-badge-popout {
|
||||
margin-top: 6px;
|
||||
}
|
||||
.BE-badge.BE-badge-popout:not(.BE-badge-CurrentGuildBoost) {
|
||||
top: 3px;
|
||||
}
|
||||
.BE-badge.BE-badge-popout.BE-badge-CurrentGuildBoost {
|
||||
top: 1px;
|
||||
}
|
||||
.BE-badge.BE-badge-list:not(.BE-badge-CurrentGuildBoost) {
|
||||
top: 1px;
|
||||
}
|
||||
.BE-badge.BE-badge-chat:not(.BE-badge-CurrentGuildBoost) {
|
||||
top: 2px;
|
||||
}
|
||||
.BE-badge.BE-badge-chat.BE-badge-CurrentGuildBoost {
|
||||
top: 1px;
|
||||
}
|
||||
${BDFDB.dotCN.userprofiletopsectionplaying} .BE-badge.BE-badge-CurrentGuildBoost svg {
|
||||
color: white !important;
|
||||
}
|
||||
.BE-badge {height:17px !important;}
|
||||
.BE-badge.BE-size-17 {width:17px !important; min-width:17px !important;}
|
||||
.BE-badge.BE-size-21 {width:21px !important; min-width:21px !important;}
|
||||
.BE-badge.BE-size-22 {width:22px !important; min-width:22px !important;}
|
||||
.BE-badge.BE-size-24 {width:24px !important; min-width:24px !important;}
|
||||
.BE-badge.BE-badge-mini {height:14px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-17 {width:14px !important; min-width:14px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-21 {width:18px !important; min-width:18px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-22 {width:18px !important; min-width:18px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-size-24 {width:19px !important; min-width:19px !important;}
|
||||
.BE-badge.BE-badge-mini.BE-badge-CurrentGuildBoost {height:12px !important;}
|
||||
|
||||
.BE-badge.BE-badge-mini:first-of-type {
|
||||
margin-left: 5px;
|
||||
}
|
||||
.BE-badge.BE-badge-mini:last-of-type {
|
||||
margin-right: 0;
|
||||
}
|
||||
${BDFDB.dotCNS.messagecozy + BDFDB.dotCN.messageusername} + .BE-badges .BE-badge:first-of-type {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.BE-badge.BE-badge-CurrentGuildBoost {height:14px !important; width:14px !important; min-width:14px !important;}
|
||||
|
||||
#app-mount .BE-badge.BE-badge-settings {width:30px !important;min-width:30px !important;}
|
||||
|
||||
${BDFDB.dotCNS.member + BDFDB.dotCN.memberpremiumicon}:not(.BE-badge-CurrentGuildBoost-inner) {display: none;}`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showInPopout: {value:true, description:"Show Badge in User Popout."},
|
||||
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/Boost Badges"}
|
||||
},
|
||||
badges: {
|
||||
"STAFF": {value:true, id:"Staff", name:"STAFF_BADGE_TOOLTIP", icon:"profileBadgeStaff", px:17},
|
||||
"PARTNER": {value:true, id:"Partner", name:"PARTNER_BADGE_TOOLTIP", icon:"profileBadgePartner", px:22},
|
||||
"HYPESQUAD": {value:true, id:"HypeSquad", name:"HYPESQUAD_BADGE_TOOLTIP", icon:"profileBadgeHypesquad", px:17},
|
||||
"BUG_HUNTER_LEVEL_1": {value:true, id:"BugHunter1", name:"BUG_HUNTER_BADGE_TOOLTIP", icon:"profileBadgeBugHunterLevel1", px:17, suffix: "Level 1"},
|
||||
"BUG_HUNTER_LEVEL_2": {value:true, id:"BugHunter2", name:"BUG_HUNTER_BADGE_TOOLTIP", icon:"profileBadgeBugHunterLevel2", px:17, suffix: "Level 2"},
|
||||
"MFA_SMS": {value:false, id:null, name:null, icon:false, px:0},
|
||||
"PREMIUM_PROMO_DISMISSED": {value:false, id:null, name:null, icon:false, px:0},
|
||||
"HYPESQUAD_ONLINE_HOUSE_1": {value:true, id:"HypeSquad1", name:"HypeSquad Bravery", icon:"profileBadgeHypeSquadOnlineHouse1", px:17},
|
||||
"HYPESQUAD_ONLINE_HOUSE_2": {value:true, id:"HypeSquad2", name:"HypeSquad Brilliance", icon:"profileBadgeHypeSquadOnlineHouse2", px:17},
|
||||
"HYPESQUAD_ONLINE_HOUSE_3": {value:true, id:"HypeSquad3", name:"HypeSquad Balance", icon:"profileBadgeHypeSquadOnlineHouse3", px:17},
|
||||
"PREMIUM_EARLY_SUPPORTER": {value:true, id:"EarlySupporter", name:"EARLY_SUPPORTER_TOOLTIP", icon:"profileBadgeEarlySupporter", px:24},
|
||||
"NITRO": {value:true, id:"Nitro", name:"Nitro", icon:"profileBadgePremium", px:21},
|
||||
"SYSTEM": {value:false, id:null, name:null, icon:null, px:0},
|
||||
"HAS_UNREAD_URGENT_MESSAGES": {value:false, id:null, name:null, icon:null, px:0},
|
||||
"GUILD_BOOST": {value:true, id:"NitroGuildBoost", name:"Nitro Guild Boost", icon:"profileGuildSubscriberlvl", px:17, types:[1,2,3,4,5,6,7,8,9]},
|
||||
},
|
||||
indicators: {
|
||||
"CURRENT_GUILD_BOOST": {value:true, id:"CurrentGuildBoost", name:"Current Nitro Guild Boost", inner:`<svg 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>`},
|
||||
}
|
||||
};
|
||||
|
||||
for (let flagname in BDFDB.DiscordConstants.UserFlags) if (this.defaults.badges[flagname]) {
|
||||
if (BDFDB.LanguageUtils.LanguageStringsCheck[this.defaults.badges[flagname].name]) this.defaults.badges[flagname].name = BDFDB.LanguageUtils.LanguageStrings[this.defaults.badges[flagname].name];
|
||||
this.defaults.badges[BDFDB.DiscordConstants.UserFlags[flagname]] = this.defaults.badges[flagname];
|
||||
delete this.defaults.badges[flagname];
|
||||
}
|
||||
nitroflag = Math.max(...BDFDB.ObjectUtils.toArray(BDFDB.DiscordConstants.UserFlags)) * 2;
|
||||
this.defaults.badges[nitroflag] = this.defaults.badges.NITRO;
|
||||
delete this.defaults.badges.NITRO;
|
||||
boostflag = nitroflag * 2;
|
||||
this.defaults.badges[boostflag] = this.defaults.badges.GUILD_BOOST;
|
||||
delete this.defaults.badges.GUILD_BOOST;
|
||||
for (let flag in this.defaults.badges) if (!this.defaults.badges[flag].icon || isNaN(parseInt(flag))) delete this.defaults.badges[flag];
|
||||
}
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), user.id);
|
||||
if (indicators.CURRENT_GUILD_BOOST && member && member.premiumSince) {
|
||||
badgewrapper.props.children.push(this.createBadge(settings.showNitroDate ? this.getTimeString(user.id, "CURRENT_GUILD_BOOST") : null, type, "CURRENT_GUILD_BOOST"));
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let badges = BDFDB.DataUtils.get(this, "badges");
|
||||
let indicators = BDFDB.DataUtils.get(this, "indicators");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
for (let flag in badges) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["badges", flag],
|
||||
label: this.defaults.badges[flag].name + (this.defaults.badges[flag].suffix ? ` ${this.defaults.badges[flag].suffix}` : ""),
|
||||
value: badges[flag],
|
||||
labelchildren: this.createSettingsBadges(flag)
|
||||
}));
|
||||
for (let flag in indicators) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["indicators", flag],
|
||||
label: this.defaults.indicators[flag].name + (this.defaults.indicators[flag].suffix ? ` ${this.defaults.indicators[flag].suffix}` : ""),
|
||||
value: indicators[flag],
|
||||
labelchildren: this.createSettingsBadges(flag)
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "Display Badges:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
return badgewrapper.props.children.length ? badgewrapper : null;
|
||||
}
|
||||
|
||||
createBadge (timestring, type, flag, rank) {
|
||||
let data = this.defaults.badges[flag] || this.defaults.indicators[flag];
|
||||
if (!data) return null;
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
className: BDFDB.DOMUtils.formatClassName(`BE-badge`, `BE-badge-${type}`, ["list", "chat"].includes(type) ? `BE-badge-mini` : null, data.id ? `BE-badge-${data.id}` : null, data.icon ? this.BadgeClasses[data.icon + (rank || "")] : null, data.px ? `BE-size-${data.px}` : null),
|
||||
text: timestring || (data.name + (data.suffix ? ` ${data.suffix}` : "") + (rank ? ` Level ${rank}` : "")),
|
||||
tooltipConfig: {
|
||||
style: "white-space: nowrap; max-width: unset;"
|
||||
},
|
||||
children: data.inner ? BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(data.inner)) : null
|
||||
})
|
||||
}
|
||||
|
||||
getTimeString (id, flag) {
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), id);
|
||||
if (flag == this.nitroflag) return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_BADGE_TOOLTIP", new Date(this.loadedusers[id].premium_since));
|
||||
else if (flag == this.boostflag) return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(this.loadedusers[id].premium_guild_since));
|
||||
else if (member && flag == "CURRENT_GUILD_BOOST") return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(member.premiumSince));
|
||||
return null;
|
||||
}
|
||||
|
||||
createSettingsBadges (flag) {
|
||||
let data = this.defaults.badges[flag] || this.defaults.indicators[flag];
|
||||
if (!data) return null;
|
||||
let eles = null;
|
||||
let colorbadgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;"></span>`));
|
||||
let uncolorbadgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionplaying}" style="all: unset !important;"></span>`));
|
||||
if (Array.isArray(data.types)) {
|
||||
for (let rank of data.types) {
|
||||
let badge = this.createBadge(null, "settings", flag, rank);
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
badgeClasses = BDFDB.ModuleUtils.findByProperties("profileBadgeStaff", "profileBadgePremium");
|
||||
|
||||
requestedUsers = {}, loadedUsers = {};
|
||||
requestQueue = {queue:[], running:false, timeout:null};
|
||||
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.TimeUtils.clear(requestQueue.timeout);
|
||||
|
||||
this.forceUpdateAll();
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
}
|
||||
|
||||
processMemberListItem (e) {
|
||||
if (e.instance.props.user && BDFDB.DataUtils.get(this, "settings", "showInMemberList")) {
|
||||
this.injectBadges(e.instance, BDFDB.ReactUtils.getValue(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, "list");
|
||||
}
|
||||
}
|
||||
|
||||
processMessageHeader (e) {
|
||||
if (e.instance.props.message && BDFDB.DataUtils.get(this, "settings", "showInChat")) {
|
||||
this.injectBadges(e.instance, e.returnvalue.props.children[2].props.children, e.instance.props.message.author, "chat");
|
||||
}
|
||||
}
|
||||
|
||||
processUserPopout (e) {
|
||||
if (e.instance.props.user && BDFDB.DataUtils.get(this, "settings", "showInPopout")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "CustomStatus"});
|
||||
if (index > -1) this.injectBadges(e.instance, children, e.instance.props.user, "popout", e.instance.props.activity && e.instance.props.activity.type != BDFDB.DiscordConstants.ActivityTypes.CUSTOM_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
injectBadges (instance, children, user, type, colored) {
|
||||
if (!BDFDB.ArrayUtils.is(children) || !user || user.bot) return;
|
||||
if (!BDFDB.ArrayUtils.is(requestedUsers[user.id])) {
|
||||
requestedUsers[user.id] = [instance];
|
||||
var queue = _ => {
|
||||
requestQueue.queue.push(user.id);
|
||||
runqueue();
|
||||
};
|
||||
var runqueue = _ => {
|
||||
if (!requestQueue.running) request(requestQueue.queue.shift());
|
||||
};
|
||||
var request = id => {
|
||||
if (id) {
|
||||
requestQueue.running = true;
|
||||
BDFDB.TimeUtils.clear(requestQueue.timeout);
|
||||
requestQueue.timeout = BDFDB.TimeUtils.timeout(_ => {
|
||||
requestQueue.running = false;
|
||||
runqueue();
|
||||
}, 30000);
|
||||
BDFDB.LibraryModules.APIUtils.get(BDFDB.DiscordConstants.Endpoints.USER_PROFILE(id)).then(result => {
|
||||
let usercopy = Object.assign({}, result.body.user);
|
||||
if (result.body.premium_since) usercopy.flags += nitroflag;
|
||||
usercopy.premium_since = result.body.premium_since;
|
||||
if (result.body.premium_guild_since) usercopy.flags += boostflag;
|
||||
usercopy.premium_guild_since = result.body.premium_guild_since;
|
||||
loadedUsers[id] = usercopy;
|
||||
for (let ins of requestedUsers[id]) BDFDB.ReactUtils.forceUpdate(ins);
|
||||
requestQueue.running = false;
|
||||
BDFDB.TimeUtils.timeout(_ => {runqueue();}, 1000);
|
||||
});
|
||||
}
|
||||
};
|
||||
queue();
|
||||
}
|
||||
else if (!loadedUsers[user.id]) requestedUsers[user.id].push(instance);
|
||||
else children.push(this.createBadges(user, type, colored));
|
||||
}
|
||||
|
||||
createBadges (user, type, uncolored) {
|
||||
let badges = BDFDB.DataUtils.get(this, "badges");
|
||||
let indicators = BDFDB.DataUtils.get(this, "indicators");
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (uncolored == undefined) uncolored = !settings.useColoredVersion;
|
||||
let badgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-${type} ${uncolored ? BDFDB.disCN.userprofiletopsectionplaying : BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;"></span>`));
|
||||
badgewrapper.props.children = [];
|
||||
for (let flag in badges) if ((loadedUsers[user.id].flags | flag) == loadedUsers[user.id].flags && badges[flag]) {
|
||||
badgewrapper.props.children.push(this.createBadge(settings.showNitroDate ? this.getTimeString(user.id, flag) : null, type, flag, flag == boostflag ? BDFDB.LibraryModules.GuildBoostUtils.getUserLevel(loadedUsers[user.id].premium_guild_since) : null));
|
||||
}
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), user.id);
|
||||
if (indicators.CURRENT_GUILD_BOOST && member && member.premiumSince) {
|
||||
badgewrapper.props.children.push(this.createBadge(settings.showNitroDate ? this.getTimeString(user.id, "CURRENT_GUILD_BOOST") : null, type, "CURRENT_GUILD_BOOST"));
|
||||
}
|
||||
return badgewrapper.props.children.length ? badgewrapper : null;
|
||||
}
|
||||
|
||||
createBadge (timestring, type, flag, rank) {
|
||||
let data = this.defaults.badges[flag] || this.defaults.indicators[flag];
|
||||
if (!data) return null;
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
className: BDFDB.DOMUtils.formatClassName(`BE-badge`, `BE-badge-${type}`, ["list", "chat"].includes(type) ? `BE-badge-mini` : null, data.id ? `BE-badge-${data.id}` : null, data.icon ? badgeClasses[data.icon + (rank || "")] : null, data.px ? `BE-size-${data.px}` : null),
|
||||
text: timestring || (data.name + (data.suffix ? ` ${data.suffix}` : "") + (rank ? ` Level ${rank}` : "")),
|
||||
tooltipConfig: {
|
||||
style: "white-space: nowrap; max-width: unset;"
|
||||
},
|
||||
children: data.inner ? BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(data.inner)) : null
|
||||
})
|
||||
}
|
||||
|
||||
getTimeString (id, flag) {
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), id);
|
||||
if (flag == nitroflag) return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_BADGE_TOOLTIP", new Date(loadedUsers[id].premium_since));
|
||||
else if (flag == boostflag) return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(loadedUsers[id].premium_guild_since));
|
||||
else if (member && flag == "CURRENT_GUILD_BOOST") return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(member.premiumSince));
|
||||
return null;
|
||||
}
|
||||
|
||||
createSettingsBadges (flag) {
|
||||
let data = this.defaults.badges[flag] || this.defaults.indicators[flag];
|
||||
if (!data) return null;
|
||||
let eles = null;
|
||||
let colorbadgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;"></span>`));
|
||||
let uncolorbadgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionplaying}" style="all: unset !important;"></span>`));
|
||||
if (Array.isArray(data.types)) {
|
||||
for (let rank of data.types) {
|
||||
let badge = this.createBadge(null, "settings", flag, rank);
|
||||
colorbadgewrapper.props.children.push(badge);
|
||||
uncolorbadgewrapper.props.children.push(badge);
|
||||
}
|
||||
eles = BDFDB.ReactUtils.createElement("div", {children: [colorbadgewrapper, BDFDB.ReactUtils.createElement("br"), uncolorbadgewrapper]});
|
||||
}
|
||||
else {
|
||||
let badge = this.createBadge(null, "settings", flag);
|
||||
colorbadgewrapper.props.children.push(badge);
|
||||
uncolorbadgewrapper.props.children.push(badge);
|
||||
eles = [colorbadgewrapper, uncolorbadgewrapper];
|
||||
}
|
||||
eles = BDFDB.ReactUtils.createElement("div", {children: [colorbadgewrapper, BDFDB.ReactUtils.createElement("br"), uncolorbadgewrapper]});
|
||||
return eles;
|
||||
}
|
||||
else {
|
||||
let badge = this.createBadge(null, "settings", flag);
|
||||
colorbadgewrapper.props.children.push(badge);
|
||||
uncolorbadgewrapper.props.children.push(badge);
|
||||
eles = [colorbadgewrapper, uncolorbadgewrapper];
|
||||
|
||||
forceUpdateAll() {
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
BDFDB.MessageUtils.rerenderAll();
|
||||
}
|
||||
return eles;
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,209 +1,232 @@
|
|||
//META{"name":"BetterSearchPage","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BetterSearchPage","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/BetterSearchPage/BetterSearchPage.plugin.js"}*//
|
||||
|
||||
class BetterSearchPage {
|
||||
getName () {return "BetterSearchPage";}
|
||||
var BetterSearchPage = (_ => {
|
||||
return class BetterSearchPage {
|
||||
getName () {return "BetterSearchPage";}
|
||||
|
||||
getVersion () {return "1.1.0";}
|
||||
getVersion () {return "1.1.1";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds some extra controls to the search results page.";}
|
||||
getDescription () {return "Adds some extra controls to the search results page.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Jump to","Pressing the Jump to button now properly works again"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
SearchResults: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
.BSP-pagination-button {
|
||||
background: url('data:image/svg+xml; base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIyNSI+PGcgZmlsbD0iIzczN2Y4ZCIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZD0iTTE3LjMzOCAxMi40ODVjLTQuMTU2IDQuMTU2LTguMzEyIDguMzEyLTEyLjQ2OCAxMi40NjctMS40MDItMS40MDItMi44MDUtMi44MDQtNC4yMDctNC4yMDYgMi43NTYtMi43NTcgNS41MTMtNS41MTQgOC4yNy04LjI3QzYuMTc2IDkuNzIgMy40MTkgNi45NjMuNjYzIDQuMjA3TDQuODcgMGMtLjA1OC0uMDU5IDEyLjU1NSAxMi41NjIgMTIuNDY4IDEyLjQ4NXoiLz48cGF0aCB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGQ9Ik0xNy4zMzggMTIuNDg1Yy00LjE1NiA0LjE1Ni04LjMxMiA4LjMxMi0xMi40NjggMTIuNDY3LTEuNDAyLTEuNDAyLTIuODA1LTIuODA0LTQuMjA3LTQuMjA2IDIuNzU2LTIuNzU3IDUuNTEzLTUuNTE0IDguMjctOC4yN0M2LjE3NiA5LjcyIDMuNDE5IDYuOTYzLjY2MyA0LjIwN0w0Ljg3IDBjLS4wNTgtLjA1OSAxMi41NTUgMTIuNTYyIDEyLjQ2OCAxMi40ODV6IiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxMiAwKSIvPjwvZz48L3N2Zz4=') 50%/9px 12px no-repeat;
|
||||
border: 1px solid rgba(79,84,92,.16);
|
||||
border-radius: 2px;
|
||||
cursor: pointer;
|
||||
height: 18px;
|
||||
left: 20px;
|
||||
opacity: .7;
|
||||
top: 20px;
|
||||
width: 18px;
|
||||
}
|
||||
${BDFDB.dotCN.themedark} .BSP-pagination-button {
|
||||
background-image: url('data:image/svg+xml; base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIyNSI+PGcgZmlsbD0iI0ZGRiIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZD0iTTE3LjMzOCAxMi40ODVjLTQuMTU2IDQuMTU2LTguMzEyIDguMzEyLTEyLjQ2OCAxMi40NjctMS40MDItMS40MDItMi44MDUtMi44MDQtNC4yMDctNC4yMDYgMi43NTYtMi43NTcgNS41MTMtNS41MTQgOC4yNy04LjI3QzYuMTc2IDkuNzIgMy40MTkgNi45NjMuNjYzIDQuMjA3TDQuODcgMGMtLjA1OC0uMDU5IDEyLjU1NSAxMi41NjIgMTIuNDY4IDEyLjQ4NXoiIC8+PHBhdGggeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBkPSJNMTcuMzM4IDEyLjQ4NWMtNC4xNTYgNC4xNTYtOC4zMTIgOC4zMTItMTIuNDY4IDEyLjQ2Ny0xLjQwMi0xLjQwMi0yLjgwNS0yLjgwNC00LjIwNy00LjIwNiAyLjc1Ni0yLjc1NyA1LjUxMy01LjUxNCA4LjI3LTguMjdDNi4xNzYgOS43MiAzLjQxOSA2Ljk2My42NjMgNC4yMDdMNC44NyAwYy0uMDU4LS4wNTkgMTIuNTU1IDEyLjU2MiAxMi40NjggMTIuNDg1eiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMTIgMCkiLz48L2c+PC9zdmc+');
|
||||
border: 1px solid hsla(0,0%,100%,.16);
|
||||
}
|
||||
.BSP-pagination-button.BSP-pagination-first {
|
||||
margin-right: 10px;
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
.BSP-pagination-button.BSP-pagination-last {
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.BSP-pagination-button.BSP-pagination-jump {
|
||||
margin-left: 10px;
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.BSP-pagination-button${BDFDB.dotCN.searchresultspaginationdisabled} {
|
||||
cursor: default;
|
||||
opacity: .3;
|
||||
}
|
||||
.BSP-pagination-button${BDFDB.notCN.searchresultspaginationdisabled}:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
addFirstLast: {value:true, description:"Adds a first and last page button."},
|
||||
addJumpTo: {value:true, description:"Adds a jump to input field (press enter to jump)."},
|
||||
cloneToTheTop: {value:true, description:"Clones the controls to the top of the results page."}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.titlesize18 + 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.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.titlesize16 + 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>`;
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
SearchResults: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
settingshtml += `</div></div>`;
|
||||
|
||||
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
.BSP-pagination-button {
|
||||
background: url('data:image/svg+xml; base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIyNSI+PGcgZmlsbD0iIzczN2Y4ZCIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZD0iTTE3LjMzOCAxMi40ODVjLTQuMTU2IDQuMTU2LTguMzEyIDguMzEyLTEyLjQ2OCAxMi40NjctMS40MDItMS40MDItMi44MDUtMi44MDQtNC4yMDctNC4yMDYgMi43NTYtMi43NTcgNS41MTMtNS41MTQgOC4yNy04LjI3QzYuMTc2IDkuNzIgMy40MTkgNi45NjMuNjYzIDQuMjA3TDQuODcgMGMtLjA1OC0uMDU5IDEyLjU1NSAxMi41NjIgMTIuNDY4IDEyLjQ4NXoiLz48cGF0aCB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGQ9Ik0xNy4zMzggMTIuNDg1Yy00LjE1NiA0LjE1Ni04LjMxMiA4LjMxMi0xMi40NjggMTIuNDY3LTEuNDAyLTEuNDAyLTIuODA1LTIuODA0LTQuMjA3LTQuMjA2IDIuNzU2LTIuNzU3IDUuNTEzLTUuNTE0IDguMjctOC4yN0M2LjE3NiA5LjcyIDMuNDE5IDYuOTYzLjY2MyA0LjIwN0w0Ljg3IDBjLS4wNTgtLjA1OSAxMi41NTUgMTIuNTYyIDEyLjQ2OCAxMi40ODV6IiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgxMiAwKSIvPjwvZz48L3N2Zz4=') 50%/9px 12px no-repeat;
|
||||
border: 1px solid rgba(79,84,92,.16);
|
||||
border-radius: 2px;
|
||||
cursor: pointer;
|
||||
height: 18px;
|
||||
left: 20px;
|
||||
opacity: .7;
|
||||
top: 20px;
|
||||
width: 18px;
|
||||
}
|
||||
${BDFDB.dotCN.themedark} .BSP-pagination-button {
|
||||
background-image: url('data:image/svg+xml; base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIyNSI+PGcgZmlsbD0iI0ZGRiIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZD0iTTE3LjMzOCAxMi40ODVjLTQuMTU2IDQuMTU2LTguMzEyIDguMzEyLTEyLjQ2OCAxMi40NjctMS40MDItMS40MDItMi44MDUtMi44MDQtNC4yMDctNC4yMDYgMi43NTYtMi43NTcgNS41MTMtNS41MTQgOC4yNy04LjI3QzYuMTc2IDkuNzIgMy40MTkgNi45NjMuNjYzIDQuMjA3TDQuODcgMGMtLjA1OC0uMDU5IDEyLjU1NSAxMi41NjIgMTIuNDY4IDEyLjQ4NXoiIC8+PHBhdGggeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBkPSJNMTcuMzM4IDEyLjQ4NWMtNC4xNTYgNC4xNTYtOC4zMTIgOC4zMTItMTIuNDY4IDEyLjQ2Ny0xLjQwMi0xLjQwMi0yLjgwNS0yLjgwNC00LjIwNy00LjIwNiAyLjc1Ni0yLjc1NyA1LjUxMy01LjUxNCA4LjI3LTguMjdDNi4xNzYgOS43MiAzLjQxOSA2Ljk2My42NjMgNC4yMDdMNC44NyAwYy0uMDU4LS4wNTkgMTIuNTU1IDEyLjU2MiAxMi40NjggMTIuNDg1eiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMTIgMCkiLz48L2c+PC9zdmc+');
|
||||
border: 1px solid hsla(0,0%,100%,.16);
|
||||
}
|
||||
.BSP-pagination-button.BSP-pagination-first {
|
||||
margin-right: 10px;
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
.BSP-pagination-button.BSP-pagination-last {
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.BSP-pagination-button.BSP-pagination-jump {
|
||||
margin-left: 10px;
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.BSP-pagination-button${BDFDB.dotCN.searchresultspaginationdisabled} {
|
||||
cursor: default;
|
||||
opacity: .3;
|
||||
}
|
||||
.BSP-pagination-button${BDFDB.notCN.searchresultspaginationdisabled}:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
`;
|
||||
|
||||
BDFDB.initElements(settingspanel, this);
|
||||
return settingspanel;
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
this.defaults = {
|
||||
settings: {
|
||||
addFirstLast: {value:true, description:"Adds a first and last page button."},
|
||||
addJumpTo: {value:true, description:"Adds a jump to input field (press enter to jump)."},
|
||||
cloneToTheTop: {value:true, description:"Clones the controls to the top of the results page."}
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.titlesize18 + 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.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.titlesize16 + 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></div>`;
|
||||
|
||||
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
|
||||
|
||||
BDFDB.initElements(settingspanel, this);
|
||||
return settingspanel;
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed (e) {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
}
|
||||
|
||||
processSearchResults (e) {
|
||||
if (e.instance.props.search) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"Pagination"});
|
||||
if (index > -1) {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let currentpage = parseInt(Math.floor(e.instance.props.search.offset / BDFDB.DiscordConstants.SEARCH_PAGE_SIZE)) + 1;
|
||||
let maxpage = e.instance.props.search.totalResults > 5000 ? parseInt(Math.ceil(5000 / BDFDB.DiscordConstants.SEARCH_PAGE_SIZE)) : parseInt(Math.ceil(e.instance.props.search.totalResults / BDFDB.DiscordConstants.SEARCH_PAGE_SIZE));
|
||||
let doJump = page => {
|
||||
page = page < 1 ? 1 : (page > maxpage ? maxpage : page);
|
||||
if (page < currentpage) BDFDB.LibraryModules.SearchPageUtils.searchPreviousPage(e.instance.props.searchId, (currentpage - page) * BDFDB.DiscordConstants.SEARCH_PAGE_SIZE);
|
||||
else if (page > currentpage) BDFDB.LibraryModules.SearchPageUtils.searchNextPage(e.instance.props.searchId, (page - currentpage) * BDFDB.DiscordConstants.SEARCH_PAGE_SIZE);
|
||||
};
|
||||
let pagination = BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCN.searchresultspagination,
|
||||
children: [
|
||||
settings.addFirstLast ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
className: ["BSP-pagination-button", "BSP-pagination-first", currentpage == 1 ? BDFDB.disCN.searchresultspaginationdisabled : null].filter(n => n).join(" "),
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed (e) {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
}
|
||||
|
||||
processSearchResults (e) {
|
||||
if (e.instance.props.search) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"Pagination"});
|
||||
if (index > -1) {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let currentpage = parseInt(Math.floor(e.instance.props.search.offset / BDFDB.DiscordConstants.SEARCH_PAGE_SIZE)) + 1;
|
||||
let maxpage = e.instance.props.search.totalResults > 5000 ? parseInt(Math.ceil(5000 / BDFDB.DiscordConstants.SEARCH_PAGE_SIZE)) : parseInt(Math.ceil(e.instance.props.search.totalResults / BDFDB.DiscordConstants.SEARCH_PAGE_SIZE));
|
||||
let doJump = page => {
|
||||
page = page < 1 ? 1 : (page > maxpage ? maxpage : page);
|
||||
if (page < currentpage) BDFDB.LibraryModules.SearchPageUtils.searchPreviousPage(e.instance.props.searchId, (currentpage - page) * BDFDB.DiscordConstants.SEARCH_PAGE_SIZE);
|
||||
else if (page > currentpage) BDFDB.LibraryModules.SearchPageUtils.searchNextPage(e.instance.props.searchId, (page - currentpage) * BDFDB.DiscordConstants.SEARCH_PAGE_SIZE);
|
||||
};
|
||||
let pagination = children[index].type(children[index].props);
|
||||
if (currentpage >= maxpage) {
|
||||
pagination.props.children[2].props.className = BDFDB.DOMUtils.formatClassName(pagination.props.children[2].props.className, BDFDB.disCN.searchresultspaginationdisabled);
|
||||
pagination.props.children[2].props.onClick = _ => {};
|
||||
}
|
||||
pagination.props.children[0] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: "Previous",
|
||||
children: pagination.props.children[0]
|
||||
});
|
||||
pagination.props.children[2] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: currentpage >= maxpage ? "Max Page is 200" : "Next",
|
||||
tooltipConfig: {color: currentpage >= maxpage && BDFDB.LibraryComponents.TooltipContainer.Colors.RED},
|
||||
children: pagination.props.children[2]
|
||||
});
|
||||
if (settings.addFirstLast) {
|
||||
pagination.props.children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: "First",
|
||||
"aria-label": "First",
|
||||
onClick: _ => {if (currentpage != 1) doJump(1);}
|
||||
}) : null,
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
className: [BDFDB.disCN.searchresultspaginationprevious, currentpage == 1 ? BDFDB.disCN.searchresultspaginationdisabled : null].filter(n => n).join(" "),
|
||||
text: BDFDB.LanguageUtils.LanguageStrings.PAGINATION_PREVIOUS,
|
||||
"aria-label": BDFDB.LanguageUtils.LanguageStrings.PAGINATION_PREVIOUS,
|
||||
onClick: _ => {if (currentpage != 1) doJump(currentpage - 1);}
|
||||
}),
|
||||
BDFDB.LanguageUtils.LanguageStringsFormat("PAGINATOR_OF_PAGES", currentpage, maxpage),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
className: [BDFDB.disCN.searchresultspaginationnext, currentpage == maxpage ? BDFDB.disCN.searchresultspaginationdisabled : null].filter(n => n).join(" "),
|
||||
text: BDFDB.LanguageUtils.LanguageStrings.PAGINATION_NEXT,
|
||||
"aria-label": BDFDB.LanguageUtils.LanguageStrings.PAGINATION_NEXT,
|
||||
onClick: _ => {if (currentpage != maxpage) doJump(currentpage + 1);}
|
||||
}),
|
||||
settings.addFirstLast ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
className: ["BSP-pagination-button", "BSP-pagination-last", currentpage == maxpage ? BDFDB.disCN.searchresultspaginationdisabled : null].filter(n => n).join(" "),
|
||||
text: "Last",
|
||||
onClick: _ => {if (currentpage != 1) doJump(1);},
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.searchresultspaginationbutton, currentpage == 1 && BDFDB.disCN.searchresultspaginationdisabled),
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCN.searchresultspaginationicon,
|
||||
nativeClass: true,
|
||||
iconSVG: `<svg width="24" height="24" viewBox="0 0 24 24"><g fill="none" fill-rule="evenodd"><polygon fill="currentColor" fill-rule="nonzero" points="12.35 4.35 10 2 0 12 10 22 12.35 19.65 4.717 12"></polygon><polygon fill="currentColor" fill-rule="nonzero" points="24.35 4.35 22 2 12 12 22 22 24.35 19.65 16.717 12"></polygon><polygon points="0 0 24 0 24 24 0 24"></polygon></g></svg>`
|
||||
})
|
||||
})
|
||||
}));
|
||||
pagination.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: currentpage >= maxpage ? "Max Page is 200" : "Last",
|
||||
tooltipConfig: {color: currentpage >= maxpage && BDFDB.LibraryComponents.TooltipContainer.Colors.RED},
|
||||
"aria-label": "Last",
|
||||
onClick: _ => {if (currentpage != maxpage) doJump(maxpage);}
|
||||
}) : null,
|
||||
settings.addJumpTo ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
|
||||
id: "BSP-pagination-jumpinput",
|
||||
onClick: _ => {if (currentpage != maxpage) doJump(maxpage);},
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.searchresultspaginationbutton, currentpage >= maxpage && BDFDB.disCN.searchresultspaginationdisabled),
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCN.searchresultspaginationicon,
|
||||
nativeClass: true,
|
||||
iconSVG: `<svg width="24" height="24" viewBox="0 0 24 24"><g fill="none" fill-rule="evenodd"><polygon fill="currentColor" fill-rule="nonzero" points="2.47 2 0.12 4.35 7.753 12 0.12 19.65 2.47 22 12.47 12"></polygon><polygon fill="currentColor" fill-rule="nonzero" points="14.47 2 12.12 4.35 19.753 12 12.12 19.65 14.47 22 24.47 12"></polygon><polygon points="0 0 24 0 24 24 0 24"></polygon></g></svg>`
|
||||
})
|
||||
})
|
||||
}));
|
||||
}
|
||||
if (settings.addJumpTo) {
|
||||
pagination.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
|
||||
key: "BSP-pagination-jumpinput",
|
||||
type: "number",
|
||||
size: BDFDB.LibraryComponents.TextInput.Sizes.MINI,
|
||||
suppress: true,
|
||||
value: currentpage,
|
||||
min: 1,
|
||||
max: maxpage,
|
||||
onKeyDown: (e, inputinstance) => {
|
||||
if (e.which == 13) doJump(inputinstance.props.value);
|
||||
}
|
||||
}) : null,
|
||||
settings.addJumpTo ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
className: "BSP-pagination-button BSP-pagination-jump",
|
||||
onKeyDown: (e, inputinstance) => {if (e.which == 13) doJump(inputinstance.props.value);}
|
||||
}));
|
||||
pagination.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: BDFDB.LanguageUtils.LanguageStrings.JUMP,
|
||||
"aria-label": BDFDB.LanguageUtils.LanguageStrings.JUMP,
|
||||
onClick: (e, buttoninstance) => {
|
||||
let jumpinput = BDFDB.ReactUtils.findOwner(buttoninstance._reactInternalFiber.return, {props:[["id","BSP-pagination-jumpinput"]]});
|
||||
let jumpinput = BDFDB.ReactUtils.findOwner(buttoninstance._reactInternalFiber.return, {key:"BSP-pagination-jumpinput"});
|
||||
if (jumpinput) doJump(jumpinput.props.value);
|
||||
}
|
||||
}) : null
|
||||
]
|
||||
});
|
||||
children.splice(index, 1, pagination);
|
||||
if (settings.cloneToTheTop) children.unshift(pagination);
|
||||
},
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
|
||||
className: BDFDB.disCN.searchresultspaginationbutton,
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCN.searchresultspaginationicon,
|
||||
nativeClass: true,
|
||||
style: {transform: "rotate(90deg"},
|
||||
name: BDFDB.LibraryComponents.SvgIcon.Names.RIGHT_CARET
|
||||
})
|
||||
})
|
||||
}));
|
||||
}
|
||||
children[index] = pagination;
|
||||
if (settings.cloneToTheTop) children.unshift(pagination);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,161 +1,163 @@
|
|||
//META{"name":"CharCounter","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CharCounter","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CharCounter/CharCounter.plugin.js"}*//
|
||||
|
||||
class CharCounter {
|
||||
getName () {return "CharCounter";}
|
||||
|
||||
getVersion () {return "1.4.5";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds a charcounter in the chat.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["New WYSIWYG Textarea","Fixed for the new WYSIWYG Textarea that is hidden by experiments"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
ChannelTextAreaContainer: "render",
|
||||
Note: "render",
|
||||
ChangeNickname: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.maxLenghts = {
|
||||
normal: 2000,
|
||||
edit: 2000,
|
||||
form: 2000,
|
||||
nickname: 32,
|
||||
popout: 256,
|
||||
profile: 256
|
||||
}
|
||||
|
||||
this.css = `
|
||||
${BDFDB.dotCNS.typing + BDFDB.dotCN.typingcooldownwrapper} {
|
||||
margin-right: 64px;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounteradded} {
|
||||
position: relative !important;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter} {
|
||||
display: block;
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
font-size: 15px;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.normal {
|
||||
right: 0;
|
||||
bottom: -1.3em;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.edit {
|
||||
left: 0;
|
||||
bottom: -1.3em;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.form {
|
||||
right: 0;
|
||||
bottom: -1.0em;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.nickname {
|
||||
right: 0 !important;
|
||||
top: 0 !important;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.popout {
|
||||
right: 3px !important;
|
||||
bottom: -8px !important;
|
||||
font-size: 10px !important;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.profile {
|
||||
right: 0 !important;
|
||||
bottom: -10px !important;
|
||||
font-size: 12px !important;
|
||||
}
|
||||
${BDFDB.dotCN.usernote} textarea:not(:focus) + ${BDFDB.dotCN._charcountercounter} {
|
||||
display: none;
|
||||
}`;
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
processChannelTextAreaContainer (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ChannelEditorContainer"});
|
||||
if (index > -1 && children[index].props.type && this.maxLenghts[children[index].props.type] && !children[index].props.disabled) {
|
||||
if (!BDFDB.ArrayUtils.is(e.returnvalue.props.children)) e.returnvalue.props.children = [e.returnvalue.props.children];
|
||||
this.injectCounter(e.returnvalue, e.returnvalue.props.children, children[index].props.type, BDFDB.dotCN.textarea, true);
|
||||
}
|
||||
}
|
||||
|
||||
processNote (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: ["TextAreaAutosize", "TextArea", "PlainTextArea"]});
|
||||
if (index > -1) this.injectCounter(e.returnvalue, children, e.instance.props.className && e.instance.props.className.indexOf(BDFDB.disCN.usernotepopout) > -1 ? "popout" : "profile", "textarea");
|
||||
}
|
||||
|
||||
processChangeNickname (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "FormItem"});
|
||||
if (index > -1) {
|
||||
let [children2, index2] = BDFDB.ReactUtils.findChildren(children[index], {name: "TextInput"});
|
||||
if (index2 > -1) this.injectCounter(children[index], children2, "nickname", BDFDB.dotCN.input);
|
||||
}
|
||||
}
|
||||
var CharCounter = (_ => {
|
||||
const maxLenghts = {
|
||||
normal: 2000,
|
||||
edit: 2000,
|
||||
form: 2000,
|
||||
nickname: 32,
|
||||
popout: 256,
|
||||
profile: 256
|
||||
};
|
||||
|
||||
injectCounter (parent, children, type, refClass, parsing) {
|
||||
if (!children) return;
|
||||
parent.props.className = ((parent.props.className || "") + " " + BDFDB.disCN._charcountercounteradded).trim();
|
||||
children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CharCounter, {
|
||||
className: `${BDFDB.disCN._charcountercounter} ${type}`,
|
||||
refClass: refClass,
|
||||
parsing: parsing,
|
||||
max: this.maxLenghts[type]
|
||||
}));
|
||||
return class CharCounter {
|
||||
getName () {return "CharCounter";}
|
||||
|
||||
getVersion () {return "1.4.6";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds a charcounter in the chat.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
ChannelTextAreaContainer: "render",
|
||||
Note: "render",
|
||||
ChangeNickname: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCNS.typing + BDFDB.dotCN.typingcooldownwrapper} {
|
||||
margin-right: 64px;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounteradded} {
|
||||
position: relative !important;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter} {
|
||||
display: block;
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
font-size: 15px;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.normal {
|
||||
right: 0;
|
||||
bottom: -1.3em;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.edit {
|
||||
right: 0;
|
||||
bottom: -1.3em;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.form {
|
||||
right: 0;
|
||||
bottom: -1.0em;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.nickname {
|
||||
right: 0 !important;
|
||||
top: 0 !important;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.popout {
|
||||
right: 3px !important;
|
||||
bottom: -8px !important;
|
||||
font-size: 10px !important;
|
||||
}
|
||||
${BDFDB.dotCN._charcountercounter}.profile {
|
||||
right: 0 !important;
|
||||
bottom: -10px !important;
|
||||
font-size: 12px !important;
|
||||
}
|
||||
${BDFDB.dotCN.usernote} textarea:not(:focus) + ${BDFDB.dotCN._charcountercounter} {
|
||||
display: none;
|
||||
}`;
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
processChannelTextAreaContainer (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ChannelEditorContainer"});
|
||||
if (index > -1 && children[index].props.type && maxLenghts[children[index].props.type] && !children[index].props.disabled) {
|
||||
if (!BDFDB.ArrayUtils.is(e.returnvalue.props.children)) e.returnvalue.props.children = [e.returnvalue.props.children];
|
||||
this.injectCounter(e.returnvalue, e.returnvalue.props.children, children[index].props.type, BDFDB.dotCN.textarea, true);
|
||||
}
|
||||
}
|
||||
|
||||
processNote (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: ["TextAreaAutosize", "TextArea", "PlainTextArea"]});
|
||||
if (index > -1) this.injectCounter(e.returnvalue, children, e.instance.props.className && e.instance.props.className.indexOf(BDFDB.disCN.usernotepopout) > -1 ? "popout" : "profile", "textarea");
|
||||
}
|
||||
|
||||
processChangeNickname (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "FormItem"});
|
||||
if (index > -1) {
|
||||
let [children2, index2] = BDFDB.ReactUtils.findChildren(children[index], {name: "TextInput"});
|
||||
if (index2 > -1) this.injectCounter(children[index], children2, "nickname", BDFDB.dotCN.input);
|
||||
}
|
||||
}
|
||||
|
||||
injectCounter (parent, children, type, refClass, parsing) {
|
||||
if (!children) return;
|
||||
parent.props.className = ((parent.props.className || "") + " " + BDFDB.disCN._charcountercounteradded).trim();
|
||||
children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CharCounter, {
|
||||
className: `${BDFDB.disCN._charcountercounter} ${type}`,
|
||||
refClass: refClass,
|
||||
parsing: parsing,
|
||||
max: maxLenghts[type]
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,408 +1,353 @@
|
|||
//META{"name":"CompleteTimestamps","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CompleteTimestamps","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CompleteTimestamps/CompleteTimestamps.plugin.js"}*//
|
||||
|
||||
class CompleteTimestamps {
|
||||
getName () {return "CompleteTimestamps";}
|
||||
|
||||
getVersion () {return "1.4.0";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Replace all timestamps with complete timestamps.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["System Messages", "Now properly works for system messages"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
Message: "render",
|
||||
MessageContent: "render",
|
||||
Embed: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.languages = {};
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showInChat: {value:true, description:"Replace Chat Timestamp with Complete Timestamp:"},
|
||||
showInEmbed: {value:true, description:"Replace Embed Timestamp with Complete Timestamp:"},
|
||||
showOnHover: {value:false, description:"Also show Timestamp when you hover over a message:"},
|
||||
changeForEdit: {value:false, description:"Change the Time for the Edited Time Tooltips:"},
|
||||
displayTime: {value:true, description:"Display the Time in the Timestamp:"},
|
||||
displayDate: {value:true, description:"Display the Date in the Timestamp:"},
|
||||
cutSeconds: {value:false, description:"Cut off Seconds of the Time:"},
|
||||
forceZeros: {value:false, description:"Force leading Zeros:"},
|
||||
otherOrder: {value:false, description:"Show the Time before the Date:"}
|
||||
},
|
||||
choices: {
|
||||
creationDateLang: {value:"$discord", description:"Timestamp Format:"}
|
||||
},
|
||||
formats: {
|
||||
ownFormat: {value:"$hour:$minute:$second, $day.$month.$year", description:"Own Format:"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let choices = BDFDB.DataUtils.get(this, "choices");
|
||||
let formats = BDFDB.DataUtils.get(this, "formats");
|
||||
let settingspanel, settingsitems = [];
|
||||
|
||||
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key],
|
||||
onChange: (e, instance) => {
|
||||
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:"BDFDB_SettingsPanel", up:true}), {name:"BDFDB_Select", all:true, noCopies:true}));
|
||||
}
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
|
||||
for (let key in choices) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Select",
|
||||
plugin: this,
|
||||
keys: ["choices", key],
|
||||
label: this.defaults.choices[key].description,
|
||||
basis: "70%",
|
||||
value: choices[key],
|
||||
options: BDFDB.ObjectUtils.toArray(BDFDB.ObjectUtils.map(this.languages, (lang, id) => {return {value:id, label:lang.name}})),
|
||||
searchable: true,
|
||||
optionRenderer: lang => {
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 0,
|
||||
shrink: 0,
|
||||
basis: "40%",
|
||||
children: lang.label
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 0,
|
||||
shrink: 0,
|
||||
basis: "60%",
|
||||
children: this.getTimestamp(this.languages[lang.value].id)
|
||||
})
|
||||
]
|
||||
});
|
||||
},
|
||||
valueRenderer: lang => {
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 0,
|
||||
shrink: 0,
|
||||
children: lang.label
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 1,
|
||||
shrink: 0,
|
||||
basis: "70%",
|
||||
children: this.getTimestamp(this.languages[lang.value].id)
|
||||
})
|
||||
]
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
|
||||
for (let key in formats) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "TextInput",
|
||||
plugin: this,
|
||||
keys: ["formats", key],
|
||||
label: this.defaults.formats[key].description,
|
||||
basis: "70%",
|
||||
value: formats[key],
|
||||
onChange: (e, instance) => {
|
||||
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:"BDFDB_SettingsPanel", up:true}), {name:"BDFDB_Select", all:true, noCopies:true}));
|
||||
}
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||
title: "Placeholder Guide",
|
||||
dividertop: true,
|
||||
collapsed: BDFDB.DataUtils.load(this, "hideInfo", "hideInfo"),
|
||||
children: ["$hour will be replaced with the current hour", "$minute will be replaced with the current minutes", "$second will be replaced with the current seconds", "$msecond will be replaced with the current milliseconds", "$timemode will change $hour to a 12h format and will be replaced with AM/PM", "$year will be replaced with the current year", "$month will be replaced with the current month", "$day will be replaced with the current day", "$monthnameL will be replaced with the monthname in long format based on the Discord Language", "$monthnameS will be replaced with the monthname in short format based on the Discord Language", "$weekdayL will be replaced with the weekday in long format based on the Discord Language", "$weekdayS will be replaced with the weekday in short format based on the Discord Language", "$daysago will be replaced with a string to tell you how many days ago the event occured. For Example: " + BDFDB.LanguageUtils.LanguageStringsFormat("ACTIVITY_FEED_USER_PLAYED_DAYS_AGO", 3)].map(string => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormText, {
|
||||
type: BDFDB.LibraryComponents.FormComponents.FormTextTypes.DESCRIPTION,
|
||||
children: string
|
||||
})),
|
||||
onClick: collapsed => {
|
||||
BDFDB.DataUtils.save(collapsed, this, "hideInfo", "hideInfo");
|
||||
}
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
this.languages = Object.assign({"own":{name:"Own",id:"own",integrated:false,dic:false}}, BDFDB.LanguageUtils.languages);
|
||||
|
||||
BDFDB.ModuleUtils.patch(this, (BDFDB.ModuleUtils.findByName("SystemMessage", false) || {}).exports, "default", {after: e => {
|
||||
this.processSystemMessage({instance:{props:e.methodArguments[0]}, returnvalue:e.returnValue, methodname:"default"});
|
||||
}});
|
||||
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.DOMUtils.removeLocalStyle(this.name + "CompactCorrection");
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
}
|
||||
|
||||
processMessage (e) {
|
||||
if (!e.instance.props.isCompact) {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (settings.showInChat) this.injectTimestamp(e.returnvalue, e.instance.props.message.timestamp);
|
||||
if (settings.showOnHover) this.injectTooltipWrapper(e.returnvalue, e.instance.props.message.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
processSystemMessage (e) {
|
||||
if (typeof e.returnvalue.props.children == "function") {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let renderChildren = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
if (settings.showInChat) this.injectTimestamp(renderedChildren, e.instance.props.timestamp, true);
|
||||
if (settings.showOnHover) this.injectTooltipWrapper(renderedChildren, e.instance.props.timestamp);
|
||||
return renderedChildren;
|
||||
};
|
||||
BDFDB.TimeUtils.timeout(this.setMaxWidth.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
processMessageContent (e) {
|
||||
if (typeof e.returnvalue.props.children == "function") {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let renderChildren = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
if (e.instance.props.isCompact && settings.showInChat) this.injectTimestamp(renderedChildren, e.instance.props.message.timestamp);
|
||||
if (settings.changeForEdit) this.injectEditStamp(renderedChildren, e.instance.props);
|
||||
return renderedChildren;
|
||||
};
|
||||
BDFDB.TimeUtils.timeout(this.setMaxWidth.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
processEmbed (e) {
|
||||
if (e.instance.props.embed.timestamp && BDFDB.DataUtils.get(this, "settings", "showInEmbed")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.embedfootertext]]});
|
||||
if (index > -1 && BDFDB.ArrayUtils.is(children[index].props.children)) children[index].props.children.splice(children[index].props.children.length - 1, 1, this.getTimestamp(this.languages[BDFDB.DataUtils.get(this, "choices", "creationDateLang")].id, e.instance.props.embed.timestamp._i));
|
||||
}
|
||||
}
|
||||
var CompleteTimestamps = (_ => {
|
||||
var languages;
|
||||
|
||||
injectTooltipWrapper (parent, timestamp) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(parent, {props:[["className", [BDFDB.disCN.messagecontent, BDFDB.disCN.messagesystemcontent]]]});
|
||||
if (index > -1) children[index] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: this.getTimestamp(this.languages[BDFDB.DataUtils.get(this, "choices", "creationDateLang")].id, timestamp._i),
|
||||
tooltipConfig: {
|
||||
type: "left"
|
||||
},
|
||||
children: children[index]
|
||||
});
|
||||
}
|
||||
|
||||
injectTimestamp (parent, timestamp, isSystem = false) {
|
||||
let [children, index] = isSystem ? BDFDB.ReactUtils.findChildren(parent, {props: [["className", BDFDB.disCN.messagetimestampsystem]]}) : BDFDB.ReactUtils.findChildren(parent, {name: "MessageTimestamp"});
|
||||
if (index > -1) {
|
||||
let props = children[index].props;
|
||||
if (!props.isCompact && !isSystem) children.splice(index++, 0, BDFDB.ReactUtils.createElement("span", {
|
||||
children: "ARABIC-FIX",
|
||||
style: {
|
||||
fontSize: 0,
|
||||
visibility: "hidden"
|
||||
return class CompleteTimestamps {
|
||||
getName () {return "CompleteTimestamps";}
|
||||
|
||||
getVersion () {return "1.4.1";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Replace all timestamps with complete timestamps.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
Message: "default",
|
||||
MessageHeader: "default",
|
||||
MessageContent: "type",
|
||||
Embed: "render",
|
||||
SystemMessage: "default"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showInChat: {value:true, description:"Replace Chat Timestamp with Complete Timestamp:"},
|
||||
showInEmbed: {value:true, description:"Replace Embed Timestamp with Complete Timestamp:"},
|
||||
changeForChat: {value:true, description:"Change the Time for the Chat Time Tooltips:"},
|
||||
changeForEdit: {value:true, description:"Change the Time for the Edited Time Tooltips:"},
|
||||
displayTime: {value:true, description:"Display the Time in the Timestamp:"},
|
||||
displayDate: {value:true, description:"Display the Date in the Timestamp:"},
|
||||
cutSeconds: {value:false, description:"Cut off Seconds of the Time:"},
|
||||
forceZeros: {value:false, description:"Force leading Zeros:"},
|
||||
otherOrder: {value:false, description:"Show the Time before the Date:"}
|
||||
},
|
||||
choices: {
|
||||
creationDateLang: {value:"$discord", description:"Timestamp Format:"}
|
||||
},
|
||||
formats: {
|
||||
ownFormat: {value:"$hour:$minute:$second, $day.$month.$year", description:"Own Format:"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel (collapseStates = {}) {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let choices = BDFDB.DataUtils.get(this, "choices");
|
||||
let formats = BDFDB.DataUtils.get(this, "formats");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in settings) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key],
|
||||
onChange: (e, instance) => {
|
||||
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:"BDFDB_SettingsPanel", up:true}), {name:"BDFDB_Select", all:true, noCopies:true}));
|
||||
}
|
||||
}));
|
||||
children.splice(index, 1, BDFDB.ReactUtils.createElement("time", {
|
||||
className: BDFDB.DOMUtils.formatClassName(props.backgroundOpacity && BDFDB.disCN["message" + props.backgroundOpacity + "backgroundopacity"], props.isVisibleOnlyOnHover && BDFDB.disCN.messagetimestampvisibleonhover, isSystem ? BDFDB.disCN.messagetimestampsystem : (props.isCompact ? (props.isMentioned ? BDFDB.disCN.messagetimestampcompactismentioned : BDFDB.disCN.messagetimestampcompact) : BDFDB.disCN.messagetimestampcozy)),
|
||||
dateTime: timestamp,
|
||||
children: [
|
||||
!isSystem && BDFDB.ReactUtils.createElement("i", {
|
||||
className: BDFDB.disCN.messagetimestampseparatorleft,
|
||||
children: props.isCompact ? "[" : " ["
|
||||
}),
|
||||
this.getTimestamp(this.languages[BDFDB.DataUtils.get(this, "choices", "creationDateLang")].id, timestamp._i),
|
||||
!isSystem && BDFDB.ReactUtils.createElement("i", {
|
||||
className: BDFDB.disCN.messagetimestampseparatorright,
|
||||
children: props.isCompact ? "] " : "]"
|
||||
})
|
||||
].filter(n => n)
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||
title: "Settings",
|
||||
collapseStates: collapseStates,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
inneritems = [];
|
||||
|
||||
for (let key in choices) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Select",
|
||||
plugin: this,
|
||||
keys: ["choices", key],
|
||||
label: this.defaults.choices[key].description,
|
||||
basis: "70%",
|
||||
value: choices[key],
|
||||
options: BDFDB.ObjectUtils.toArray(BDFDB.ObjectUtils.map(languages, (lang, id) => {return {value:id, label:lang.name}})),
|
||||
searchable: true,
|
||||
optionRenderer: lang => {
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 0,
|
||||
shrink: 0,
|
||||
basis: "40%",
|
||||
children: lang.label
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 0,
|
||||
shrink: 0,
|
||||
basis: "60%",
|
||||
children: this.getTimestamp(languages[lang.value].id)
|
||||
})
|
||||
]
|
||||
});
|
||||
},
|
||||
valueRenderer: lang => {
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 0,
|
||||
shrink: 0,
|
||||
children: lang.label
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
grow: 1,
|
||||
shrink: 0,
|
||||
basis: "70%",
|
||||
children: this.getTimestamp(languages[lang.value].id)
|
||||
})
|
||||
]
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
|
||||
for (let key in formats) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "TextInput",
|
||||
plugin: this,
|
||||
keys: ["formats", key],
|
||||
label: this.defaults.formats[key].description,
|
||||
basis: "70%",
|
||||
value: formats[key],
|
||||
onChange: (e, instance) => {
|
||||
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:"BDFDB_SettingsPanel", up:true}), {name:"BDFDB_Select", all:true, noCopies:true}));
|
||||
}
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||
title: "Format",
|
||||
collapseStates: collapseStates,
|
||||
dividertop: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||
title: "Placeholder Guide",
|
||||
collapseStates: collapseStates,
|
||||
dividertop: true,
|
||||
children: ["$hour will be replaced with the current hour", "$minute will be replaced with the current minutes", "$second will be replaced with the current seconds", "$msecond will be replaced with the current milliseconds", "$timemode will change $hour to a 12h format and will be replaced with AM/PM", "$year will be replaced with the current year", "$month will be replaced with the current month", "$day will be replaced with the current day", "$monthnameL will be replaced with the monthname in long format based on the Discord Language", "$monthnameS will be replaced with the monthname in short format based on the Discord Language", "$weekdayL will be replaced with the weekday in long format based on the Discord Language", "$weekdayS will be replaced with the weekday in short format based on the Discord Language", "$daysago will be replaced with a string to tell you how many days ago the event occured. For Example: " + BDFDB.LanguageUtils.LanguageStringsFormat("ACTIVITY_FEED_USER_PLAYED_DAYS_AGO", 3)].map(string => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormText, {
|
||||
type: BDFDB.LibraryComponents.FormComponents.FormTextTypes.DESCRIPTION,
|
||||
children: string
|
||||
}))
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
}
|
||||
|
||||
injectEditStamp (parent, props) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(parent, {name: "SuffixEdited"});
|
||||
if (index > -1) children.splice(index, 1, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: this.getTimestamp(this.languages[BDFDB.DataUtils.get(this, "choices", "creationDateLang")].id, props.message.editedTimestamp._i),
|
||||
children: BDFDB.ReactUtils.createElement("time", {
|
||||
className: BDFDB.disCN.messageedited,
|
||||
dateTime: props.message.editedTimestamp,
|
||||
children: `(${BDFDB.LanguageStrings.MESSAGE_EDITED.toLowerCase()})`
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
getTimestamp (languageid, time) {
|
||||
let timeobj = time ? time : new Date();
|
||||
if (typeof time == "string") timeobj = new Date(time);
|
||||
if (timeobj.toString() == "Invalid Date") timeobj = new Date(parseInt(time));
|
||||
if (timeobj.toString() == "Invalid Date") return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings"), timestring = "";
|
||||
if (languageid != "own") {
|
||||
let timestamp = [];
|
||||
if (settings.displayDate) timestamp.push(timeobj.toLocaleDateString(languageid));
|
||||
if (settings.displayTime) timestamp.push(settings.cutSeconds ? this.cutOffSeconds(timeobj.toLocaleTimeString(languageid)) : timeobj.toLocaleTimeString(languageid));
|
||||
if (settings.otherOrder) timestamp.reverse();
|
||||
timestring = timestamp.length > 1 ? timestamp.join(", ") : (timestamp.length > 0 ? timestamp[0] : "");
|
||||
if (timestring && settings.forceZeros) timestring = this.addLeadingZeros(timestring);
|
||||
}
|
||||
else {
|
||||
let ownformat = BDFDB.DataUtils.get(this, "formats", "ownFormat");
|
||||
languageid = BDFDB.LanguageUtils.getLanguage().id;
|
||||
let hour = timeobj.getHours(), minute = timeobj.getMinutes(), second = timeobj.getSeconds(), msecond = timeobj.getMilliseconds(), day = timeobj.getDate(), month = timeobj.getMonth()+1, timemode = "", daysago = Math.round((new Date() - timeobj)/(1000*60*60*24));
|
||||
if (ownformat.indexOf("$timemode") > -1) {
|
||||
timemode = hour >= 12 ? "PM" : "AM";
|
||||
hour = hour % 12;
|
||||
hour = hour ? hour : 12;
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
timestring = ownformat
|
||||
.replace("$hour", settings.forceZeros && hour < 10 ? "0" + hour : hour)
|
||||
.replace("$minute", minute < 10 ? "0" + minute : minute)
|
||||
.replace("$second", second < 10 ? "0" + second : second)
|
||||
.replace("$msecond", settings.forceZeros ? (msecond < 10 ? "00" + msecond : (msecond < 100 ? "0" + msecond : msecond)) : msecond)
|
||||
.replace("$timemode", timemode)
|
||||
.replace("$weekdayL", timeobj.toLocaleDateString(languageid,{weekday: "long"}))
|
||||
.replace("$weekdayS", timeobj.toLocaleDateString(languageid,{weekday: "short"}))
|
||||
.replace("$monthnameL", timeobj.toLocaleDateString(languageid,{month: "long"}))
|
||||
.replace("$monthnameS", timeobj.toLocaleDateString(languageid,{month: "short"}))
|
||||
.replace("$daysago", daysago > 0 ? BDFDB.LanguageUtils.LanguageStringsFormat("ACTIVITY_FEED_USER_PLAYED_DAYS_AGO", daysago) : BDFDB.LanguageUtils.LanguageStrings.SEARCH_SHORTCUT_TODAY)
|
||||
.replace("$day", settings.forceZeros && day < 10 ? "0" + day : day)
|
||||
.replace("$month", settings.forceZeros && month < 10 ? "0" + month : month)
|
||||
.replace("$year", timeobj.getFullYear())
|
||||
.trim().split(" ").filter(n => n).join(" ");
|
||||
}
|
||||
return timestring;
|
||||
}
|
||||
|
||||
cutOffSeconds (timestring) {
|
||||
return timestring.replace(/(.{1,2}:.{1,2}):.{1,2}(.*)/, "$1$2").replace(/(.{1,2}\..{1,2})\..{1,2}(.*)/, "$1$2").replace(/(.{1,2} h .{1,2} min) .{1,2} s(.*)/, "$1$2");
|
||||
}
|
||||
|
||||
addLeadingZeros (timestring) {
|
||||
let chararray = timestring.split("");
|
||||
let numreg = /[0-9]/;
|
||||
for (let i = 0; i < chararray.length; i++) {
|
||||
if (!numreg.test(chararray[i-1]) && numreg.test(chararray[i]) && !numreg.test(chararray[i+1])) chararray[i] = "0" + chararray[i];
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
return chararray.join("");
|
||||
}
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
setMaxWidth () {
|
||||
if (this.currentMode != BDFDB.DiscordUtils.getMode()) {
|
||||
this.currentMode = BDFDB.DiscordUtils.getMode();
|
||||
let timestamp = document.querySelector(BDFDB.dotCN.messagetimestampcompact);
|
||||
if (timestamp) {
|
||||
let choice = BDFDB.DataUtils.get(this, "choices", "creationDateLang");
|
||||
let testtimestamp = BDFDB.DOMUtils.create(`<time class="${timestamp.className}" style="width: auto !important;">${this.getTimestamp(this.languages[choice].id, new Date(253402124399995))}</time>`);
|
||||
document.body.appendChild(testtimestamp);
|
||||
let width = BDFDB.DOMUtils.getRects(testtimestamp).width + 5;
|
||||
testtimestamp.remove();
|
||||
BDFDB.DOMUtils.appendLocalStyle(this.name + "CompactCorrection", `
|
||||
${BDFDB.dotCN.messagetimestampcompact} {
|
||||
width: ${width}px !important;
|
||||
}
|
||||
${BDFDB.dotCN.messagetimestampcompactismentioned} {
|
||||
width: ${width + 2}px !important;
|
||||
}
|
||||
${BDFDB.dotCN.messagemarkupiscompact} {
|
||||
margin-left: calc(${width}px + 4ch) !important;
|
||||
text-indent: calc(-${width}px - 4ch) !important;
|
||||
}
|
||||
${BDFDB.dotCN.messagemarkupiscompact} > label {
|
||||
margin-left: calc(${width}px + 4ch) !important;
|
||||
}
|
||||
${BDFDB.dotCN.messageaccessorycompact} {
|
||||
padding-left: ${width}px !important;
|
||||
}
|
||||
`);
|
||||
languages = Object.assign({"own":{name:"Own",id:"own",integrated:false,dic:false}}, BDFDB.LanguageUtils.languages);
|
||||
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
else BDFDB.DOMUtils.removeLocalStyle(this.name + "CompactCorrection");
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.DOMUtils.removeLocalStyle(this.name + "CompactCorrection");
|
||||
|
||||
this.forceUpdateAll();
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
}
|
||||
|
||||
processMessage (e) {
|
||||
if (BDFDB.ReactUtils.getValue(e, "instance.props.childrenHeader.type.type.displayName") == "MessageTimestamp" && BDFDB.DataUtils.get(this, "settings", "changeForChat")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: e.instance.props.childrenHeader.type});
|
||||
if (index > -1) this.changeTimestamp(children, index, {child:false, tooltip:true});
|
||||
}
|
||||
}
|
||||
|
||||
processMessageHeader (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "MessageTimestamp"});
|
||||
if (index > -1) {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
this.changeTimestamp(children, index, {child:!e.instance.props.compact && settings.showInChat, tooltip:settings.changeForChat});
|
||||
}
|
||||
}
|
||||
|
||||
processMessageContent (e) {
|
||||
if (e.instance.props.message.editedTimestamp && BDFDB.DataUtils.get(this, "settings", "changeForEdit")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "SuffixEdited"});
|
||||
if (index > -1) this.changeTimestamp(children, index, {child:false, tooltip:true});
|
||||
}
|
||||
}
|
||||
|
||||
processEmbed (e) {
|
||||
if (e.instance.props.embed.timestamp && BDFDB.DataUtils.get(this, "settings", "showInEmbed")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.embedfootertext]]});
|
||||
if (index > -1 && BDFDB.ArrayUtils.is(children[index].props.children)) children[index].props.children.splice(children[index].props.children.length-1, 1, this.getTimestamp(languages[BDFDB.DataUtils.get(this, "choices", "creationDateLang")].id, e.instance.props.embed.timestamp._i));
|
||||
}
|
||||
}
|
||||
|
||||
processSystemMessage (e) {
|
||||
if (BDFDB.DataUtils.get(this, "settings", "showInChat")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "time"});
|
||||
if (index > -1) children[index].props.children = this.getTimestamp(languages[BDFDB.DataUtils.get(this, "choices", "creationDateLang")].id, e.instance.props.timestamp._i);
|
||||
}
|
||||
}
|
||||
|
||||
changeTimestamp (parent, index, change = {}) {
|
||||
let type = parent[index].type && parent[index].type.type || parent[index].type;
|
||||
if (typeof type != "function") return;
|
||||
let stamp = type(parent[index].props), tooltipWrapper;
|
||||
if (stamp.type.displayName == "Tooltip") tooltipWrapper = stamp;
|
||||
else {
|
||||
let [children, tooltipIndex] = BDFDB.ReactUtils.findChildren(stamp, {name: "Tooltip"});
|
||||
if (tooltipIndex > -1) tooltipWrapper = children[tooltipIndex];
|
||||
}
|
||||
if (tooltipWrapper) {
|
||||
let timestamp = this.getTimestamp(languages[BDFDB.DataUtils.get(this, "choices", "creationDateLang")].id, parent[index].props.timestamp._i);
|
||||
if (change.tooltip) {
|
||||
tooltipWrapper.props.text = timestamp;
|
||||
tooltipWrapper.props.delay = 0;
|
||||
}
|
||||
if (change.child && typeof tooltipWrapper.props.children == "function") {
|
||||
tooltipWrapper.props.delay = 99999999999999999999;
|
||||
let renderChildren = tooltipWrapper.props.children;
|
||||
tooltipWrapper.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
if (BDFDB.ArrayUtils.is(renderedChildren.props.children)) renderedChildren.props.children[1] = timestamp;
|
||||
else renderChildren.props.children = timestamp;
|
||||
return renderedChildren;
|
||||
};
|
||||
}
|
||||
}
|
||||
parent[index] = stamp;
|
||||
}
|
||||
|
||||
getTimestamp (languageid, time) {
|
||||
let timeobj = time ? time : new Date();
|
||||
if (typeof time == "string") timeobj = new Date(time);
|
||||
if (timeobj.toString() == "Invalid Date") timeobj = new Date(parseInt(time));
|
||||
if (timeobj.toString() == "Invalid Date") return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings"), timestring = "";
|
||||
if (languageid != "own") {
|
||||
let timestamp = [];
|
||||
if (settings.displayDate) timestamp.push(timeobj.toLocaleDateString(languageid));
|
||||
if (settings.displayTime) timestamp.push(settings.cutSeconds ? this.cutOffSeconds(timeobj.toLocaleTimeString(languageid)) : timeobj.toLocaleTimeString(languageid));
|
||||
if (settings.otherOrder) timestamp.reverse();
|
||||
timestring = timestamp.length > 1 ? timestamp.join(", ") : (timestamp.length > 0 ? timestamp[0] : "");
|
||||
if (timestring && settings.forceZeros) timestring = this.addLeadingZeros(timestring);
|
||||
}
|
||||
else {
|
||||
let ownformat = BDFDB.DataUtils.get(this, "formats", "ownFormat");
|
||||
languageid = BDFDB.LanguageUtils.getLanguage().id;
|
||||
let hour = timeobj.getHours(), minute = timeobj.getMinutes(), second = timeobj.getSeconds(), msecond = timeobj.getMilliseconds(), day = timeobj.getDate(), month = timeobj.getMonth()+1, timemode = "", daysago = Math.round((new Date() - timeobj)/(1000*60*60*24));
|
||||
if (ownformat.indexOf("$timemode") > -1) {
|
||||
timemode = hour >= 12 ? "PM" : "AM";
|
||||
hour = hour % 12;
|
||||
hour = hour ? hour : 12;
|
||||
}
|
||||
timestring = ownformat
|
||||
.replace("$hour", settings.forceZeros && hour < 10 ? "0" + hour : hour)
|
||||
.replace("$minute", minute < 10 ? "0" + minute : minute)
|
||||
.replace("$second", second < 10 ? "0" + second : second)
|
||||
.replace("$msecond", settings.forceZeros ? (msecond < 10 ? "00" + msecond : (msecond < 100 ? "0" + msecond : msecond)) : msecond)
|
||||
.replace("$timemode", timemode)
|
||||
.replace("$weekdayL", timeobj.toLocaleDateString(languageid,{weekday: "long"}))
|
||||
.replace("$weekdayS", timeobj.toLocaleDateString(languageid,{weekday: "short"}))
|
||||
.replace("$monthnameL", timeobj.toLocaleDateString(languageid,{month: "long"}))
|
||||
.replace("$monthnameS", timeobj.toLocaleDateString(languageid,{month: "short"}))
|
||||
.replace("$daysago", daysago > 0 ? BDFDB.LanguageUtils.LanguageStringsFormat("ACTIVITY_FEED_USER_PLAYED_DAYS_AGO", daysago) : BDFDB.LanguageUtils.LanguageStrings.SEARCH_SHORTCUT_TODAY)
|
||||
.replace("$day", settings.forceZeros && day < 10 ? "0" + day : day)
|
||||
.replace("$month", settings.forceZeros && month < 10 ? "0" + month : month)
|
||||
.replace("$year", timeobj.getFullYear())
|
||||
.trim().split(" ").filter(n => n).join(" ");
|
||||
}
|
||||
return timestring;
|
||||
}
|
||||
|
||||
cutOffSeconds (timestring) {
|
||||
return timestring.replace(/(.{1,2}:.{1,2}):.{1,2}(.*)/, "$1$2").replace(/(.{1,2}\..{1,2})\..{1,2}(.*)/, "$1$2").replace(/(.{1,2} h .{1,2} min) .{1,2} s(.*)/, "$1$2");
|
||||
}
|
||||
|
||||
addLeadingZeros (timestring) {
|
||||
let chararray = timestring.split("");
|
||||
let numreg = /[0-9]/;
|
||||
for (let i = 0; i < chararray.length; i++) {
|
||||
if (!numreg.test(chararray[i-1]) && numreg.test(chararray[i]) && !numreg.test(chararray[i+1])) chararray[i] = "0" + chararray[i];
|
||||
}
|
||||
|
||||
return chararray.join("");
|
||||
}
|
||||
|
||||
forceUpdateAll() {
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
BDFDB.MessageUtils.rerenderAll();
|
||||
}
|
||||
}
|
||||
|
||||
forceUpdateAll () {
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:"SystemMessageWrapper", unlimited:true, all:true}));
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,94 +1,119 @@
|
|||
//META{"name":"CopyRawMessage","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/CopyRawMessage","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/CopyRawMessage/CopyRawMessage.plugin.js"}*//
|
||||
|
||||
class CopyRawMessage {
|
||||
getName () {return "CopyRawMessage";}
|
||||
var CopyRawMessage = (_ => {
|
||||
const copyRawIcon = `<svg width="512" height="512" viewBox="0 0 64 64"><path fill="currentColor" d="m54 8h-44c-1.104 0-2 .896-2 2s.896 2 2 2h44c1.104 0 2-.896 2-2s-.896-2-2-2z"/><path fill="currentColor" d="m54 52h-44c-1.104 0-2 .896-2 2s.896 2 2 2h44c1.104 0 2-.896 2-2s-.896-2-2-2z"/><path fill="currentColor" d="m54 19h-28c-1.104 0-2 .896-2 2s.896 2 2 2h28c1.104 0 2-.896 2-2s-.896-2-2-2z"/><path fill="currentColor" d="m54 30h-44c-1.104 0-2 .896-2 2s.896 2 2 2h44c1.104 0 2-.896 2-2s-.896-2-2-2z"/><path fill="currentColor" d="m54 41h-28c-1.104 0-2 .896-2 2s.896 2 2 2h28c1.104 0 2-.896 2-2s-.896-2-2-2z"/></svg>`;
|
||||
|
||||
return class CopyRawMessage {
|
||||
getName () {return "CopyRawMessage";}
|
||||
|
||||
getVersion () {return "1.0.3";}
|
||||
getVersion () {return "1.0.4";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds a entry in the contextmenu when you right click a message that allows you to copy the raw contents of a message.";}
|
||||
getDescription () {return "Adds a entry in the contextmenu when you right click a message that allows you to copy the raw contents of a message.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
// begin of own functions
|
||||
|
||||
onMessageContextMenu (e) {
|
||||
if (e.instance.props.message && e.instance.props.message.content) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
|
||||
const itemgroup = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
|
||||
hint: BDFDB.BDUtils.isPluginEnabled("MessageUtilities") ? BDFDB.BDUtils.getPlugin("MessageUtilities").getActiveShortcutString("Copy_Raw") : null,
|
||||
action: _ => {
|
||||
BDFDB.ContextMenuUtils.close(e.instance);
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:e.instance.props.message.content});
|
||||
}
|
||||
onMessageContextMenu (e) {
|
||||
if (e.instance.props.message && e.instance.props.message.content) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
|
||||
children.splice(index > -1 ? index : children.length, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
|
||||
hint: BDFDB.BDUtils.isPluginEnabled("MessageUtilities") ? BDFDB.BDUtils.getPlugin("MessageUtilities").getActiveShortcutString("Copy_Raw") : null,
|
||||
action: _ => {
|
||||
BDFDB.ContextMenuUtils.close(e.instance);
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:e.instance.props.message.content});
|
||||
}
|
||||
})
|
||||
]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
onMessageOptionToolbar (e) {
|
||||
if (!e.instance.props.hasMorePopout && e.instance.props.message && e.instance.props.channel) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {key: ["mark-unread"]});
|
||||
children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
|
||||
className: BDFDB.disCNS.messagetoolbarbutton,
|
||||
onClick: _ => {BDFDB.LibraryRequires.electron.clipboard.write({text:e.instance.props.message.content});},
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCNS.messagetoolbaricon,
|
||||
nativeClass: true,
|
||||
iconSVG: copyRawIcon
|
||||
})
|
||||
})
|
||||
]
|
||||
});
|
||||
if (index > -1) children.splice(index, 0, itemgroup);
|
||||
else children.push(itemgroup);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMessageOptionPopout (e) {
|
||||
if (e.instance.props.message) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["label", BDFDB.LanguageUtils.LanguageStrings.DELETE]]});
|
||||
children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
|
||||
className: BDFDB.disCN.optionpopoutitem,
|
||||
action: _ => {
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:e.instance.props.message.content});
|
||||
e.instance.props.onClose();
|
||||
}
|
||||
}));
|
||||
onMessageOptionContextMenu (e) {
|
||||
if (e.instance.props.message && e.instance.props.channel) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {key: ["mark-unread"]});
|
||||
children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
|
||||
hint: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCNS.messagetoolbaricon,
|
||||
nativeClass: true,
|
||||
iconSVG: copyRawIcon
|
||||
}),
|
||||
action: _ => {
|
||||
e.instance.props.onClose();
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:e.instance.props.message.content});
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,137 +1,148 @@
|
|||
//META{"name":"ForceImagePreviews","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ForceImagePreviews","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ForceImagePreviews/ForceImagePreviews.plugin.js"}*//
|
||||
|
||||
class ForceImagePreviews {
|
||||
getName () {return "ForceImagePreviews";}
|
||||
var ForceImagePreviews = (_ => {
|
||||
return class ForceImagePreviews {
|
||||
getName () {return "ForceImagePreviews";}
|
||||
|
||||
getVersion () {return "1.1.5";}
|
||||
getVersion () {return "1.1.6";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Forces embedded Image Previews, if Discord doesn't do it itself. Caution: Externals Images can contain malicious code and reveal your IP!";}
|
||||
getDescription () {return "Forces embedded Image Previews, if Discord doesn't do it itself. Caution: Externals Images can contain malicious code and reveal your IP!";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
}
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.patch(this, (BDFDB.ModuleUtils.findByName("MessageAccessories") || {}).prototype, "render", {before: e => {
|
||||
if (e.thisObject.props.message.content) {
|
||||
let message = new BDFDB.DiscordObjects.Message(e.thisObject.props.message);
|
||||
for (let word of e.thisObject.props.message.content.split(/\n|\s|\r|\t|\0/g)) if (word.indexOf("https://") > -1 || word.indexOf("http://") > -1) {
|
||||
word = word.indexOf("<") == 0 && word.indexOf(">") == word.length-1 ? word.slice(1,-1) : word;
|
||||
if (!this.isEmbedded(message.embeds, word)) this.injectEmbed(e.thisObject, message.embeds, word);
|
||||
}
|
||||
e.thisObject.props.message = message;
|
||||
this.patchedModules = {
|
||||
before: {
|
||||
SimpleMessageAccessories: "default"
|
||||
}
|
||||
}});
|
||||
|
||||
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:"MessageAccessories", all:true, noCopies:true, unlimited:true}));
|
||||
};
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
injectEmbed (instance, embeds, link) {
|
||||
BDFDB.LibraryRequires.request(link, (error, response, result) => {
|
||||
if (response && response.headers["content-type"] && response.headers["content-type"].indexOf("image") > -1) {
|
||||
let imagethrowaway = document.createElement("img");
|
||||
imagethrowaway.src = link;
|
||||
imagethrowaway.onload = _ => {
|
||||
// begin of own functions
|
||||
|
||||
processSimpleMessageAccessories (e) {
|
||||
if (e.instance.props.message.content) {
|
||||
let message = new BDFDB.DiscordObjects.Message(e.instance.props.message);
|
||||
for (let word of e.instance.props.message.content.split(/\n|\s|\r|\t|\0/g)) if (word.indexOf("https://") > -1 || word.indexOf("http://") > -1) {
|
||||
word = word.indexOf("<") == 0 && word.indexOf(">") == word.length-1 ? word.slice(1,-1) : word;
|
||||
if (!this.isEmbedded(message.embeds, word)) this.injectEmbed(e.instance, message.embeds, word);
|
||||
}
|
||||
e.instance.props.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
injectEmbed (instance, embeds, link) {
|
||||
BDFDB.LibraryRequires.request(link, (error, response, result) => {
|
||||
if (response && response.headers["content-type"] && response.headers["content-type"].indexOf("image") > -1) {
|
||||
let imagethrowaway = document.createElement("img");
|
||||
imagethrowaway.src = link;
|
||||
imagethrowaway.onload = _ => {
|
||||
if (!this.isEmbedded(embeds, link)) {
|
||||
embeds.push({
|
||||
image: {
|
||||
url: link,
|
||||
proxyURL: link,
|
||||
height: imagethrowaway.naturalHeight,
|
||||
width: imagethrowaway.naturalWidth
|
||||
},
|
||||
type: "image",
|
||||
url: link
|
||||
});
|
||||
BDFDB.ReactUtils.forceUpdate(instance);
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (response && response.headers["server"] && response.headers["server"].toLowerCase().indexOf("youtube") > -1 && result.indexOf("yt-user-info") > -1) {
|
||||
if (!this.isEmbedded(embeds, link)) {
|
||||
result = result.replace(/[\r|\n|\t]|[\s]{2,}/g, "");
|
||||
let width = result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta itemprop="width" content="'), "i"))[1].split('"')[0];
|
||||
let height = result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta itemprop="height" content="'), "i"))[1].split('"')[0];
|
||||
let thumbnail = result.split(new RegExp(BDFDB.StringUtils.regEscape('<link itemprop="thumbnailUrl" href="'), "i"))[1].split('"')[0];
|
||||
embeds.push({
|
||||
image: {
|
||||
url: link,
|
||||
proxyURL: link,
|
||||
height: imagethrowaway.naturalHeight,
|
||||
width: imagethrowaway.naturalWidth
|
||||
author: {
|
||||
name: result.split(new RegExp(BDFDB.StringUtils.regEscape('<div class="yt-user-info"><a href="'), "i"))[1].split('>')[1].split('<')[0],
|
||||
url: `https://www.youtube.com${result.split(new RegExp(BDFDB.StringUtils.regEscape('<div class="yt-user-info"><a href="'), "i"))[1].split('"')[0]}`
|
||||
},
|
||||
type: "image",
|
||||
url: link
|
||||
color: "#ff0000",
|
||||
provider: {
|
||||
name: "YouTube",
|
||||
url: "https://www.youtube.com/"
|
||||
},
|
||||
rawDescription: result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta property="og:description" content="'), "i"))[1].split('"')[0],
|
||||
rawTitle: result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta property="og:title" content="'), "i"))[1].split('"')[0],
|
||||
thumbnail: {
|
||||
url: thumbnail,
|
||||
proxyURL: thumbnail,
|
||||
width: width,
|
||||
height: height
|
||||
},
|
||||
type: "video",
|
||||
url: link,
|
||||
video: {
|
||||
url: result.split(new RegExp(BDFDB.StringUtils.regEscape('<link itemprop="embedUrl" href="'), "i"))[1].split('"')[0],
|
||||
width: width,
|
||||
height: height
|
||||
}
|
||||
});
|
||||
BDFDB.ReactUtils.forceUpdate(instance);
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (response && response.headers["server"] && response.headers["server"].toLowerCase().indexOf("youtube") > -1 && result.indexOf("yt-user-info") > -1) {
|
||||
if (!this.isEmbedded(embeds, link)) {
|
||||
result = result.replace(/[\r|\n|\t]|[\s]{2,}/g, "");
|
||||
let width = result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta itemprop="width" content="'), "i"))[1].split('"')[0];
|
||||
let height = result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta itemprop="height" content="'), "i"))[1].split('"')[0];
|
||||
let thumbnail = result.split(new RegExp(BDFDB.StringUtils.regEscape('<link itemprop="thumbnailUrl" href="'), "i"))[1].split('"')[0];
|
||||
embeds.push({
|
||||
author: {
|
||||
name: result.split(new RegExp(BDFDB.StringUtils.regEscape('<div class="yt-user-info"><a href="'), "i"))[1].split('>')[1].split('<')[0],
|
||||
url: `https://www.youtube.com${result.split(new RegExp(BDFDB.StringUtils.regEscape('<div class="yt-user-info"><a href="'), "i"))[1].split('"')[0]}`
|
||||
},
|
||||
color: "#ff0000",
|
||||
provider: {
|
||||
name: "YouTube",
|
||||
url: "https://www.youtube.com/"
|
||||
},
|
||||
rawDescription: result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta property="og:description" content="'), "i"))[1].split('"')[0],
|
||||
rawTitle: result.split(new RegExp(BDFDB.StringUtils.regEscape('<meta property="og:title" content="'), "i"))[1].split('"')[0],
|
||||
thumbnail: {
|
||||
url: thumbnail,
|
||||
proxyURL: thumbnail,
|
||||
width: width,
|
||||
height: height
|
||||
},
|
||||
type: "video",
|
||||
url: link,
|
||||
video: {
|
||||
url: result.split(new RegExp(BDFDB.StringUtils.regEscape('<link itemprop="embedUrl" href="'), "i"))[1].split('"')[0],
|
||||
width: width,
|
||||
height: height
|
||||
}
|
||||
});
|
||||
BDFDB.ReactUtils.forceUpdate(instance);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
isEmbedded (embeds, link) {
|
||||
for (let embed of embeds) if (embed.url == link) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
isEmbedded (embeds, link) {
|
||||
for (let embed of embeds) if (embed.url == link) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
})();
|
File diff suppressed because it is too large
Load Diff
|
@ -1,181 +1,201 @@
|
|||
//META{"name":"ImageGallery","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ImageGallery","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ImageGallery/ImageGallery.plugin.js"}*//
|
||||
|
||||
class ImageGallery {
|
||||
getName () {return "ImageGallery";}
|
||||
var ImageGallery = (_ => {
|
||||
var eventFired;
|
||||
|
||||
return class ImageGallery {
|
||||
getName () {return "ImageGallery";}
|
||||
|
||||
getVersion () {return "1.6.2";}
|
||||
getVersion () {return "1.6.3";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Allows the user to browse through images sent inside the same message.";}
|
||||
getDescription () {return "Allows the user to browse through images sent inside the same message.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Spoiler Images","No longer included unrevealed as spoiler marked images in the gallery preview"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
ImageModal: ["render", "componentDidMount"]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.eventFired = false;
|
||||
|
||||
this.css = `
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegalleryprevious},
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegallerynext} {
|
||||
position: fixed;
|
||||
z-index: -1;
|
||||
}
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegalleryprevious} {
|
||||
right: 90%;
|
||||
}
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegallerynext} {
|
||||
left: 90%;
|
||||
}`;
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
processImageModal (e) {
|
||||
let message = this.getMessageGroupOfImage(e.instance.props.src);
|
||||
if (message) {
|
||||
if (e.returnvalue) {
|
||||
let images = Array.from(message.querySelectorAll(BDFDB.dotCNS.imagewrapper + "img")).filter(img => !BDFDB.DOMUtils.getParent(BDFDB.dotCN.spoilerhidden, img));
|
||||
let next, previous;
|
||||
for (let i = 0; i < images.length; i++) if (this.getSrcOfImage(e.instance.props.src) == this.getSrcOfImage(images[i])) {
|
||||
next = this.getSrcOfImage(images[i+1]);
|
||||
previous = this.getSrcOfImage(images[i-1]);
|
||||
break;
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
ImageModal: ["render", "componentDidMount"]
|
||||
}
|
||||
if (next) {
|
||||
if (e.instance.nextRef) e.returnvalue.props.children.splice(1, 0, e.instance.nextRef);
|
||||
else this.loadImage(e.instance, this.getSrcOfImage(next), "next");
|
||||
}
|
||||
if (previous) {
|
||||
if (e.instance.previousRef) e.returnvalue.props.children.push(e.instance.previousRef);
|
||||
else this.loadImage(e.instance, this.getSrcOfImage(previous), "previous");
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegalleryprevious},
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegallerynext} {
|
||||
position: fixed;
|
||||
z-index: -1;
|
||||
}
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegalleryprevious} {
|
||||
right: 90%;
|
||||
}
|
||||
${BDFDB.dotCNS._imagegallerygallery + BDFDB.dotCN.imagewrapper + BDFDB.dotCN._imagegallerynext} {
|
||||
left: 90%;
|
||||
}`;
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
if (e.node) {
|
||||
BDFDB.DOMUtils.addClass(BDFDB.DOMUtils.getParent(BDFDB.dotCN.modal, e.node), BDFDB.disCN._imagegallerygallery);
|
||||
this.cleanUpListeners();
|
||||
document.keydownImageGalleryListener = event => {
|
||||
if (!document.contains(e.node)) this.cleanUpListeners();
|
||||
else if (!this.eventFired) {
|
||||
this.eventFired = true;
|
||||
if (event.keyCode == 37) this.switchImages(e.instance, "previous");
|
||||
else if (event.keyCode == 39) this.switchImages(e.instance, "next");
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
eventFired = false;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
processImageModal (e) {
|
||||
let messages = this.getMessageGroupOfImage(e.instance.props.src);
|
||||
if (messages.length) {
|
||||
if (e.returnvalue) {
|
||||
let images = messages.map(n => Array.from(n.querySelectorAll(BDFDB.dotCNS.imagewrapper + "img"))).flat().filter(img => !BDFDB.DOMUtils.getParent(BDFDB.dotCN.spoilerhidden, img));
|
||||
let next, previous;
|
||||
for (let i = 0; i < images.length; i++) if (this.getSrcOfImage(e.instance.props.src) == this.getSrcOfImage(images[i])) {
|
||||
next = this.getSrcOfImage(images[i+1]);
|
||||
previous = this.getSrcOfImage(images[i-1]);
|
||||
break;
|
||||
}
|
||||
};
|
||||
document.keyupImageGalleryListener = _ => {
|
||||
this.eventFired = false;
|
||||
if (!document.contains(e.node)) this.cleanUpListeners();
|
||||
};
|
||||
document.addEventListener("keydown", document.keydownImageGalleryListener);
|
||||
document.addEventListener("keyup", document.keyupImageGalleryListener);
|
||||
if (next) {
|
||||
if (e.instance.nextRef) e.returnvalue.props.children.splice(1, 0, e.instance.nextRef);
|
||||
else this.loadImage(e.instance, this.getSrcOfImage(next), "next");
|
||||
}
|
||||
if (previous) {
|
||||
if (e.instance.previousRef) e.returnvalue.props.children.push(e.instance.previousRef);
|
||||
else this.loadImage(e.instance, this.getSrcOfImage(previous), "previous");
|
||||
}
|
||||
}
|
||||
if (e.node) {
|
||||
BDFDB.DOMUtils.addClass(BDFDB.DOMUtils.getParent(BDFDB.dotCN.modal, e.node), BDFDB.disCN._imagegallerygallery);
|
||||
this.cleanUpListeners();
|
||||
document.keydownImageGalleryListener = event => {
|
||||
if (!document.contains(e.node)) this.cleanUpListeners();
|
||||
else if (!eventFired) {
|
||||
eventFired = true;
|
||||
if (event.keyCode == 37) this.switchImages(e.instance, "previous");
|
||||
else if (event.keyCode == 39) this.switchImages(e.instance, "next");
|
||||
}
|
||||
};
|
||||
document.keyupImageGalleryListener = _ => {
|
||||
eventFired = false;
|
||||
if (!document.contains(e.node)) this.cleanUpListeners();
|
||||
};
|
||||
document.addEventListener("keydown", document.keydownImageGalleryListener);
|
||||
document.addEventListener("keyup", document.keyupImageGalleryListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getMessageGroupOfImage (src) {
|
||||
if (src) for (let group of document.querySelectorAll(BDFDB.dotCN.messagegroup)) for (let img of group.querySelectorAll(BDFDB.dotCNS.imagewrapper + "img")) if (img.src && this.getSrcOfImage(img) == this.getSrcOfImage(src)) return group;
|
||||
return null;
|
||||
}
|
||||
getMessageGroupOfImage (src) {
|
||||
if (src) for (let message of document.querySelectorAll(BDFDB.dotCN.message)) for (let img of message.querySelectorAll(BDFDB.dotCNS.imagewrapper + "img")) if (img.src && this.getSrcOfImage(img) == this.getSrcOfImage(src)) {
|
||||
let previousSiblings = [], nextSiblings = [];
|
||||
let previousSibling = message.previousSibling, nextSibling = message.nextSibling;
|
||||
while (previousSibling) {
|
||||
previousSiblings.push(previousSibling);
|
||||
if (BDFDB.DOMUtils.containsClass(previousSibling, BDFDB.disCN.messagegroupstart)) previousSibling = null;
|
||||
else previousSibling = previousSibling.previousSibling;
|
||||
}
|
||||
while (nextSibling) {
|
||||
if (!BDFDB.DOMUtils.containsClass(nextSibling, BDFDB.disCN.messagegroupstart)) {
|
||||
nextSiblings.push(nextSibling);
|
||||
nextSibling = nextSibling.nextSibling;
|
||||
}
|
||||
else nextSibling = null;
|
||||
}
|
||||
return [].concat(previousSiblings.reverse(), message, nextSiblings).filter(n => n && BDFDB.DOMUtils.containsClass(n, BDFDB.disCN.message));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
getSrcOfImage (img) {
|
||||
if (!img) return null;
|
||||
return (typeof img == "string" ? img : (img.src || (img.querySelector("canvas") ? img.querySelector("canvas").src : ""))).split("?width=")[0];
|
||||
}
|
||||
|
||||
loadImage (instance, src, type) {
|
||||
let imagethrowaway = document.createElement("img");
|
||||
imagethrowaway.src = src;
|
||||
imagethrowaway.onload = _ => {
|
||||
let arects = BDFDB.DOMUtils.getRects(document.querySelector(BDFDB.dotCN.appmount));
|
||||
let resizeY = (arects.height/imagethrowaway.naturalHeight) * 0.65, resizeX = (arects.width/imagethrowaway.naturalWidth) * 0.8;
|
||||
let resize = resizeX < resizeY ? resizeX : resizeY;
|
||||
let newHeight = imagethrowaway.naturalHeight * resize;
|
||||
let newWidth = imagethrowaway.naturalWidth * resize;
|
||||
instance[type + "Ref"] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.LazyImage, {
|
||||
className: BDFDB.disCN[`_imagegallery${type}`],
|
||||
src: src,
|
||||
height: imagethrowaway.naturalHeight,
|
||||
width: imagethrowaway.naturalWidth,
|
||||
maxHeight: newHeight,
|
||||
maxWidth: newWidth,
|
||||
onClick: _ => {this.switchImages(instance, type);}
|
||||
});
|
||||
getSrcOfImage (img) {
|
||||
if (!img) return null;
|
||||
return (typeof img == "string" ? img : (img.src || (img.querySelector("canvas") ? img.querySelector("canvas").src : ""))).split("?width=")[0];
|
||||
}
|
||||
|
||||
loadImage (instance, src, type) {
|
||||
let imagethrowaway = document.createElement("img");
|
||||
imagethrowaway.src = src;
|
||||
imagethrowaway.onload = _ => {
|
||||
let arects = BDFDB.DOMUtils.getRects(document.querySelector(BDFDB.dotCN.appmount));
|
||||
let resizeY = (arects.height/imagethrowaway.naturalHeight) * 0.65, resizeX = (arects.width/imagethrowaway.naturalWidth) * 0.8;
|
||||
let resize = resizeX < resizeY ? resizeX : resizeY;
|
||||
let newHeight = imagethrowaway.naturalHeight * resize;
|
||||
let newWidth = imagethrowaway.naturalWidth * resize;
|
||||
instance[type + "Ref"] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.LazyImage, {
|
||||
className: BDFDB.disCN[`_imagegallery${type}`],
|
||||
src: src,
|
||||
height: imagethrowaway.naturalHeight,
|
||||
width: imagethrowaway.naturalWidth,
|
||||
maxHeight: newHeight,
|
||||
maxWidth: newWidth,
|
||||
onClick: _ => {this.switchImages(instance, type);}
|
||||
});
|
||||
BDFDB.ReactUtils.forceUpdate(instance);
|
||||
};
|
||||
}
|
||||
|
||||
switchImages (instance, type) {
|
||||
let imageRef = instance[type + "Ref"];
|
||||
if (!imageRef) return;
|
||||
delete instance.previousRef;
|
||||
delete instance.nextRef;
|
||||
instance.props.original = imageRef.props.src;
|
||||
instance.props.placeholder = imageRef.props.src;
|
||||
instance.props.src = imageRef.props.src;
|
||||
instance.props.height = imageRef.props.height;
|
||||
instance.props.width = imageRef.props.width;
|
||||
BDFDB.ReactUtils.forceUpdate(instance);
|
||||
};
|
||||
}
|
||||
|
||||
cleanUpListeners () {
|
||||
document.removeEventListener("keydown", document.keydownImageGalleryListener);
|
||||
document.removeEventListener("keyup", document.keyupImageGalleryListener);
|
||||
delete document.keydownImageGalleryListener;
|
||||
delete document.keyupImageGalleryListener;
|
||||
}
|
||||
}
|
||||
|
||||
switchImages (instance, type) {
|
||||
let imageRef = instance[type + "Ref"];
|
||||
if (!imageRef) return;
|
||||
delete instance.previousRef;
|
||||
delete instance.nextRef;
|
||||
instance.props.original = imageRef.props.src;
|
||||
instance.props.placeholder = imageRef.props.src;
|
||||
instance.props.src = imageRef.props.src;
|
||||
instance.props.height = imageRef.props.height;
|
||||
instance.props.width = imageRef.props.width;
|
||||
BDFDB.ReactUtils.forceUpdate(instance);
|
||||
}
|
||||
|
||||
cleanUpListeners () {
|
||||
document.removeEventListener("keydown", document.keydownImageGalleryListener);
|
||||
document.removeEventListener("keyup", document.keyupImageGalleryListener);
|
||||
delete document.keydownImageGalleryListener;
|
||||
delete document.keyupImageGalleryListener;
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,428 +1,407 @@
|
|||
//META{"name":"MessageUtilities","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/MessageUtilities","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/MessageUtilities/MessageUtilities.plugin.js"}*//
|
||||
|
||||
class MessageUtilities {
|
||||
getName () {return "MessageUtilities";}
|
||||
var MessageUtilities = (_ => {
|
||||
var firedEvents = [];
|
||||
var clickMap = ["CLICK", "DBLCLICK"];
|
||||
|
||||
return class MessageUtilities {
|
||||
getName () {return "MessageUtilities";}
|
||||
|
||||
getVersion () {return "1.6.7";}
|
||||
getVersion () {return "1.6.8";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Offers a number of useful message options. Remap the keybindings in the settings.";}
|
||||
getDescription () {return "Offers a number of useful message options. Remap the keybindings in the settings.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"added":[["Quote Message", "Now supports Discords new native Quote Feature"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MessageContextMenu: ["componentDidMount","componentDidUpdate"]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.bindings = {};
|
||||
|
||||
this.firedEvents = [];
|
||||
|
||||
this.clickMap = ["CLICK", "DBLCLICK"];
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
"addHints": {value:true, description:"Add keycombo hints to contextmenus:"},
|
||||
"clearOnEscape": {value:true, description:"Clear chat input when Escape is pressed:"}
|
||||
},
|
||||
toasts: {},
|
||||
bindings: {
|
||||
"Edit_Message": {name:"Edit Message", func:this.doEdit, value:{click:1, keycombo:[]} },
|
||||
"Delete_Message": {name:"Delete Message", func:this.doDelete, value:{click:0, keycombo:[46]} },
|
||||
"Pin/Unpin_Message": {name:"Pin/Unpin Message", func:this.doPinUnPin, value:{click:0, keycombo:[17]} },
|
||||
"React_to_Message": {name:"React to Message", func:this.doOpenReact, value:{click:0, keycombo:[17,83]} },
|
||||
"Copy_Raw": {name:"Copy raw Message", func:this.doCopyRaw, value:{click:0, keycombo:[17,68]} },
|
||||
"Copy_Link": {name:"Copy Message Link", func:this.doCopyLink, value:{click:0, keycombo:[17,81]} },
|
||||
"Quote_Message": {name:"Quote Message", func:this.doQuote, value:{click:0, keycombo:[17,87]} },
|
||||
"__Note_Message": {name:"Note Message (Pesonal Pins)", func:this.doNote, value:{click:0, keycombo:[16]}, plugin:"PersonalPins"},
|
||||
"__Translate_Message": {name:"Translate Message (Google Translate Option)", func:this.doTranslate, value:{click:0, keycombo:[20]}, plugin:"GoogleTranslateOption"},
|
||||
"__Reveal_Spoilers": {name:"Reveal All Spoilers (RevealAllSpoilersOption)", func:this.doReveal, value:{click:0, keycombo:[17,74]}, plugin:"RevealAllSpoilersOption"}
|
||||
}
|
||||
};
|
||||
for (let type in this.defaults.bindings) {
|
||||
let nativeaction = type.indexOf("__") != 0;
|
||||
this.defaults.settings[type] = {value:nativeaction};
|
||||
if (nativeaction) this.defaults.toasts[type] = {value:type != "Edit_Message" && type != "React_to_Message" && type != "Quote_Message"};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MessageContextMenu: ["componentDidMount","componentDidUpdate"]
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let bindings = BDFDB.DataUtils.get(this, "bindings");
|
||||
let toasts = BDFDB.DataUtils.get(this, "toasts");
|
||||
let settingspanel, settingsitems = [];
|
||||
|
||||
for (let key in settings) if (this.defaults.settings[key].description) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
for (let action in bindings) if (!this.defaults.bindings[action].plugin || BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings[action].plugin)) {
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
||||
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
|
||||
label: this.defaults.bindings[action].name
|
||||
}),
|
||||
toasts[action] != undefined ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
type: "Switch",
|
||||
mini: true,
|
||||
plugin: this,
|
||||
keys: ["toasts", action],
|
||||
grow: 0,
|
||||
label: "Toast:",
|
||||
value: toasts[action]
|
||||
}) : null
|
||||
].filter(n => n)
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
initConstructor () {
|
||||
this.defaults = {
|
||||
settings: {
|
||||
"addHints": {value:true, description:"Add keycombo hints to contextmenus:"},
|
||||
"clearOnEscape": {value:true, description:"Clear chat input when Escape is pressed:"}
|
||||
},
|
||||
toasts: {},
|
||||
bindings: {
|
||||
"Edit_Message": {name:"Edit Message", func:this.doEdit, value:{click:1, keycombo:[]} },
|
||||
"Delete_Message": {name:"Delete Message", func:this.doDelete, value:{click:0, keycombo:[46]} },
|
||||
"Pin/Unpin_Message": {name:"Pin/Unpin Message", func:this.doPinUnPin, value:{click:0, keycombo:[17]} },
|
||||
"React_to_Message": {name:"React to Message", func:this.doOpenReact, value:{click:0, keycombo:[17,83]} },
|
||||
"Copy_Raw": {name:"Copy raw Message", func:this.doCopyRaw, value:{click:0, keycombo:[17,68]} },
|
||||
"Copy_Link": {name:"Copy Message Link", func:this.doCopyLink, value:{click:0, keycombo:[17,81]} },
|
||||
"Quote_Message": {name:"Quote Message", func:this.doQuote, value:{click:0, keycombo:[17,87]} },
|
||||
"__Note_Message": {name:"Note Message", func:this.doNote, value:{click:0, keycombo:[16]}, plugin:"PersonalPins"},
|
||||
"__Translate_Message": {name:"Translate Message", func:this.doTranslate, value:{click:0, keycombo:[20]}, plugin:"GoogleTranslateOption"},
|
||||
"__Reveal_Spoilers": {name:"Reveal All Spoilers", func:this.doReveal, value:{click:0, keycombo:[17,74]}, plugin:"RevealAllSpoilersOption"}
|
||||
}
|
||||
};
|
||||
for (let type in this.defaults.bindings) {
|
||||
let nativeaction = type.indexOf("__") != 0;
|
||||
this.defaults.settings[type] = {value:nativeaction};
|
||||
if (nativeaction) this.defaults.toasts[type] = {value:type != "Edit_Message" && type != "React_to_Message" && type != "Quote_Message"};
|
||||
}
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let bindings = BDFDB.DataUtils.get(this, "bindings");
|
||||
let toasts = BDFDB.DataUtils.get(this, "toasts");
|
||||
let settingspanel, settingsitems = [];
|
||||
|
||||
for (let key in settings) if (this.defaults.settings[key].description) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
dividerbottom: true,
|
||||
mini: true,
|
||||
plugin: this,
|
||||
keys: ["settings", action],
|
||||
value: settings[action],
|
||||
labelchildren: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
for (let action in bindings) if (!this.defaults.bindings[action].plugin || BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings[action].plugin)) {
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
||||
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Select, {
|
||||
value: bindings[action].click,
|
||||
options: this.clickMap.map((label, i) => {return {value:i, label:label}}),
|
||||
onChange: choice => {
|
||||
bindings[action].click = choice.value;
|
||||
BDFDB.DataUtils.save(bindings, this, "bindings");
|
||||
}
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
|
||||
label: this.defaults.bindings[action].name + (this.defaults.bindings[action].plugin ? ` (${this.defaults.bindings[action].plugin})` : "")
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.KeybindRecorder, {
|
||||
defaultValue: bindings[action].keycombo.filter(n => n),
|
||||
reset: true,
|
||||
onChange: keycombo => {
|
||||
bindings[action].keycombo = keycombo;
|
||||
BDFDB.DataUtils.save(bindings, this, "bindings");
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
}));
|
||||
}
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
||||
type: "Button",
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
color: BDFDB.LibraryComponents.Button.Colors.RED,
|
||||
label: "Reset all Key Bindings",
|
||||
onClick: (e, instance) => {
|
||||
BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all Key Bindings?", _ => {
|
||||
BDFDB.DataUtils.remove(this, "bindings");
|
||||
settingspanel.parentElement.appendChild(this.getSettingsPanel());
|
||||
settingspanel.remove();
|
||||
});
|
||||
},
|
||||
children: BDFDB.LanguageUtils.LanguageStrings.RESET
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
// REMOVE 15.11.2019
|
||||
let bindings = BDFDB.DataUtils.load(this, "bindings");
|
||||
if (bindings[Object.keys(bindings)[0]].keycombo == undefined) {
|
||||
for (let key in bindings) bindings[key] = {click: bindings[key].click, keycombo: [bindings[key].key1, bindings[key].key2].filter(n => n)};
|
||||
BDFDB.DataUtils.save(bindings, this, "bindings");
|
||||
toasts[action] != undefined ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
type: "Switch",
|
||||
mini: true,
|
||||
plugin: this,
|
||||
keys: ["toasts", action],
|
||||
grow: 0,
|
||||
label: "Toast:",
|
||||
value: toasts[action]
|
||||
}) : null
|
||||
].filter(n => n)
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
dividerbottom: true,
|
||||
mini: true,
|
||||
plugin: this,
|
||||
keys: ["settings", action],
|
||||
value: settings[action],
|
||||
labelchildren: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.KeybindRecorder, {
|
||||
defaultValue: bindings[action].keycombo.filter(n => n),
|
||||
reset: true,
|
||||
onChange: keycombo => {
|
||||
bindings[action].keycombo = keycombo;
|
||||
BDFDB.DataUtils.save(bindings, this, "bindings");
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Select, {
|
||||
value: bindings[action].click,
|
||||
options: clickMap.map((label, i) => {return {value:i, label:label}}),
|
||||
onChange: choice => {
|
||||
bindings[action].click = choice.value;
|
||||
BDFDB.DataUtils.save(bindings, this, "bindings");
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
BDFDB.ListenerUtils.add(this, document, "click", BDFDB.dotCN.messagegroup + "> [aria-disabled]," + BDFDB.dotCN.messagegroup + "> * > [aria-disabled]," + BDFDB.dotCN.messagesystem, e => {
|
||||
this.onClick(e, 0, "onSglClick");
|
||||
})
|
||||
BDFDB.ListenerUtils.add(this, document, "dblclick", BDFDB.dotCN.messagegroup + "> [aria-disabled]," + BDFDB.dotCN.messagegroup + "> * > [aria-disabled]," + BDFDB.dotCN.messagesystem, e => {
|
||||
this.onClick(e, 1, "onDblClick");
|
||||
});
|
||||
BDFDB.ListenerUtils.add(this, document, "keydown", e => {
|
||||
if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.textareawrapchat, document.activeElement)) this.onKeyDown(document.activeElement, e.which, "onKeyDown");
|
||||
});
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
||||
type: "Button",
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
color: BDFDB.LibraryComponents.Button.Colors.RED,
|
||||
label: "Reset all Key Bindings",
|
||||
onClick: (e, instance) => {
|
||||
BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all Key Bindings?", _ => {
|
||||
BDFDB.DataUtils.remove(this, "bindings");
|
||||
settingspanel.parentElement.appendChild(this.getSettingsPanel());
|
||||
settingspanel.remove();
|
||||
});
|
||||
},
|
||||
children: BDFDB.LanguageUtils.LanguageStrings.RESET
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ListenerUtils.add(this, document, "click", BDFDB.dotCN.message, e => {
|
||||
this.onClick(e, 0, "onSglClick");
|
||||
});
|
||||
BDFDB.ListenerUtils.add(this, document, "dblclick", BDFDB.dotCN.message, e => {
|
||||
this.onClick(e, 1, "onDblClick");
|
||||
});
|
||||
BDFDB.ListenerUtils.add(this, document, "keydown", e => {
|
||||
if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.textareawrapchat, document.activeElement)) this.onKeyDown(document.activeElement, e.which, "onKeyDown");
|
||||
});
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//begin of own functions
|
||||
|
||||
processMessageContextMenu (e) {
|
||||
if (e.instance.props.message && e.instance.props.channel && e.instance.props.target) {
|
||||
for (let itemlabel of e.node.querySelectorAll(BDFDB.dotCN.contextmenulabel)) {
|
||||
let hint = itemlabel.parentElement.querySelector(BDFDB.dotCN.contextmenuhint);
|
||||
if (hint) {
|
||||
let hintlabel;
|
||||
if (itemlabel.innerText == BDFDB.LanguageUtils.LanguageStrings.MARK_UNREAD) {
|
||||
if (BDFDB.DataUtils.get(this, "settings", "addHints")) hintlabel = `${this.clickMap[0]}+${BDFDB.LibraryModules.KeyCodeUtils.getString(18)}`;
|
||||
//begin of own functions
|
||||
|
||||
processMessageContextMenu (e) {
|
||||
if (e.instance.props.message && e.instance.props.channel) {
|
||||
for (let itemlabel of e.node.querySelectorAll(BDFDB.dotCN.contextmenulabel)) {
|
||||
let hint = itemlabel.parentElement.querySelector(BDFDB.dotCN.contextmenuhint);
|
||||
if (hint) {
|
||||
let hintlabel;
|
||||
if (itemlabel.innerText == BDFDB.LanguageUtils.LanguageStrings.MARK_UNREAD) {
|
||||
if (BDFDB.DataUtils.get(this, "settings", "addHints")) hintlabel = `${clickMap[0]}+${BDFDB.LibraryModules.KeyCodeUtils.getString(18)}`;
|
||||
}
|
||||
else {
|
||||
let action = null;
|
||||
switch (itemlabel.innerText) {
|
||||
case BDFDB.LanguageUtils.LanguageStrings.COPY_MESSAGE_LINK:
|
||||
action = "Copy_Link";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.EDIT_MESSAGE:
|
||||
action = "Edit_Message";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.PIN_MESSAGE:
|
||||
case BDFDB.LanguageUtils.LanguageStrings.UNPIN_MESSAGE:
|
||||
action = "Pin/Unpin_Message";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.DELETE_MESSAGE:
|
||||
action = "Delete_Message";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.QUOTE:
|
||||
action = "Quote_Message";
|
||||
break;
|
||||
}
|
||||
if (action) hintlabel = this.getActiveShortcutString(action);
|
||||
}
|
||||
if (hintlabel) {
|
||||
hint.style.setProperty("width", "42px");
|
||||
hint.style.setProperty("max-width", "42px");
|
||||
hint.style.setProperty("margin-left", "8px");
|
||||
BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, {speed: 2, children: hintlabel}), hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClick (e, click, name) {
|
||||
if (!firedEvents.includes(name)) {
|
||||
firedEvents.push(name);
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let bindings = BDFDB.ObjectUtils.filter(BDFDB.DataUtils.get(this, "bindings"), action => {return settings[action]}, true);
|
||||
let priorityaction = null;
|
||||
for (let action in bindings) {
|
||||
let binding = bindings[action];
|
||||
let prioritybinding = bindings[priorityaction];
|
||||
if (this.checkIfBindingIsValid(binding, click) && (!bindings[priorityaction] || binding.click > prioritybinding.click || binding.keycombo.length > prioritybinding.keycombo.length)) priorityaction = action;
|
||||
}
|
||||
if (priorityaction) {
|
||||
let {messagediv, message} = this.getMessageData(e.currentTarget);
|
||||
if (messagediv && message) {
|
||||
BDFDB.ListenerUtils.stopEvent(e);
|
||||
BDFDB.TimeUtils.clear(this.clickTimeout);
|
||||
if (!this.hasDoubleClickOverwrite(bindings, bindings[priorityaction])) {
|
||||
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, message}, priorityaction]);
|
||||
}
|
||||
else this.clickTimeout = BDFDB.TimeUtils.timeout(_ => {
|
||||
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, message}, priorityaction]);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
BDFDB.TimeUtils.timeout(_ => {BDFDB.ArrayUtils.remove(firedEvents, name, true)});
|
||||
}
|
||||
}
|
||||
|
||||
checkIfBindingIsValid (binding, doneclick) {
|
||||
let valid = true;
|
||||
if (binding.click != doneclick) valid = false;
|
||||
for (let key of binding.keycombo) if (!BDFDB.InternalData.pressedKeys.includes(key)) valid = false;
|
||||
return valid;
|
||||
}
|
||||
|
||||
hasDoubleClickOverwrite (bindings, binding) {
|
||||
if (binding.click == 1) return false;
|
||||
let dblbindings = BDFDB.ObjectUtils.filter(bindings, bndg => {return bndg.click == 1});
|
||||
for (let dblaction in dblbindings) {
|
||||
let dblbndg = dblbindings[dblaction];
|
||||
let overwrite = true;
|
||||
if (BDFDB.equals(binding.keycombo, dblbndg.keycombo)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
doDelete ({messagediv, message}, action) {
|
||||
let deletelink = messagediv.parentElement.querySelector(BDFDB.dotCNS.messagelocalbotmessage + BDFDB.dotCN.anchor);
|
||||
if (deletelink) deletelink.click();
|
||||
else {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if ((channel && BDFDB.UserUtils.can("MANAGE_MESSAGES")) || message.author.id == BDFDB.UserUtils.me.id && message.type != 1 && message.type != 2 && message.type != 3) {
|
||||
BDFDB.LibraryModules.MessageUtils.deleteMessage(message.channel_id, message.id, message.state != "SENT");
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Message has been deleted.", {type:"success"});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doEdit ({messagediv, message}, action) {
|
||||
if (message.author.id == BDFDB.UserUtils.me.id && !messagediv.querySelector("textarea")) {
|
||||
BDFDB.LibraryModules.MessageUtils.startEditMessage(message.channel_id, message.id, message.content);
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Started editing.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doOpenReact ({messagediv, message}, action) {
|
||||
let reactButton = messagediv.querySelector(BDFDB.dotCN.emojipickerbutton);
|
||||
if (reactButton) {
|
||||
reactButton.click();
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Reaction popout has been opened.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doPinUnPin ({messagediv, message}, action) {
|
||||
if (message.state == "SENT") {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel && (channel.type == 1 || channel.type == 3 || BDFDB.UserUtils.can("MANAGE_MESSAGES")) && message.type == 0) {
|
||||
if (message.pinned) {
|
||||
BDFDB.LibraryModules.MessagePinUtils.unpinMessage(channel, message.id);
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Message has been unpinned.", {type:"error"});
|
||||
}
|
||||
else {
|
||||
let action = null;
|
||||
switch (itemlabel.innerText) {
|
||||
case BDFDB.LanguageUtils.LanguageStrings.COPY_MESSAGE_LINK:
|
||||
action = "Copy_Link";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.EDIT_MESSAGE:
|
||||
action = "Edit_Message";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.PIN_MESSAGE:
|
||||
case BDFDB.LanguageUtils.LanguageStrings.UNPIN_MESSAGE:
|
||||
action = "Pin/Unpin_Message";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.DELETE_MESSAGE:
|
||||
action = "Delete_Message";
|
||||
break;
|
||||
case BDFDB.LanguageUtils.LanguageStrings.QUOTE:
|
||||
action = "Quote_Message";
|
||||
break;
|
||||
}
|
||||
if (action) hintlabel = this.getActiveShortcutString(action);
|
||||
}
|
||||
if (hintlabel) {
|
||||
hint.style.setProperty("width", "42px");
|
||||
hint.style.setProperty("max-width", "42px");
|
||||
hint.style.setProperty("margin-left", "8px");
|
||||
BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, {speed: 2, children: hintlabel}), hint);
|
||||
BDFDB.LibraryModules.MessagePinUtils.pinMessage(channel, message.id);
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Message has been pinned.", {type:"success"});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClick (e, click, name) {
|
||||
if (!this.isEventFired(name)) {
|
||||
this.fireEvent(name);
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let bindings = BDFDB.ObjectUtils.filter(BDFDB.DataUtils.get(this, "bindings"), action => {return settings[action]}, true);
|
||||
let priorityaction = null;
|
||||
for (let action in bindings) {
|
||||
let binding = bindings[action];
|
||||
let prioritybinding = bindings[priorityaction];
|
||||
if (this.checkIfBindingIsValid(binding, click) && (!bindings[priorityaction] || binding.click > prioritybinding.click || binding.keycombo.length > prioritybinding.keycombo.length)) priorityaction = action;
|
||||
doCopyRaw ({messagediv, message}, action) {
|
||||
if (message.content) {
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:message.content});
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Raw message content has been copied.", {type:"success"});
|
||||
}
|
||||
if (priorityaction) {
|
||||
let {messagediv, pos, message} = this.getMessageData(e.currentTarget);
|
||||
if (messagediv && pos > -1 && message) {
|
||||
BDFDB.ListenerUtils.stopEvent(e);
|
||||
BDFDB.TimeUtils.clear(this.clickTimeout);
|
||||
if (!this.hasDoubleClickOverwrite(bindings, bindings[priorityaction])) {
|
||||
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, pos, message}, priorityaction]);
|
||||
}
|
||||
|
||||
doCopyLink ({messagediv, message}, action) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel) {
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:`https://discordapp.com/channels/${channel.guild_id || "@me"}/${channel.id}/${message.id}`});
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Messagelink has been copied.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doQuote ({messagediv, message}, action) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel && BDFDB.LibraryModules.QuoteUtils.canQuote(message, channel)) {
|
||||
BDFDB.LibraryModules.DispatchUtils.ComponentDispatch.dispatch(BDFDB.DiscordConstants.ComponentActions.INSERT_QUOTE_TEXT, {
|
||||
text: BDFDB.LibraryModules.QuoteUtils.createQuotedText(message, channel)
|
||||
});
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Quote has been created.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doNote ({messagediv, message}, action) {
|
||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Note_Message.plugin)) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Note_Message.plugin).addMessageToNotes(message, channel);
|
||||
}
|
||||
}
|
||||
|
||||
doTranslate ({messagediv, message}, action) {
|
||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Translate_Message.plugin)) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Translate_Message.plugin).translateMessage(message, channel);
|
||||
}
|
||||
}
|
||||
|
||||
doReveal ({messagediv, message}, action) {
|
||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Reveal_Spoilers.plugin)) {
|
||||
BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Reveal_Spoilers.plugin).revealAllSpoilers(messagediv);
|
||||
}
|
||||
}
|
||||
|
||||
onKeyDown (target, key, name) {
|
||||
if (!firedEvents.includes(name)) {
|
||||
firedEvents.push(name);
|
||||
if (key == 27 && BDFDB.DataUtils.get(this, "settings", "clearOnEscape")) {
|
||||
let chatform = BDFDB.DOMUtils.getParent(BDFDB.dotCN.chatform, target);
|
||||
if (chatform) {
|
||||
let instance = BDFDB.ReactUtils.findOwner(chatform, {name:"ChannelTextAreaForm"}) || BDFDB.ReactUtils.findOwner(chatform, {name:"ChannelTextAreaForm", up:true});
|
||||
if (instance) instance.setState({textValue:"", richValue:BDFDB.LibraryModules.SlateUtils.deserialize("")});
|
||||
}
|
||||
else this.clickTimeout = BDFDB.TimeUtils.timeout(_ => {
|
||||
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, pos, message}, priorityaction]);
|
||||
}, 500);
|
||||
}
|
||||
BDFDB.TimeUtils.timeout(_ => {BDFDB.ArrayUtils.remove(firedEvents, name, true)});
|
||||
}
|
||||
}
|
||||
|
||||
getActiveShortcutString (action) {
|
||||
if (!action) return null;
|
||||
let str = "", settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (settings.addHints && settings[action]) {
|
||||
let binding = BDFDB.DataUtils.get(this, "bindings", action);
|
||||
if (binding) {
|
||||
str += clickMap[binding.click];
|
||||
if (binding.keycombo.length) str += " + " + BDFDB.LibraryModules.KeyCodeUtils.getString(binding.keycombo);
|
||||
}
|
||||
}
|
||||
this.cancelEvent(name);
|
||||
return str.replace(/ /g, "");
|
||||
}
|
||||
|
||||
getMessageData (target) {
|
||||
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.message, target);
|
||||
if (messagediv && messagediv.querySelector(BDFDB.dotCN.textarea)) return {messagediv: null, message: null};
|
||||
let instance = BDFDB.ReactUtils.getInstance(messagediv);
|
||||
let message = instance && BDFDB.ReactUtils.findValue(instance, "message");
|
||||
return {messagediv, message};
|
||||
}
|
||||
}
|
||||
|
||||
checkIfBindingIsValid (binding, doneclick) {
|
||||
let valid = true;
|
||||
if (binding.click != doneclick) valid = false;
|
||||
for (let key of binding.keycombo) if (!BDFDB.InternalData.pressedKeys.includes(key)) valid = false;
|
||||
return valid;
|
||||
}
|
||||
|
||||
hasDoubleClickOverwrite (bindings, binding) {
|
||||
if (binding.click == 1) return false;
|
||||
let dblbindings = BDFDB.ObjectUtils.filter(bindings, bndg => {return bndg.click == 1});
|
||||
for (let dblaction in dblbindings) {
|
||||
let dblbndg = dblbindings[dblaction];
|
||||
let overwrite = true;
|
||||
if (BDFDB.equals(binding.keycombo, dblbndg.keycombo)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
doDelete ({messagediv, pos, message}, action) {
|
||||
let deletelink = messagediv.parentElement.querySelector(BDFDB.dotCNS.messagelocalbotmessage + BDFDB.dotCN.anchor);
|
||||
if (deletelink) deletelink.click();
|
||||
else {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if ((channel && BDFDB.UserUtils.can("MANAGE_MESSAGES")) || message.author.id == BDFDB.UserUtils.me.id && message.type != 1 && message.type != 2 && message.type != 3) {
|
||||
BDFDB.LibraryModules.MessageUtils.deleteMessage(message.channel_id, message.id, message.state != "SENT");
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Message has been deleted.", {type:"success"});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doEdit ({messagediv, pos, message}, action) {
|
||||
if (message.author.id == BDFDB.UserUtils.me.id && !messagediv.querySelector("textarea")) {
|
||||
BDFDB.LibraryModules.MessageUtils.startEditMessage(message.channel_id, message.id, message.content);
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Started editing.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doOpenReact ({messagediv, pos, message}, action) {
|
||||
let reactButton = messagediv.querySelector(BDFDB.dotCN.emojipickerbutton);
|
||||
if (reactButton) {
|
||||
reactButton.click();
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Reaction popout has been opened.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doPinUnPin ({messagediv, pos, message}, action) {
|
||||
if (message.state == "SENT") {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel && (channel.type == 1 || channel.type == 3 || BDFDB.UserUtils.can("MANAGE_MESSAGES")) && message.type == 0) {
|
||||
if (message.pinned) {
|
||||
BDFDB.LibraryModules.MessagePinUtils.unpinMessage(channel, message.id);
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Message has been unpinned.", {type:"error"});
|
||||
}
|
||||
else {
|
||||
BDFDB.LibraryModules.MessagePinUtils.pinMessage(channel, message.id);
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Message has been pinned.", {type:"success"});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doCopyRaw ({messagediv, pos, message}, action) {
|
||||
if (message.content) {
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:message.content});
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Raw message content has been copied.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doCopyLink ({messagediv, pos, message}, action) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel) {
|
||||
BDFDB.LibraryRequires.electron.clipboard.write({text:`https://discordapp.com/channels/${channel.guild_id || "@me"}/${channel.id}/${message.id}`});
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Messagelink has been copied.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doQuote ({messagediv, pos, message}, action) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel && BDFDB.LibraryModules.QuoteUtils.canQuote(message, channel)) {
|
||||
BDFDB.LibraryModules.DispatchUtils.ComponentDispatch.dispatch(BDFDB.DiscordConstants.ComponentActions.INSERT_QUOTE_TEXT, {
|
||||
text: BDFDB.LibraryModules.QuoteUtils.createQuotedText(message, channel)
|
||||
});
|
||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Quote has been created.", {type:"success"});
|
||||
}
|
||||
}
|
||||
|
||||
doNote ({messagediv, pos, message}, action) {
|
||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Note_Message.plugin)) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Note_Message.plugin).addMessageToNotes(message, messagediv, channel);
|
||||
}
|
||||
}
|
||||
|
||||
doTranslate ({messagediv, pos, message}, action) {
|
||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Translate_Message.plugin)) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Translate_Message.plugin).translateMessage(message, messagediv, channel);
|
||||
}
|
||||
}
|
||||
|
||||
doReveal ({messagediv, pos, message}, action) {
|
||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Reveal_Spoilers.plugin)) {
|
||||
BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Reveal_Spoilers.plugin).revealAllSpoilers(messagediv);
|
||||
}
|
||||
}
|
||||
|
||||
onKeyDown (target, key, name) {
|
||||
if (!this.isEventFired(name)) {
|
||||
this.fireEvent(name);
|
||||
if (key == 27 && BDFDB.DataUtils.get(this, "settings", "clearOnEscape")) {
|
||||
let chatform = BDFDB.DOMUtils.getParent(BDFDB.dotCN.chatform, target);
|
||||
if (chatform) {
|
||||
let instance = BDFDB.ReactUtils.findOwner(chatform, {name:"ChannelTextAreaForm"}) || BDFDB.ReactUtils.findOwner(chatform, {name:"ChannelTextAreaForm", up:true});
|
||||
if (instance) instance.setState({textValue:"", richValue:BDFDB.LibraryModules.SlateUtils.deserialize("")});
|
||||
}
|
||||
}
|
||||
this.cancelEvent(name);
|
||||
}
|
||||
}
|
||||
|
||||
getActiveShortcutString (action) {
|
||||
if (!action) return null;
|
||||
let str = "", settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (settings.addHints && settings[action]) {
|
||||
let binding = BDFDB.DataUtils.get(this, "bindings", action);
|
||||
if (binding) {
|
||||
str += this.clickMap[binding.click];
|
||||
if (binding.keycombo.length) str += " + " + BDFDB.LibraryModules.KeyCodeUtils.getString(binding.keycombo);
|
||||
}
|
||||
}
|
||||
return str.replace(/ /g, "");
|
||||
}
|
||||
|
||||
getMessageData (target) {
|
||||
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> [aria-disabled]", target) || BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> * > [aria-disabled]", target) || BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagesystem, target);
|
||||
if (messagediv && messagediv.querySelector(BDFDB.dotCN.textarea)) return {messagediv: null, pos: -1, message: null};
|
||||
let pos = messagediv ? Array.from(messagediv.parentElement.childNodes).filter(n => n.nodeType != Node.TEXT_NODE).indexOf(messagediv) : -1;
|
||||
let instance = BDFDB.ReactUtils.getInstance(messagediv);
|
||||
let message = instance ? BDFDB.ReactUtils.findValue(instance, "message", {up:true}) : null;
|
||||
return {messagediv, pos, message};
|
||||
}
|
||||
|
||||
fireEvent (name) {
|
||||
this.firedEvents.push(name);
|
||||
}
|
||||
|
||||
isEventFired (name) {
|
||||
return this.firedEvents.includes(name);
|
||||
}
|
||||
|
||||
cancelEvent (name) {
|
||||
BDFDB.TimeUtils.timeout(_ => {BDFDB.ArrayUtils.remove(this.firedEvents, name, true)});
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -1,239 +1,252 @@
|
|||
//META{"name":"OwnerTag","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/OwnerTag","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/OwnerTag/OwnerTag.plugin.js"}*//
|
||||
|
||||
class OwnerTag {
|
||||
getName () {return "OwnerTag";}
|
||||
var OwnerTag = (_ => {
|
||||
return class OwnerTag {
|
||||
getName () {return "OwnerTag";}
|
||||
|
||||
getVersion () {return "1.2.4";}
|
||||
getVersion () {return "1.2.5";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds a Tag like Bottags to the Serverowner.";}
|
||||
getDescription () {return "Adds a Tag like Bottags to the Serverowner.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["User Profile","Switching users in the user profile modal via mutual friends now properly removes the owner tag"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MemberListItem: "render",
|
||||
MessageUsername: "render",
|
||||
UserPopout: ["componentDidMount", "componentDidUpdate"],
|
||||
UserProfile: ["componentDidMount", "componentDidUpdate"]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCN.memberownericon}.admin-crown {
|
||||
color: #b3b3b3;
|
||||
}
|
||||
`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
addInChatWindow: {value:true, inner:true, description:"Messages"},
|
||||
addInMemberList: {value:true, inner:true, description:"Member List"},
|
||||
addInUserPopout: {value:true, inner:true, description:"User Popouts"},
|
||||
addInUserProfil: {value:true, inner:true, description:"User Profile Modal"},
|
||||
useRoleColor: {value:true, inner:false, description:"Use the Rolecolor instead of the default blue."},
|
||||
useBlackFont: {value:false, inner:false, description:"Instead of darkening the Rolecolor on bright colors use black font."},
|
||||
useCrown: {value:false, inner:false, description:"Use the Crown Icon instead of the OwnerTag."},
|
||||
hideNativeCrown: {value:true, inner:false, description:"Hide the native Crown Icon (not the Plugin one)."},
|
||||
addForAdmins: {value:false, inner:false, description:"Also add the Tag for any user with Admin rights."}
|
||||
},
|
||||
inputs: {
|
||||
ownTagName: {value:"Owner", description:"Owner Tag Text for Owners"},
|
||||
ownAdminTagName: {value:"Admin", description:"Owner Tag Text for Admins"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let inputs = BDFDB.DataUtils.get(this, "inputs");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in inputs) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "TextInput",
|
||||
plugin: this,
|
||||
keys: ["inputs", key],
|
||||
label: this.defaults.inputs[key].description,
|
||||
basis: "50%",
|
||||
value: inputs[key]
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "Add Owner Tag in:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
}
|
||||
|
||||
processMemberListItem (e) {
|
||||
let usertype = this.getUserType(e.instance.props.user);
|
||||
if (usertype && BDFDB.DataUtils.get(this, "settings", "addInMemberList")) {
|
||||
this.injectOwnerTag(BDFDB.ReactUtils.getValue(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, usertype, 1, BDFDB.disCN.bottagmember);
|
||||
}
|
||||
}
|
||||
|
||||
processMessageUsername (e) {
|
||||
let user = BDFDB.ReactUtils.getValue(e.instance, "props.message.author");
|
||||
let usertype = this.getUserType(user);
|
||||
if (usertype && user && typeof e.returnvalue.props.children == "function" && BDFDB.DataUtils.get(this, "settings", "addInChatWindow")) {
|
||||
let renderChildren = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
this.injectOwnerTag(renderedChildren.props.children, user, usertype, 2, e.instance.props.isCompact ? BDFDB.disCN.bottagmessagecompact : BDFDB.disCN.bottagmessagecozy);
|
||||
return renderedChildren;
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MemberListItem: "render",
|
||||
MessageHeader: "default",
|
||||
NameTag: "default",
|
||||
UserPopout: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
processUserPopout (e) {
|
||||
BDFDB.DOMUtils.remove(e.node.querySelectorAll(".owner-tag"));
|
||||
let usertype = this.getUserType(e.instance.props.user);
|
||||
if (usertype && BDFDB.DataUtils.get(this, "settings", "addInUserPopout")) {
|
||||
let nameTag = e.node.querySelector(BDFDB.dotCN.nametag);
|
||||
let tagProps = BDFDB.ReactUtils.findProps(nameTag, {name:["DiscordTag", "ColoredFluxTag"], up:true});
|
||||
if (nameTag && tagProps) this.appendOwnerTag(nameTag, e.instance.props.user, usertype, ((tagProps.botClass || "") + " " + BDFDB.disCNS.bottagnametag).trim(), tagProps.invertBotTagColor);
|
||||
}
|
||||
}
|
||||
|
||||
processUserProfile (e) {
|
||||
BDFDB.DOMUtils.remove(e.node.querySelectorAll(".owner-tag"));
|
||||
let usertype = this.getUserType(e.instance.props.user);
|
||||
if (usertype && BDFDB.DataUtils.get(this, "settings", "addInUserProfil")) {
|
||||
let nameTag = e.node.querySelector(BDFDB.dotCN.nametag);
|
||||
let tagProps = BDFDB.ReactUtils.findProps(nameTag, {name:["DiscordTag", "ColoredFluxTag"], up:true});
|
||||
if (nameTag && tagProps) this.appendOwnerTag(nameTag, e.instance.props.user, usertype, ((tagProps.botClass || "") + " " + BDFDB.disCNS.bottagnametag).trim(), tagProps.invertBotTagColor);
|
||||
}
|
||||
}
|
||||
|
||||
injectOwnerTag (children, user, usertype, insertindex, tagclass = "", inverted = false) {
|
||||
if (!BDFDB.ArrayUtils.is(children) || !user) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let [_, index] = BDFDB.ReactUtils.findChildren(settings.useCrown || settings.hideNativeCrown ? children : null, {props:[["text",[BDFDB.LanguageUtils.LanguageStrings.GROUP_OWNER, BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER]]]});
|
||||
if (index > -1) children[index] = null;
|
||||
children.splice(insertindex, 0, this.createOwnerTag(user, usertype, tagclass, inverted, settings));
|
||||
}
|
||||
|
||||
appendOwnerTag (parent, user, usertype, tagclass = "", inverted = false) {
|
||||
BDFDB.DOMUtils.remove(parent.querySelectorAll(".owner-tag"));
|
||||
let renderWrapper = BDFDB.DOMUtils.create(`<span class="owner-tag"></span>`);
|
||||
BDFDB.ReactUtils.render(this.createOwnerTag(user, usertype, tagclass, inverted), renderWrapper);
|
||||
parent.appendChild(renderWrapper);
|
||||
}
|
||||
|
||||
createOwnerTag (user, usertype, tagclass, inverted, settings = BDFDB.DataUtils.get(this, "settings")) {
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(BDFDB.LibraryModules.LastChannelStore.getChannelId());
|
||||
let member = settings.useRoleColor ? (BDFDB.LibraryModules.MemberStore.getMember(channel.guild_id, user.id) || {}) : {};
|
||||
let isowner = usertype == 2;
|
||||
if (settings.useCrown) {
|
||||
let label = isowner ? (channel.type == 3 ? BDFDB.LanguageUtils.LanguageStrings.GROUP_OWNER : BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER) : BDFDB.LanguageUtils.LanguageStrings.ADMINISTRATOR;
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: label,
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCNS.memberownericon + (isowner ? "owner-crown" : "admin-crown"),
|
||||
name: BDFDB.LibraryComponents.SvgIcon.Names.CROWN,
|
||||
"aria-label": label
|
||||
})
|
||||
});
|
||||
}
|
||||
else {
|
||||
let tagcolor = BDFDB.ColorUtils.convert(member.colorString, "RGBA");
|
||||
let isbright = BDFDB.ColorUtils.isBright(tagcolor);
|
||||
tagcolor = isbright ? (settings.useBlackFont ? tagcolor : BDFDB.ColorUtils.change(tagcolor, -0.3)) : tagcolor;
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BotTag, {
|
||||
className: tagclass,
|
||||
tag: BDFDB.DataUtils.get(this, "inputs", isowner ? "ownTagName" : "ownAdminTagName"),
|
||||
invertColor: inverted,
|
||||
style: {
|
||||
backgroundColor: inverted ? (isbright && settings.useBlackFont ? "black" : null) : tagcolor,
|
||||
color: !inverted ? (isbright && settings.useBlackFont ? "black" : null) : tagcolor
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCN.memberownericon}.admin-crown {
|
||||
color: #b3b3b3;
|
||||
}
|
||||
});
|
||||
${BDFDB.dotCNS.message + BDFDB.dotCN.memberownericon} {
|
||||
top: 2px;
|
||||
}
|
||||
${BDFDB.dotCNS.userprofile + BDFDB.dotCN.memberownericon} {
|
||||
top: 0px;
|
||||
}
|
||||
${BDFDB.dotCNS.messagecozy + BDFDB.dotCN.messageusername} + ${BDFDB.dotCN.memberownericon} {
|
||||
margin-left: 0;
|
||||
}
|
||||
`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
addInChatWindow: {value:true, inner:true, description:"Messages"},
|
||||
addInMemberList: {value:true, inner:true, description:"Member List"},
|
||||
addInUserPopout: {value:true, inner:true, description:"User Popouts"},
|
||||
addInUserProfile: {value:true, inner:true, description:"User Profile Modal"},
|
||||
useRoleColor: {value:true, inner:false, description:"Use the Rolecolor instead of the default blue."},
|
||||
useBlackFont: {value:false, inner:false, description:"Instead of darkening the Rolecolor on bright colors use black font."},
|
||||
useCrown: {value:false, inner:false, description:"Use the Crown Icon instead of the OwnerTag."},
|
||||
hideNativeCrown: {value:true, inner:false, description:"Hide the native Crown Icon (not the Plugin one)."},
|
||||
addForAdmins: {value:false, inner:false, description:"Also add the Tag for any user with Admin rights."}
|
||||
},
|
||||
inputs: {
|
||||
ownTagName: {value:"Owner", description:"Owner Tag Text for Owners"},
|
||||
ownAdminTagName: {value:"Admin", description:"Owner Tag Text for Admins"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let inputs = BDFDB.DataUtils.get(this, "inputs");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in inputs) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "TextInput",
|
||||
plugin: this,
|
||||
keys: ["inputs", key],
|
||||
label: this.defaults.inputs[key].description,
|
||||
basis: "50%",
|
||||
value: inputs[key]
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "Add Owner Tag in:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
this.forceUpdateAll();
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
}
|
||||
|
||||
processMemberListItem (e) {
|
||||
let usertype = this.getUserType(e.instance.props.user);
|
||||
if (usertype && BDFDB.DataUtils.get(this, "settings", "addInMemberList")) {
|
||||
this.injectOwnerTag(BDFDB.ReactUtils.getValue(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, usertype, 1, BDFDB.disCN.bottagmember);
|
||||
}
|
||||
}
|
||||
|
||||
processMessageHeader (e) {
|
||||
if (e.instance.props.message && BDFDB.DataUtils.get(this, "settings", "addInChatWindow")) {
|
||||
let usertype = this.getUserType(e.instance.props.message.author);
|
||||
if (usertype) this.injectOwnerTag(e.returnvalue.props.children[2].props.children, e.instance.props.message.author, usertype, e.instance.props.compact ? 0 : 2, e.instance.props.compact ? BDFDB.disCN.messagebottagcompact : BDFDB.disCN.messagebottagcozy);
|
||||
}
|
||||
}
|
||||
|
||||
processNameTag (e) {
|
||||
if (e.instance.props.user && e.instance.props.className) {
|
||||
let usertype = this.getUserType(e.instance.props.user);
|
||||
if (usertype) {
|
||||
let inject = false, bottag = "";
|
||||
switch (e.instance.props.className) {
|
||||
case BDFDB.disCN.userpopoutheadertagnonickname:
|
||||
inject = BDFDB.DataUtils.get(this, "settings", "addInUserPopout");
|
||||
bottag = BDFDB.disCN.bottagnametag;
|
||||
break;
|
||||
case BDFDB.disCN.userprofilenametag:
|
||||
inject = BDFDB.DataUtils.get(this, "settings", "addInUserProfile");
|
||||
bottag = BDFDB.disCNS.userprofilebottag + BDFDB.disCN.bottagnametag;
|
||||
break;
|
||||
}
|
||||
if (inject) this.injectOwnerTag(e.returnvalue.props.children, e.instance.props.user, usertype, 2, bottag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processUserPopout (e) {
|
||||
if (e.instance.props.user && BDFDB.DataUtils.get(this, "settings", "addInUserPopout")) {
|
||||
let usertype = this.getUserType(e.instance.props.user);
|
||||
if (usertype) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props: [["className", BDFDB.disCN.userpopoutheadertagwithnickname]]});
|
||||
if (index > -1) this.injectOwnerTag(children, e.instance.props.user, usertype, 2, BDFDB.disCNS.userpopoutheaderbottagwithnickname + BDFDB.disCN.bottagnametag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
injectOwnerTag (children, user, usertype, insertindex, tagclass = "", inverted = false) {
|
||||
if (!BDFDB.ArrayUtils.is(children) || !user) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (settings.useCrown || settings.hideNativeCrown) {
|
||||
let [_, index] = BDFDB.ReactUtils.findChildren(children, {props: [["text",[BDFDB.LanguageUtils.LanguageStrings.GROUP_OWNER, BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER]]]});
|
||||
if (index > -1) children[index] = null;
|
||||
}
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(BDFDB.LibraryModules.LastChannelStore.getChannelId());
|
||||
let member = settings.useRoleColor ? (BDFDB.LibraryModules.MemberStore.getMember(channel.guild_id, user.id) || {}) : {};
|
||||
let isOwner = usertype == 2;
|
||||
let tag = null;
|
||||
if (settings.useCrown) {
|
||||
let label = isOwner ? (channel.type == 3 ? BDFDB.LanguageUtils.LanguageStrings.GROUP_OWNER : BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER) : BDFDB.LanguageUtils.LanguageStrings.ADMINISTRATOR;
|
||||
tag = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: label,
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCNS.memberownericon + (isOwner ? "owner-crown" : "admin-crown"),
|
||||
name: BDFDB.LibraryComponents.SvgIcon.Names.CROWN,
|
||||
"aria-label": label
|
||||
})
|
||||
});
|
||||
}
|
||||
else {
|
||||
let tagcolor = BDFDB.ColorUtils.convert(member.colorString, "RGBA");
|
||||
let isbright = BDFDB.ColorUtils.isBright(tagcolor);
|
||||
tagcolor = isbright ? (settings.useBlackFont ? tagcolor : BDFDB.ColorUtils.change(tagcolor, -0.3)) : tagcolor;
|
||||
tag = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BotTag, {
|
||||
className: tagclass,
|
||||
tag: BDFDB.DataUtils.get(this, "inputs", isOwner ? "ownTagName" : "ownAdminTagName"),
|
||||
invertColor: inverted,
|
||||
style: {
|
||||
backgroundColor: inverted ? (isbright && settings.useBlackFont ? "black" : null) : tagcolor,
|
||||
color: !inverted ? (isbright && settings.useBlackFont ? "black" : null) : tagcolor
|
||||
}
|
||||
});
|
||||
}
|
||||
children.splice(insertindex, 0, tag);
|
||||
}
|
||||
|
||||
getUserType (user) {
|
||||
if (!user) return 0;
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(BDFDB.LibraryModules.LastChannelStore.getChannelId());
|
||||
if (!channel) return 0;
|
||||
let guild = BDFDB.LibraryModules.GuildStore.getGuild(channel.guild_id);
|
||||
let isowner = channel.ownerId == user.id || guild && guild.ownerId == user.id;
|
||||
if (!(isowner || (BDFDB.DataUtils.get(this, "settings", "addForAdmins") && BDFDB.UserUtils.can("ADMINISTRATOR", user.id)))) return 0;
|
||||
return isowner ? 2 : 1;
|
||||
}
|
||||
|
||||
forceUpdateAll () {
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
BDFDB.MessageUtils.rerenderAll();
|
||||
}
|
||||
}
|
||||
|
||||
getUserType (user) {
|
||||
if (!user) return 0;
|
||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(BDFDB.LibraryModules.LastChannelStore.getChannelId());
|
||||
if (!channel) return 0;
|
||||
let guild = BDFDB.LibraryModules.GuildStore.getGuild(channel.guild_id);
|
||||
let isowner = channel.ownerId == user.id || guild && guild.ownerId == user.id;
|
||||
if (!(isowner || (BDFDB.DataUtils.get(this, "settings", "addForAdmins") && BDFDB.UserUtils.can("ADMINISTRATOR", user.id)))) return 0;
|
||||
return isowner ? 2 : 1;
|
||||
}
|
||||
}
|
||||
})();
|
File diff suppressed because it is too large
Load Diff
|
@ -122,6 +122,7 @@ https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/O
|
|||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PersonalPins/PersonalPins.plugin.js
|
||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PinDMs/PinDMs.plugin.js
|
||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PluginRepo/PluginRepo.plugin.js
|
||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/QuickMention/QuickMention.plugin.js
|
||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js
|
||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/RemoveNicknames/RemoveNicknames.plugin.js
|
||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/RepoControls/RepoControls.plugin.js
|
||||
|
|
|
@ -1,422 +1,433 @@
|
|||
//META{"name":"ReadAllNotificationsButton","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ReadAllNotificationsButton","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js"}*//
|
||||
|
||||
class ReadAllNotificationsButton {
|
||||
getName () {return "ReadAllNotificationsButton";}
|
||||
var ReadAllNotificationsButton = (_ => {
|
||||
return class ReadAllNotificationsButton {
|
||||
getName () {return "ReadAllNotificationsButton";}
|
||||
|
||||
getVersion () {return "1.5.4";}
|
||||
getVersion () {return "1.5.5";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds a button to clear all notifications.";}
|
||||
getDescription () {return "Adds a button to clear all notifications.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Clear Mentions","Clear Mentions buton is now properly added again"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
Guilds: "render",
|
||||
MessagesPopout: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCN._readallnotificationsbuttonframe} {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
${BDFDB.dotCN._readallnotificationsbuttonbutton} {
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.3;
|
||||
}
|
||||
`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
addClearButton: {value:true, inner:false, description:"Adds a 'Clear Mentions' button to the recent mentions popout"},
|
||||
includeGuilds: {value:true, inner:true, description:"unread Servers"},
|
||||
includeMuted: {value:false, inner:true, description:"muted unread Servers"},
|
||||
includeDMs: {value:false, inner:true, description:"unread DMs"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key],
|
||||
disabled: key == "includeMuted" && !settings.includeGuilds,
|
||||
onChange: (value, instance) => {
|
||||
if (key != "includeGuilds") return;
|
||||
let mutedSwitchIns = BDFDB.ReactUtils.findOwner(instance, {props:[["keys",["settings", "includeMuted"]]]});
|
||||
if (mutedSwitchIns) {
|
||||
mutedSwitchIns.props.disabled = !value;
|
||||
BDFDB.ReactUtils.forceUpdate(mutedSwitchIns);
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
Guilds: "render",
|
||||
MessagesPopout: "render"
|
||||
}
|
||||
}
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "When left clicking the 'read all' button mark following Elements as read:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
};
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCN._readallnotificationsbuttonframe} {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
${BDFDB.dotCN._readallnotificationsbuttonbutton} {
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.3;
|
||||
}
|
||||
`;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
this.defaults = {
|
||||
settings: {
|
||||
addClearButton: {value:true, inner:false, description:"Adds a 'Clear Mentions' button to the recent mentions popout"},
|
||||
confirmClear: {value:false, inner:false, description:"Asks for your confirmation before clearing reads."},
|
||||
includeGuilds: {value:true, inner:true, description:"unread Servers"},
|
||||
includeMuted: {value:false, inner:true, description:"muted unread Servers"},
|
||||
includeDMs: {value:false, inner:true, description:"unread DMs"}
|
||||
}
|
||||
};
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onUserContextMenu (e) {
|
||||
if (e.instance.props.channelId && e.instance.props.type == BDFDB.DiscordConstants.ContextMenuTypes.USER_PRIVATE_CHANNELS) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: BDFDB.LibraryComponents.ContextMenuItems.Group});
|
||||
if (index > -1) this.injectItem(children, e.instance.props.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
onGroupDMContextMenu (e) {
|
||||
if (e.instance.props.channelId) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: BDFDB.LibraryComponents.ContextMenuItems.Group});
|
||||
if (index > -1) this.injectItem(children, e.instance.props.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
injectItem (children, channelId) {
|
||||
children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.MARK_AS_READ,
|
||||
disabled: !BDFDB.LibraryModules.DirectMessageUnreadStore.getUnreadPrivateChannelIds().includes(channelId),
|
||||
action: event => {
|
||||
BDFDB.ContextMenuUtils.close(event.target);
|
||||
BDFDB.DMUtils.markAsRead(channelId);
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
processGuilds (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ConnectedUnreadDMs"});
|
||||
if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.guildouter + BDFDB.disCN._readallnotificationsbuttonframe,
|
||||
style: {height: 20},
|
||||
children: BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.guildiconwrapper + BDFDB.disCN._readallnotificationsbuttoninner,
|
||||
style: {height: 20},
|
||||
children: BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.guildiconchildwrapper + BDFDB.disCN._readallnotificationsbuttonbutton,
|
||||
style: {height: 20},
|
||||
children: "read all",
|
||||
onClick: _ => {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (settings.includeGuilds) BDFDB.GuildUtils.markAsRead(settings.includeMuted ? BDFDB.GuildUtils.getAll() : BDFDB.GuildUtils.getUnread());
|
||||
if (settings.includeDMs) BDFDB.DMUtils.markAsRead(BDFDB.DMUtils.getAll());
|
||||
},
|
||||
onContextMenu: event => {
|
||||
BDFDB.ContextMenuUtils.open(this, event, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_unreadguilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getUnread());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_pingedguilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getPinged());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_mutedguilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getMuted());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_guilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
this.addPinnedRecent(instance.props.channel.id);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getAll());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_dms_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.DMUtils.markAsRead(BDFDB.DMUtils.getAll());
|
||||
}
|
||||
})
|
||||
]
|
||||
}));
|
||||
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key],
|
||||
disabled: key == "includeMuted" && !settings.includeGuilds,
|
||||
onChange: (value, instance) => {
|
||||
if (key != "includeGuilds") return;
|
||||
let mutedSwitchIns = BDFDB.ReactUtils.findOwner(instance, {props:[["keys",["settings", "includeMuted"]]]});
|
||||
if (mutedSwitchIns) {
|
||||
mutedSwitchIns.props.disabled = !value;
|
||||
BDFDB.ReactUtils.forceUpdate(mutedSwitchIns);
|
||||
}
|
||||
})
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
processMessagesPopout (e) {
|
||||
if (e.instance.props.className == BDFDB.disCN.recentmentionspopout && BDFDB.DataUtils.get(this, "settings", "addClearButton")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "RecentMentionsHeader"});
|
||||
if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, {
|
||||
look: BDFDB.LibraryComponents.Button.Looks.OUTLINED,
|
||||
color: BDFDB.LibraryComponents.Button.Colors.GREY,
|
||||
hover: BDFDB.LibraryComponents.Button.Hovers.RED,
|
||||
size: BDFDB.LibraryComponents.Button.Sizes.SMALL,
|
||||
children: BDFDB.LanguageUtils.LanguageStrings.REMOVE,
|
||||
onClick: (event, buttoninstance) => {
|
||||
this.clearMentions(e.instance, BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagespopoutwrap, BDFDB.ReactUtils.findDOMNode(buttoninstance)));
|
||||
},
|
||||
style: {
|
||||
position: "absolute",
|
||||
top: 8,
|
||||
right: 20
|
||||
}
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "When left clicking the 'read all' button mark following Elements as read:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
}
|
||||
|
||||
clearMentions (instance, wrapper) {
|
||||
if (!instance || !Node.prototype.isPrototypeOf(wrapper) || !document.contains(wrapper)) return;
|
||||
let closebuttons = wrapper.querySelectorAll(BDFDB.dotCN.messagespopoutclosebutton);
|
||||
for (let btn of wrapper.querySelectorAll(BDFDB.dotCN.messagespopoutclosebutton)) btn.click();
|
||||
if (closebuttons.length) {
|
||||
instance.props.loadMore();
|
||||
BDFDB.TimeUtils.timeout(_ => {this.clearMentions(instance, wrapper);},3000);
|
||||
}
|
||||
}
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
setLabelsByLanguage () {
|
||||
switch (BDFDB.LanguageUtils.getLanguage().id) {
|
||||
case "hr": //croatian
|
||||
return {
|
||||
context_unreadguilds_text: "Nepročitani poslužitelje",
|
||||
context_pingedguilds_text: "Zvižduci poslužitelje",
|
||||
context_mutedguilds_text: "Prigušeni poslužitelje",
|
||||
context_guilds_text: "Sve poslužitelje",
|
||||
context_dms_text: "Prikvacene izravne"
|
||||
};
|
||||
case "da": //danish
|
||||
return {
|
||||
context_unreadguilds_text: "Ulæste servere",
|
||||
context_pingedguilds_text: "Pinget servere",
|
||||
context_mutedguilds_text: "Dæmpede servere",
|
||||
context_guilds_text: "Alle servere",
|
||||
context_dms_text: "Private beskeder"
|
||||
};
|
||||
case "de": //german
|
||||
return {
|
||||
context_unreadguilds_text: "Ungelesene Server",
|
||||
context_pingedguilds_text: "Gepingte Server",
|
||||
context_mutedguilds_text: "Stummgeschaltene Server",
|
||||
context_guilds_text: "Alle Server",
|
||||
context_dms_text: "Direktnachrichten"
|
||||
};
|
||||
case "es": //spanish
|
||||
return {
|
||||
context_unreadguilds_text: "Servidores no leídos",
|
||||
context_pingedguilds_text: "Servidores mencionados",
|
||||
context_mutedguilds_text: "Servidores silenciados",
|
||||
context_guilds_text: "Todos los servidores",
|
||||
context_dms_text: "Mensajes directos"
|
||||
};
|
||||
case "fr": //french
|
||||
return {
|
||||
context_unreadguilds_text: "Serveurs non lus",
|
||||
context_pingedguilds_text: "Serveurs mentionnés",
|
||||
context_mutedguilds_text: "Serveurs en sourdine",
|
||||
context_guilds_text: "Tous les serveurs",
|
||||
context_dms_text: "Messages privés"
|
||||
};
|
||||
case "it": //italian
|
||||
return {
|
||||
context_unreadguilds_text: "Server non letti",
|
||||
context_pingedguilds_text: "Server pingato",
|
||||
context_mutedguilds_text: "Server mutate",
|
||||
context_guilds_text: "Tutti i server",
|
||||
context_dms_text: "Messaggi diretti"
|
||||
};
|
||||
case "nl": //dutch
|
||||
return {
|
||||
context_unreadguilds_text: "Ongelezen servers",
|
||||
context_pingedguilds_text: "Gepingde servers",
|
||||
context_mutedguilds_text: "Gedempte servers",
|
||||
context_guilds_text: "Alle servers",
|
||||
context_dms_text: "Prive berichten"
|
||||
};
|
||||
case "no": //norwegian
|
||||
return {
|
||||
context_unreadguilds_text: "Uleste servere",
|
||||
context_pingedguilds_text: "Pinget servere",
|
||||
context_mutedguilds_text: "Dempet servere",
|
||||
context_guilds_text: "Alle servere",
|
||||
context_dms_text: "Direktemeldinger"
|
||||
};
|
||||
case "pl": //polish
|
||||
return {
|
||||
context_unreadguilds_text: "Nieprzeczytane serwery",
|
||||
context_pingedguilds_text: "Pingowany serwery",
|
||||
context_mutedguilds_text: "Wyciszone serwery",
|
||||
context_guilds_text: "Wszystkie serwery",
|
||||
context_dms_text: "Prywatne wiadomości"
|
||||
};
|
||||
case "pt-BR": //portuguese (brazil)
|
||||
return {
|
||||
context_unreadguilds_text: "Servidores não lidos",
|
||||
context_pingedguilds_text: "Servidores com ping",
|
||||
context_mutedguilds_text: "Servidores silenciosos",
|
||||
context_guilds_text: "Todos os servidores",
|
||||
context_dms_text: "Mensagens diretas"
|
||||
};
|
||||
case "fi": //finnish
|
||||
return {
|
||||
context_unreadguilds_text: "Lukemattomia palvelimet",
|
||||
context_pingedguilds_text: "Tapitut palvelimet",
|
||||
context_mutedguilds_text: "Mykistetyt palvelimet",
|
||||
context_guilds_text: "Kaikki palvelimet",
|
||||
context_dms_text: "Yksityisviestit"
|
||||
};
|
||||
case "sv": //swedish
|
||||
return {
|
||||
context_unreadguilds_text: "Olästa servrar",
|
||||
context_pingedguilds_text: "Pingade servrar",
|
||||
context_mutedguilds_text: "Dämpade servrar",
|
||||
context_guilds_text: "Alla servrar",
|
||||
context_dms_text: "Direktmeddelanden"
|
||||
};
|
||||
case "tr": //turkish
|
||||
return {
|
||||
context_unreadguilds_text: "Okunmamış sunucular",
|
||||
context_pingedguilds_text: "Ping sunucular",
|
||||
context_mutedguilds_text: "Sessiz sunucular",
|
||||
context_guilds_text: "Tüm sunucular",
|
||||
context_dms_text: "Özel mesajlar"
|
||||
};
|
||||
case "cs": //czech
|
||||
return {
|
||||
context_unreadguilds_text: "Nepřečtené servery",
|
||||
context_pingedguilds_text: "Pinged servery",
|
||||
context_mutedguilds_text: "Tlumené servery",
|
||||
context_guilds_text: "Všechny servery",
|
||||
context_dms_text: "Přímé zpráva"
|
||||
};
|
||||
case "bg": //bulgarian
|
||||
return {
|
||||
context_unreadguilds_text: "Непрочетени сървъри",
|
||||
context_pingedguilds_text: "Споменатите сървъри",
|
||||
context_mutedguilds_text: "Приглушени сървъри",
|
||||
context_guilds_text: "Всички сървъри",
|
||||
context_dms_text: "Директно съобщение"
|
||||
};
|
||||
case "ru": //russian
|
||||
return {
|
||||
context_unreadguilds_text: "Непрочитанные серверы",
|
||||
context_pingedguilds_text: "Проверенные серверы",
|
||||
context_mutedguilds_text: "Отключенные серверы",
|
||||
context_guilds_text: "Все серверы",
|
||||
context_dms_text: "Прямые сообщения"
|
||||
};
|
||||
case "uk": //ukrainian
|
||||
return {
|
||||
context_unreadguilds_text: "Непрочитаних сервери",
|
||||
context_pingedguilds_text: "Згадані сервери",
|
||||
context_mutedguilds_text: "Приглушені сервери",
|
||||
context_guilds_text: "Всі сервери",
|
||||
context_dms_text: "Прямі Повідомлення"
|
||||
};
|
||||
case "ja": //japanese
|
||||
return {
|
||||
context_unreadguilds_text: "未読サーバー",
|
||||
context_pingedguilds_text: "",
|
||||
context_mutedguilds_text: "ミュートサーバー",
|
||||
context_guilds_text: "すべてのサーバー",
|
||||
context_dms_text: "ダイレクトメッセージ"
|
||||
};
|
||||
case "zh-TW": //chinese (traditional)
|
||||
return {
|
||||
context_unreadguilds_text: "未讀服務器",
|
||||
context_pingedguilds_text: "言及されたサーバー",
|
||||
context_mutedguilds_text: "靜音服務器",
|
||||
context_guilds_text: "所有服務器",
|
||||
context_dms_text: "直接消息",
|
||||
};
|
||||
case "ko": //korean
|
||||
return {
|
||||
context_unreadguilds_text: "읽지 않은 서버",
|
||||
context_pingedguilds_text: "언급 된 서버",
|
||||
context_mutedguilds_text: "음소거 된 서버",
|
||||
context_guilds_text: "모든 서버",
|
||||
context_dms_text: "직접 메시지"
|
||||
};
|
||||
default: //default: english
|
||||
return {
|
||||
context_unreadguilds_text: "Unread Servers",
|
||||
context_pingedguilds_text: "Pinged Servers",
|
||||
context_mutedguilds_text: "Muted Servers",
|
||||
context_guilds_text: "All Servers",
|
||||
context_dms_text: "Direct Messages"
|
||||
};
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onUserContextMenu (e) {
|
||||
if (e.instance.props.channelId && e.instance.props.type == BDFDB.DiscordConstants.ContextMenuTypes.USER_PRIVATE_CHANNELS) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: BDFDB.LibraryComponents.ContextMenuItems.Group});
|
||||
if (index > -1) this.injectItem(children, e.instance.props.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
onGroupDMContextMenu (e) {
|
||||
if (e.instance.props.channelId) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: BDFDB.LibraryComponents.ContextMenuItems.Group});
|
||||
if (index > -1) this.injectItem(children, e.instance.props.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
injectItem (children, channelId) {
|
||||
children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.MARK_AS_READ,
|
||||
disabled: !BDFDB.LibraryModules.DirectMessageUnreadStore.getUnreadPrivateChannelIds().includes(channelId),
|
||||
action: event => {
|
||||
BDFDB.ContextMenuUtils.close(event.target);
|
||||
BDFDB.DMUtils.markAsRead(channelId);
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
processGuilds (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ConnectedUnreadDMs"});
|
||||
if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.guildouter + BDFDB.disCN._readallnotificationsbuttonframe,
|
||||
style: {height: 20},
|
||||
children: BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.guildiconwrapper + BDFDB.disCN._readallnotificationsbuttoninner,
|
||||
style: {height: 20},
|
||||
children: BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.guildiconchildwrapper + BDFDB.disCN._readallnotificationsbuttonbutton,
|
||||
style: {height: 20},
|
||||
children: "read all",
|
||||
onClick: _ => {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings"), clear = _ => {
|
||||
if (settings.includeGuilds) BDFDB.GuildUtils.markAsRead(settings.includeMuted ? BDFDB.GuildUtils.getAll() : BDFDB.GuildUtils.getUnread());
|
||||
if (settings.includeDMs) BDFDB.DMUtils.markAsRead(BDFDB.DMUtils.getAll());
|
||||
};
|
||||
if (!settings.confirmClear) clear();
|
||||
else BDFDB.ModalUtils.confirm(this, `Are you sure you want to mark all Notifications as read?`, clear);
|
||||
},
|
||||
onContextMenu: event => {
|
||||
BDFDB.ContextMenuUtils.open(this, event, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_unreadguilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getUnread());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_pingedguilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getPinged());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_mutedguilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getMuted());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_guilds_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
this.addPinnedRecent(instance.props.channel.id);
|
||||
BDFDB.GuildUtils.markAsRead(BDFDB.GuildUtils.getAll());
|
||||
}
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: this.labels.context_dms_text,
|
||||
action: event2 => {
|
||||
BDFDB.ContextMenuUtils.close(event2._targetInst);
|
||||
BDFDB.DMUtils.markAsRead(BDFDB.DMUtils.getAll());
|
||||
}
|
||||
})
|
||||
]
|
||||
}));
|
||||
}
|
||||
})
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
processMessagesPopout (e) {
|
||||
if (e.instance.props.className == BDFDB.disCN.recentmentionspopout && BDFDB.DataUtils.get(this, "settings", "addClearButton")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "RecentMentionsHeader"});
|
||||
if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, {
|
||||
look: BDFDB.LibraryComponents.Button.Looks.OUTLINED,
|
||||
color: BDFDB.LibraryComponents.Button.Colors.GREY,
|
||||
hover: BDFDB.LibraryComponents.Button.Hovers.RED,
|
||||
size: BDFDB.LibraryComponents.Button.Sizes.MIN,
|
||||
children: BDFDB.LanguageUtils.LanguageStrings.REMOVE,
|
||||
onClick: (event, buttoninstance) => {
|
||||
let clear = _ => {
|
||||
this.clearMentions(e.instance, BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagespopoutwrap, BDFDB.ReactUtils.findDOMNode(buttoninstance)));
|
||||
};
|
||||
if (!BDFDB.DataUtils.get(this, "settings", "confirmClear")) clear();
|
||||
else BDFDB.ModalUtils.confirm(this, `Are you sure you want to mark all Mentions as read?`, clear);
|
||||
},
|
||||
style: {
|
||||
position: "absolute",
|
||||
top: 14,
|
||||
right: 16,
|
||||
zIndex: 1
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
clearMentions (instance, wrapper) {
|
||||
if (!instance || !Node.prototype.isPrototypeOf(wrapper) || !document.contains(wrapper)) return;
|
||||
let closebuttons = wrapper.querySelectorAll(BDFDB.dotCN.messagespopoutclosebutton);
|
||||
for (let btn of closebuttons) btn.click();
|
||||
if (closebuttons.length) {
|
||||
instance.props.loadMore();
|
||||
BDFDB.TimeUtils.timeout(_ => {this.clearMentions(instance, wrapper);},3000);
|
||||
}
|
||||
}
|
||||
|
||||
setLabelsByLanguage () {
|
||||
switch (BDFDB.LanguageUtils.getLanguage().id) {
|
||||
case "hr": //croatian
|
||||
return {
|
||||
context_unreadguilds_text: "Nepročitani poslužitelje",
|
||||
context_pingedguilds_text: "Zvižduci poslužitelje",
|
||||
context_mutedguilds_text: "Prigušeni poslužitelje",
|
||||
context_guilds_text: "Sve poslužitelje",
|
||||
context_dms_text: "Prikvacene izravne"
|
||||
};
|
||||
case "da": //danish
|
||||
return {
|
||||
context_unreadguilds_text: "Ulæste servere",
|
||||
context_pingedguilds_text: "Pinget servere",
|
||||
context_mutedguilds_text: "Dæmpede servere",
|
||||
context_guilds_text: "Alle servere",
|
||||
context_dms_text: "Private beskeder"
|
||||
};
|
||||
case "de": //german
|
||||
return {
|
||||
context_unreadguilds_text: "Ungelesene Server",
|
||||
context_pingedguilds_text: "Gepingte Server",
|
||||
context_mutedguilds_text: "Stummgeschaltene Server",
|
||||
context_guilds_text: "Alle Server",
|
||||
context_dms_text: "Direktnachrichten"
|
||||
};
|
||||
case "es": //spanish
|
||||
return {
|
||||
context_unreadguilds_text: "Servidores no leídos",
|
||||
context_pingedguilds_text: "Servidores mencionados",
|
||||
context_mutedguilds_text: "Servidores silenciados",
|
||||
context_guilds_text: "Todos los servidores",
|
||||
context_dms_text: "Mensajes directos"
|
||||
};
|
||||
case "fr": //french
|
||||
return {
|
||||
context_unreadguilds_text: "Serveurs non lus",
|
||||
context_pingedguilds_text: "Serveurs mentionnés",
|
||||
context_mutedguilds_text: "Serveurs en sourdine",
|
||||
context_guilds_text: "Tous les serveurs",
|
||||
context_dms_text: "Messages privés"
|
||||
};
|
||||
case "it": //italian
|
||||
return {
|
||||
context_unreadguilds_text: "Server non letti",
|
||||
context_pingedguilds_text: "Server pingato",
|
||||
context_mutedguilds_text: "Server mutate",
|
||||
context_guilds_text: "Tutti i server",
|
||||
context_dms_text: "Messaggi diretti"
|
||||
};
|
||||
case "nl": //dutch
|
||||
return {
|
||||
context_unreadguilds_text: "Ongelezen servers",
|
||||
context_pingedguilds_text: "Gepingde servers",
|
||||
context_mutedguilds_text: "Gedempte servers",
|
||||
context_guilds_text: "Alle servers",
|
||||
context_dms_text: "Prive berichten"
|
||||
};
|
||||
case "no": //norwegian
|
||||
return {
|
||||
context_unreadguilds_text: "Uleste servere",
|
||||
context_pingedguilds_text: "Pinget servere",
|
||||
context_mutedguilds_text: "Dempet servere",
|
||||
context_guilds_text: "Alle servere",
|
||||
context_dms_text: "Direktemeldinger"
|
||||
};
|
||||
case "pl": //polish
|
||||
return {
|
||||
context_unreadguilds_text: "Nieprzeczytane serwery",
|
||||
context_pingedguilds_text: "Pingowany serwery",
|
||||
context_mutedguilds_text: "Wyciszone serwery",
|
||||
context_guilds_text: "Wszystkie serwery",
|
||||
context_dms_text: "Prywatne wiadomości"
|
||||
};
|
||||
case "pt-BR": //portuguese (brazil)
|
||||
return {
|
||||
context_unreadguilds_text: "Servidores não lidos",
|
||||
context_pingedguilds_text: "Servidores com ping",
|
||||
context_mutedguilds_text: "Servidores silenciosos",
|
||||
context_guilds_text: "Todos os servidores",
|
||||
context_dms_text: "Mensagens diretas"
|
||||
};
|
||||
case "fi": //finnish
|
||||
return {
|
||||
context_unreadguilds_text: "Lukemattomia palvelimet",
|
||||
context_pingedguilds_text: "Tapitut palvelimet",
|
||||
context_mutedguilds_text: "Mykistetyt palvelimet",
|
||||
context_guilds_text: "Kaikki palvelimet",
|
||||
context_dms_text: "Yksityisviestit"
|
||||
};
|
||||
case "sv": //swedish
|
||||
return {
|
||||
context_unreadguilds_text: "Olästa servrar",
|
||||
context_pingedguilds_text: "Pingade servrar",
|
||||
context_mutedguilds_text: "Dämpade servrar",
|
||||
context_guilds_text: "Alla servrar",
|
||||
context_dms_text: "Direktmeddelanden"
|
||||
};
|
||||
case "tr": //turkish
|
||||
return {
|
||||
context_unreadguilds_text: "Okunmamış sunucular",
|
||||
context_pingedguilds_text: "Ping sunucular",
|
||||
context_mutedguilds_text: "Sessiz sunucular",
|
||||
context_guilds_text: "Tüm sunucular",
|
||||
context_dms_text: "Özel mesajlar"
|
||||
};
|
||||
case "cs": //czech
|
||||
return {
|
||||
context_unreadguilds_text: "Nepřečtené servery",
|
||||
context_pingedguilds_text: "Pinged servery",
|
||||
context_mutedguilds_text: "Tlumené servery",
|
||||
context_guilds_text: "Všechny servery",
|
||||
context_dms_text: "Přímé zpráva"
|
||||
};
|
||||
case "bg": //bulgarian
|
||||
return {
|
||||
context_unreadguilds_text: "Непрочетени сървъри",
|
||||
context_pingedguilds_text: "Споменатите сървъри",
|
||||
context_mutedguilds_text: "Приглушени сървъри",
|
||||
context_guilds_text: "Всички сървъри",
|
||||
context_dms_text: "Директно съобщение"
|
||||
};
|
||||
case "ru": //russian
|
||||
return {
|
||||
context_unreadguilds_text: "Непрочитанные серверы",
|
||||
context_pingedguilds_text: "Проверенные серверы",
|
||||
context_mutedguilds_text: "Отключенные серверы",
|
||||
context_guilds_text: "Все серверы",
|
||||
context_dms_text: "Прямые сообщения"
|
||||
};
|
||||
case "uk": //ukrainian
|
||||
return {
|
||||
context_unreadguilds_text: "Непрочитаних сервери",
|
||||
context_pingedguilds_text: "Згадані сервери",
|
||||
context_mutedguilds_text: "Приглушені сервери",
|
||||
context_guilds_text: "Всі сервери",
|
||||
context_dms_text: "Прямі Повідомлення"
|
||||
};
|
||||
case "ja": //japanese
|
||||
return {
|
||||
context_unreadguilds_text: "未読サーバー",
|
||||
context_pingedguilds_text: "",
|
||||
context_mutedguilds_text: "ミュートサーバー",
|
||||
context_guilds_text: "すべてのサーバー",
|
||||
context_dms_text: "ダイレクトメッセージ"
|
||||
};
|
||||
case "zh-TW": //chinese (traditional)
|
||||
return {
|
||||
context_unreadguilds_text: "未讀服務器",
|
||||
context_pingedguilds_text: "言及されたサーバー",
|
||||
context_mutedguilds_text: "靜音服務器",
|
||||
context_guilds_text: "所有服務器",
|
||||
context_dms_text: "直接消息",
|
||||
};
|
||||
case "ko": //korean
|
||||
return {
|
||||
context_unreadguilds_text: "읽지 않은 서버",
|
||||
context_pingedguilds_text: "언급 된 서버",
|
||||
context_mutedguilds_text: "음소거 된 서버",
|
||||
context_guilds_text: "모든 서버",
|
||||
context_dms_text: "직접 메시지"
|
||||
};
|
||||
default: //default: english
|
||||
return {
|
||||
context_unreadguilds_text: "Unread Servers",
|
||||
context_pingedguilds_text: "Pinged Servers",
|
||||
context_mutedguilds_text: "Muted Servers",
|
||||
context_guilds_text: "All Servers",
|
||||
context_dms_text: "Direct Messages"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,215 +1,201 @@
|
|||
//META{"name":"RemoveNicknames","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/RemoveNicknames","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/RemoveNicknames/RemoveNicknames.plugin.js"}*//
|
||||
|
||||
class RemoveNicknames {
|
||||
getName () {return "RemoveNicknames";}
|
||||
var RemoveNicknames = (_ => {
|
||||
return class RemoveNicknames {
|
||||
getName () {return "RemoveNicknames";}
|
||||
|
||||
getVersion () {return "1.2.7";}
|
||||
getVersion () {return "1.2.8";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Replace all nicknames with the actual accountnames.";}
|
||||
getDescription () {return "Replace all nicknames with the actual accountnames.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"added":[["Ignore Elements","Added an option list that let's you costumize in which places nicknames are being removed"]]
|
||||
};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
"MemberListItem":"componentDidMount",
|
||||
"MessageUsername":"componentDidMount",
|
||||
"TypingUsers":"componentDidUpdate",
|
||||
"Clickable":"componentDidMount",
|
||||
"StandardSidebarView":"componentWillUnmount"
|
||||
this.patchedModules = {
|
||||
before: {
|
||||
AutocompleteUserResult: "render",
|
||||
VoiceUser: "render",
|
||||
MemberListItem: "render",
|
||||
Message: "default",
|
||||
MessageContent: "type",
|
||||
TypingUsers: "render",
|
||||
Clickable:"componentDidMount"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.defaults = {
|
||||
settings: {
|
||||
replaceOwn: {value:false, inner:false, description:"Replace your own name:"},
|
||||
replaceBots: {value:true, inner:false, description:"Replace the nickname of bots:"},
|
||||
addNickname: {value:false, inner:false, description:"Add nickname as parentheses:"},
|
||||
swapPositions: {value:false, inner:false, description:"Swap the position of username and nickname:"},
|
||||
changeInChatWindow: {value:true, inner:true, description:"Messages"},
|
||||
changeInMentions: {value:true, inner:true, description:"Mentions"},
|
||||
changeInVoiceChat: {value:true, inner:true, description:"Voice Channels"},
|
||||
changeInMemberList: {value:true, inner:true, description:"Member List"},
|
||||
changeInTyping: {value:true, inner:true, description:"Typing List"},
|
||||
changeInAutoComplete: {value:true, inner:true, description:"Autocomplete Menu"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "Remove Nicknames in:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.defaults = {
|
||||
settings: {
|
||||
replaceOwn: {value:false, inner:false, description:"Replace your own name:"},
|
||||
replaceBots: {value:true, inner:false, description:"Replace the nickname of bots:"},
|
||||
addNickname: {value:false, inner:false, description:"Add nickname as parentheses:"},
|
||||
swapPositions: {value:false, inner:false, description:"Swap the position of username and nickname:"},
|
||||
changeInChatWindow: {value:true, inner:true, description:"Messages"},
|
||||
changeInMentions: {value:true, inner:true, description:"Mentions"},
|
||||
changeInVoiceChat: {value:true, inner:true, description:"Voice Channels"},
|
||||
changeInMemberList: {value:true, inner:true, description:"Member List"},
|
||||
changeInTyping: {value:true, inner:true, description:"Typing List"},
|
||||
changeInAutoComplete: {value:true, inner:true, description:"Autocomplete Menu"}
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.titlesize18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
|
||||
for (let key in settings) {
|
||||
if (!this.defaults.settings[key].inner) 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.titlesize16 + 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>`;
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
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.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 0 0 auto;">Remove Nicknames in:</h3></div><div class="BDFDB-settings-inner-list">`;
|
||||
for (let key in settings) {
|
||||
if (this.defaults.settings[key].inner) 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.titlesize16 + 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>`;
|
||||
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
this.forceUpdateAll();
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
settingshtml += `</div>`;
|
||||
settingshtml += `</div></div>`;
|
||||
|
||||
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
|
||||
|
||||
BDFDB.initElements(settingspanel, this);
|
||||
;
|
||||
return settingspanel;
|
||||
}
|
||||
// begin of own functions
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
onSettingsClosed (e) {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
this.reseting = false;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
processAutocompleteUserResult (e) {
|
||||
if (e.instance.props.user && e.instance.props.nick && BDFDB.DataUtils.get(this, "settings", "changeInAutoComplete")) {
|
||||
let newName = this.getNewName(e.instance.props.user);
|
||||
if (newName) e.instance.props.nick = newName;
|
||||
}
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
this.reseting = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
processVoiceUser (e) {
|
||||
if (e.instance.props.user && e.instance.props.nick && BDFDB.DataUtils.get(this, "settings", "changeInVoiceChat")) {
|
||||
let newName = this.getNewName(e.instance.props.user);
|
||||
if (newName) e.instance.props.nick = newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
processMemberListItem (instance, wrapper, returnvalue) {
|
||||
let user = BDFDB.ReactUtils.getValue(instance, "props.user");
|
||||
if (user) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.memberusername);
|
||||
if (username) BDFDB.DOMUtils.setText(username, this.getNewName(user, wrapper));
|
||||
processMemberListItem (e) {
|
||||
if (e.instance.props.user && e.instance.props.nick && BDFDB.DataUtils.get(this, "settings", "changeInMemberList")) {
|
||||
let newName = this.getNewName(e.instance.props.user);
|
||||
if (newName) e.instance.props.nick = newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processMessageUsername (instance, wrapper, returnvalue) {
|
||||
let message = BDFDB.ReactUtils.getValue(instance, "props.message");
|
||||
if (message) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.messageusername);
|
||||
if (username) BDFDB.DOMUtils.setText(username, this.getNewName(message.author, wrapper));
|
||||
}
|
||||
}
|
||||
|
||||
processTypingUsers (instance, wrapper, returnvalue) {
|
||||
let users = !instance.props.typingUsers ? [] : Object.keys(instance.props.typingUsers).filter(id => id != BDFDB.UserUtils.me.id).filter(id => !BDFDB.LibraryModules.FriendUtils.isBlocked(id)).map(id => BDFDB.LibraryModules.UserStore.getUser(id)).filter(id => id != null);
|
||||
wrapper.querySelectorAll("strong").forEach((username, i) => {
|
||||
if (users[i] && username) BDFDB.DOMUtils.setText(username, this.getNewName(users[i]));
|
||||
});
|
||||
}
|
||||
|
||||
processClickable (instance, wrapper, returnvalue) {
|
||||
if (!wrapper || !instance.props || !instance.props.className) return;
|
||||
if (instance.props.tag == "a" && instance.props.className.indexOf(BDFDB.disCN.anchorunderlineonhover) > -1) {
|
||||
if (BDFDB.DOMUtils.containsClass(wrapper.parentElement, BDFDB.disCN.messagesystemcontent) && wrapper.parentElement.querySelector("a") == wrapper) {
|
||||
let message = BDFDB.ReactUtils.findValue(wrapper.parentElement, "message", {up:true});
|
||||
if (message) {
|
||||
BDFDB.DOMUtils.setText(wrapper, this.getNewName(message.author, wrapper));
|
||||
if (message.mentions.length == 1) {
|
||||
let seconduser = BDFDB.LibraryModules.UserStore.getUser(message.mentions[0]);
|
||||
let secondwrapper = wrapper.parentElement.querySelectorAll("a")[1];
|
||||
if (seconduser && secondwrapper) BDFDB.DOMUtils.setText(secondwrapper, this.getNewName(seconduser, wrapper));
|
||||
processTypingUsers (e) {
|
||||
if (BDFDB.ObjectUtils.is(e.instance.props.typingUsers) && Object.keys(e.instance.props.typingUsers).length && BDFDB.DataUtils.get(this, "settings", "changeInTyping")) {
|
||||
let users = Object.keys(e.instance.props.typingUsers).filter(id => id != BDFDB.UserUtils.me.id).filter(id => !BDFDB.LibraryModules.FriendUtils.isBlocked(id)).map(id => BDFDB.LibraryModules.UserStore.getUser(id)).filter(user => user);
|
||||
if (users.length) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props: [["className", BDFDB.disCN.typingtext]]});
|
||||
if (index > -1 && BDFDB.ArrayUtils.is(children[index].props.children)) for (let child of children[index].props.children) if (child.type == "strong") {
|
||||
let newName = this.getNewName(users.shift());
|
||||
if (newName) child.props.children = newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (instance.props.tag == "span" && instance.props.className.indexOf(BDFDB.disCN.mention) > -1) {
|
||||
let render = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.return.stateNode.props.render");
|
||||
if (typeof render == "function") {
|
||||
var props = render().props;
|
||||
if (props && props.user) BDFDB.DOMUtils.setText(wrapper, "@" + this.getNewName(props.user, wrapper));
|
||||
else if (props && props.userId) BDFDB.DOMUtils.setText(wrapper, "@" + this.getNewName(BDFDB.LibraryModules.UserStore.getUser(props.userId), wrapper));
|
||||
}
|
||||
}
|
||||
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.voiceuser) > -1) {
|
||||
let user = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.memoizedProps.user");
|
||||
if (user) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.voicename);
|
||||
if (username) BDFDB.DOMUtils.setText(username, this.getNewName(user, username));
|
||||
}
|
||||
}
|
||||
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.autocompleterow) > -1) {
|
||||
let user = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.memoizedProps.user");
|
||||
if (user) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.marginleft8);
|
||||
if (username) BDFDB.DOMUtils.setText(username, this.getNewName(user, username));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processStandardSidebarView (instance, wrapper, returnvalue) {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
processMessage (e) {
|
||||
let header = e.instance.props.childrenHeader;
|
||||
if (header && header.props && header.props.message && header.props.message.nick) {
|
||||
let newName = this.getNewName(header.props.message.author);
|
||||
if (newName) header.props.message = new BDFDB.DiscordObjects.Message(Object.assign({}, header.props.message, {nick: newName}));
|
||||
}
|
||||
}
|
||||
|
||||
processMessageContent (e) {
|
||||
if (BDFDB.ArrayUtils.is(e.instance.props.content) && BDFDB.DataUtils.get(this, "settings", "changeInMentions")) for (let ele of e.instance.props.content) {
|
||||
if (BDFDB.ReactUtils.isValidElement(ele) && ele.type && (ele.type.displayName || "").toLowerCase().indexOf("popout") > -1 && typeof ele.props.render == "function") {
|
||||
if (BDFDB.ReactUtils.getValue(ele, "props.children.type.displayName") == "Mention") {
|
||||
let newName = this.getNewName(BDFDB.LibraryModules.UserStore.getUser(ele.props.render().props.userId));
|
||||
if (newName) ele.props.children.props.children[0] = "@" + newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.instance.props.message.type != BDFDB.DiscordConstants.MessageTypes.DEFAULT && e.instance.props.message.nick && BDFDB.DataUtils.get(this, "settings", "changeInChatWindow")) {
|
||||
let newName = this.getNewName(e.instance.props.message.author);
|
||||
if (newName) {
|
||||
e.instance.props.message = new BDFDB.DiscordObjects.Message(Object.assign({}, e.instance.props.message, {nick: newName}));
|
||||
e.instance.props.children.props.message = e.instance.props.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getNewName (user, wrapper) {
|
||||
if (!user) return null;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), user.id) || {};
|
||||
if (!member.nick || user.id == BDFDB.UserUtils.me.id && !!settings.replaceOwn || user.bot && !settings.replaceBots) return null;
|
||||
let username = (BDFDB.BDUtils.isPluginEnabled("EditUsers") && BDFDB.DataUtils.load("EditUsers", "users", user.id) || {}).name || user.username;
|
||||
return settings.addNickname ? (settings.swapPositions ? (member.nick + " (" + username + ")") : (username + " (" + member.nick + ")")) : username;
|
||||
}
|
||||
|
||||
forceUpdateAll () {
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
BDFDB.MessageUtils.rerenderAll();
|
||||
}
|
||||
}
|
||||
|
||||
getNewName (info, wrapper) {
|
||||
if (!info) return null;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), info.id) || {};
|
||||
let EditUsersData = (BDFDB.BDUtils.isPluginEnabled("EditUsers") ? BDFDB.DataUtils.load("EditUsers", "users") : null, info.id) || {};
|
||||
if (this.reseting || !member.nick || info.id == BDFDB.UserUtils.me.id && !settings.replaceOwn || info.bot && !settings.replaceBots || this.ignoreElement(wrapper)) return EditUsersData.name || member.nick || info.username;
|
||||
var username = EditUsersData.name || info.username;
|
||||
return settings.addNickname ? (settings.swapPositions ? (member.nick + " (" + username + ")") : (username + " (" + member.nick + ")")) : username;
|
||||
}
|
||||
|
||||
ignoreElement (id, wrapper) {
|
||||
let allenabled = true, settings = BDFDB.ObjectUtils.filter(BDFDB.DataUtils.get(this, "settings"), key => {return this.defaults.settings[key].inner;}, true);
|
||||
for (let i in settings) if (!settings[i]) {
|
||||
allenabled = false;
|
||||
break;
|
||||
}
|
||||
if (allenabled) return false;
|
||||
|
||||
let key = null;
|
||||
if (!BDFDB.DOMUtils.containsClass(wrapper, BDFDB.disCN.mention) && BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup, wrapper)) key = "changeInChatWindow";
|
||||
else if (BDFDB.DOMUtils.containsClass(wrapper, BDFDB.disCN.mention)) key = "changeInMentions";
|
||||
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.voiceuser, wrapper)) key = "changeInVoiceChat";
|
||||
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.members, wrapper)) key = "changeInMemberList";
|
||||
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.typing, wrapper)) key = "changeInTyping";
|
||||
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.autocomplete, wrapper)) key = "changeInAutoComplete";
|
||||
|
||||
if (!key || settings[key]) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,89 +1,90 @@
|
|||
//META{"name":"RevealAllSpoilersOption","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/RevealAllSpoilersOption","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/RevealAllSpoilersOption/RevealAllSpoilersOption.plugin.js"}*//
|
||||
|
||||
class RevealAllSpoilersOption {
|
||||
getName () {return "RevealAllSpoilersOption";}
|
||||
var RevealAllSpoilersOption = (_ => {
|
||||
return class RevealAllSpoilersOption {
|
||||
getName () {return "RevealAllSpoilersOption";}
|
||||
|
||||
getVersion () {return "1.0.3";}
|
||||
getVersion () {return "1.0.4";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds an entry to the message contextmenu to reveal all spoilers within a messageblock.";}
|
||||
getDescription () {return "Adds an entry to the message contextmenu to reveal all spoilers within a messageblock.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onMessageContextMenu (e) {
|
||||
if (e.instance.props.message && e.instance.props.target) {
|
||||
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.message, e.instance.props.target);
|
||||
if (!messagediv || !messagediv.querySelector(BDFDB.dotCN.spoilerhidden)) return;
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
|
||||
children.splice(index > -1 ? index : children.length, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: "Reveal all Spoilers",
|
||||
hint: BDFDB.BDUtils.isPluginEnabled("MessageUtilities") ? BDFDB.BDUtils.getPlugin("MessageUtilities").getActiveShortcutString("__Reveal_Spoilers") : null,
|
||||
action: _ => {
|
||||
BDFDB.ContextMenuUtils.close(e.instance);
|
||||
this.revealAllSpoilers(messagediv);
|
||||
}
|
||||
})
|
||||
]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
revealAllSpoilers (target) {
|
||||
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.message, target);
|
||||
if (!messagediv) return;
|
||||
for (let spoiler of messagediv.querySelectorAll(BDFDB.dotCN.spoilerhidden)) spoiler.click();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onMessageContextMenu (e) {
|
||||
if (e.instance.props.message && e.instance.props.target) {
|
||||
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> [aria-disabled]," + BDFDB.dotCN.messagegroup + "> * > [aria-disabled]", e.instance.props.target);
|
||||
if (!messagediv || !messagediv.querySelector(BDFDB.dotCN.spoilerhidden)) return;
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
|
||||
const itemgroup = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: "Reveal all Spoilers",
|
||||
hint: BDFDB.BDUtils.isPluginEnabled("MessageUtilities") ? BDFDB.BDUtils.getPlugin("MessageUtilities").getActiveShortcutString("__Reveal_Spoilers") : null,
|
||||
action: _ => {
|
||||
BDFDB.ContextMenuUtils.close(e.instance);
|
||||
this.revealAllSpoilers(messagediv);
|
||||
}
|
||||
})
|
||||
]
|
||||
});
|
||||
if (index > -1) children.splice(index, 0, itemgroup);
|
||||
else children.push(itemgroup);
|
||||
}
|
||||
}
|
||||
|
||||
revealAllSpoilers (target) {
|
||||
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> [aria-disabled]," + BDFDB.dotCN.messagegroup + "> * > [aria-disabled]", target);
|
||||
if (!messagediv) return;
|
||||
for (let spoiler of messagediv.querySelectorAll(BDFDB.dotCN.spoilerhidden)) spoiler.click();
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,183 +1,201 @@
|
|||
//META{"name":"ShowImageDetails","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowImageDetails","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ShowImageDetails/ShowImageDetails.plugin.js"}*//
|
||||
|
||||
class ShowImageDetails {
|
||||
getName () {return "ShowImageDetails";}
|
||||
var ShowImageDetails = (_ => {
|
||||
return class ShowImageDetails {
|
||||
getName () {return "ShowImageDetails";}
|
||||
|
||||
getVersion () {return "1.1.8";}
|
||||
getVersion () {return "1.1.9";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Display the name, size and dimensions of uploaded images in the chat as an header or as a tooltip.";}
|
||||
getDescription () {return "Display the name, size and dimensions of uploaded images in the chat as an header or as a tooltip.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
LazyImage: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCN._showimagedetailsdetails} {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
${BDFDB.dotCNS.spoilerhidden + BDFDB.dotCN._showimagedetailsdetails} {
|
||||
visibility: hidden;
|
||||
max-width: 1px;
|
||||
}
|
||||
`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showOnHover: {value:false, description:"Show the details as Tooltip instead:"}
|
||||
},
|
||||
amounts: {
|
||||
hoverDelay: {value:0, min:0, description:"Tooltip delay in millisec:"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let amounts = BDFDB.DataUtils.get(this, "amounts");
|
||||
let settingspanel, settingsitems = [];
|
||||
|
||||
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
|
||||
for (let key in amounts) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "TextInput",
|
||||
childProps: {
|
||||
type: "number"
|
||||
},
|
||||
plugin: this,
|
||||
keys: ["amounts", key],
|
||||
label: this.defaults.amounts[key].description,
|
||||
basis: "50%",
|
||||
min: this.defaults.amounts[key].min,
|
||||
max: this.defaults.amounts[key].max,
|
||||
value: amounts[key]
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
}
|
||||
|
||||
processLazyImage (e) {
|
||||
if (typeof e.returnvalue.props.children == "function" && e.instance.props.original && e.instance.props.src.indexOf("https://media.discordapp.net/attachments") == 0) {
|
||||
let attachment = BDFDB.ReactUtils.findValue(e.instance, "attachment", {up:true});
|
||||
if (!attachment) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let amounts = BDFDB.DataUtils.get(this, "amounts");
|
||||
let renderChildren = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
if (settings.showOnHover) return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: `${attachment.filename}\n${BDFDB.NumberUtils.formatBytes(attachment.size)}\n${attachment.width}x${attachment.height}px`,
|
||||
tooltipConfig: {
|
||||
type: "right",
|
||||
delay: amounts.hoverDelay
|
||||
},
|
||||
children: renderedChildren
|
||||
});
|
||||
else return [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
className: BDFDB.disCN._showimagedetailsdetails,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {
|
||||
title: e.instance.props.original,
|
||||
href: e.instance.props.original,
|
||||
children: attachment.filename
|
||||
})
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
|
||||
color: BDFDB.LibraryComponents.TextElement.Colors.PRIMARY,
|
||||
children: BDFDB.NumberUtils.formatBytes(attachment.size)
|
||||
})
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
|
||||
color: BDFDB.LibraryComponents.TextElement.Colors.PRIMARY,
|
||||
children: `${attachment.width}x${attachment.height}px`
|
||||
})
|
||||
})
|
||||
]
|
||||
}),
|
||||
renderedChildren
|
||||
];
|
||||
this.patchedModules = {
|
||||
before: {
|
||||
LazyImage: "render"
|
||||
},
|
||||
after: {
|
||||
LazyImage: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCN._showimagedetailsdetailsadded},
|
||||
${BDFDB.dotCN._showimagedetailsdetailsadded}:hover {
|
||||
text-decoration: none;
|
||||
width: unset !important;
|
||||
}
|
||||
${BDFDB.dotCN._showimagedetailsdetails} {
|
||||
margin: 5px 0;
|
||||
}
|
||||
${BDFDB.dotCNS.spoilerhidden + BDFDB.dotCN._showimagedetailsdetails} {
|
||||
visibility: hidden;
|
||||
max-width: 1px;
|
||||
}
|
||||
`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showOnHover: {value:false, description:"Show the details as Tooltip instead:"}
|
||||
},
|
||||
amounts: {
|
||||
hoverDelay: {value:0, min:0, description:"Tooltip delay in millisec:"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let amounts = BDFDB.DataUtils.get(this, "amounts");
|
||||
let settingspanel, settingsitems = [];
|
||||
|
||||
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||
className: BDFDB.disCN.marginbottom8
|
||||
}));
|
||||
|
||||
for (let key in amounts) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "TextInput",
|
||||
childProps: {
|
||||
type: "number"
|
||||
},
|
||||
plugin: this,
|
||||
keys: ["amounts", key],
|
||||
label: this.defaults.amounts[key].description,
|
||||
basis: "50%",
|
||||
min: this.defaults.amounts[key].min,
|
||||
max: this.defaults.amounts[key].max,
|
||||
value: amounts[key]
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
}
|
||||
|
||||
processLazyImage (e) {
|
||||
if (e.instance.props.original && e.instance.props.src.indexOf("https://media.discordapp.net/attachments") == 0) {
|
||||
if (!e.returnvalue) e.instance.props.className = BDFDB.DOMUtils.formatClassName(e.instance.props.className, BDFDB.disCN._showimagedetailsdetailsadded);
|
||||
else if (typeof e.returnvalue.props.children == "function") {
|
||||
let attachment = BDFDB.ReactUtils.findValue(e.instance, "attachment", {up:true});
|
||||
if (!attachment) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let amounts = BDFDB.DataUtils.get(this, "amounts");
|
||||
let renderChildren = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
if (settings.showOnHover) return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: `${attachment.filename}\n${BDFDB.NumberUtils.formatBytes(attachment.size)}\n${attachment.width}x${attachment.height}px`,
|
||||
tooltipConfig: {
|
||||
type: "right",
|
||||
delay: amounts.hoverDelay
|
||||
},
|
||||
children: renderedChildren
|
||||
});
|
||||
else return [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||
className: BDFDB.disCN._showimagedetailsdetails,
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {
|
||||
title: e.instance.props.original,
|
||||
href: e.instance.props.original,
|
||||
children: attachment.filename,
|
||||
onClick: event => {
|
||||
BDFDB.ListenerUtils.stopEvent(event);
|
||||
BDFDB.DiscordUtils.openLink(e.instance.props.original);
|
||||
}
|
||||
})
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
|
||||
color: BDFDB.LibraryComponents.TextElement.Colors.PRIMARY,
|
||||
children: BDFDB.NumberUtils.formatBytes(attachment.size)
|
||||
})
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
|
||||
color: BDFDB.LibraryComponents.TextElement.Colors.PRIMARY,
|
||||
children: `${attachment.width}x${attachment.height}px`
|
||||
})
|
||||
})
|
||||
]
|
||||
}),
|
||||
renderedChildren
|
||||
];
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -1,215 +1,217 @@
|
|||
//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"}*//
|
||||
|
||||
class TopRoleEverywhere {
|
||||
getName () {return "TopRoleEverywhere";}
|
||||
var TopRoleEverywhere = (_ => {
|
||||
return class TopRoleEverywhere {
|
||||
getName () {return "TopRoleEverywhere";}
|
||||
|
||||
getVersion () {return "2.9.5";}
|
||||
getVersion () {return "2.9.6";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getDescription () {return "Adds the highest role of a user as a tag.";}
|
||||
getDescription () {return "Adds the highest role of a user as a tag.";}
|
||||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Compact", "Fixed roles in role style for compact mode"]],
|
||||
"improved":[["Coloress", "If you disabled the plugin for colorless roles and the highest role of a user is a role without color, then the plugin will try to find the next highest role with a color"], ["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Message Update","Fixed the plugin for the new Message Update"]],
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MemberListItem: "render",
|
||||
MessageUsername: "render"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCNS.member + BDFDB.dotCN.namecontainercontent} {
|
||||
overflow: visible;
|
||||
}
|
||||
.TRE-tag {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.TRE-tag.TRE-roletag {
|
||||
margin: 0 0 0 0.3rem;
|
||||
}
|
||||
${BDFDB.dotCN.messageheadercompact} .TRE-roletag {
|
||||
text-indent: 0;
|
||||
}
|
||||
.TRE-tag.TRE-bottag {
|
||||
margin-left: 0.3rem;
|
||||
}
|
||||
.TRE-tag.TRE-listtag {
|
||||
max-width: 50%;
|
||||
}
|
||||
.TRE-roletag {
|
||||
display: inline-flex;
|
||||
}
|
||||
.TRE-roletag ${BDFDB.dotCN.userpopoutrolecircle} {
|
||||
flex: 0 0 auto;
|
||||
}`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showInChat: {value:true, inner:true, description:"Chat Window"},
|
||||
showInMemberList: {value:true, inner:true, description:"Member List"},
|
||||
useOtherStyle: {value:false, inner:false, description:"Use BotTag Style instead of the Role Style."},
|
||||
useBlackFont: {value:false, inner:false, description:"Instead of darkening the color for BotTag Style on bright colors use black font."},
|
||||
includeColorless: {value:false, inner:false, description:"Include colorless roles."},
|
||||
showOwnerRole: {value:false, inner:false, description:`Display Role Tag of Serverowner as "${BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER}".`},
|
||||
disableForBots: {value:false, inner:false, description:"Disable Role Tag for Bots."},
|
||||
addUserID: {value:false, inner:false, description:"Add the UserID as a Tag to the Chat Window."}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "Add Role Tags in:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
}
|
||||
|
||||
processMemberListItem (e) {
|
||||
if (e.instance.props.user && BDFDB.DataUtils.get(this, "settings", "showInMemberList")) {
|
||||
this.injectRoleTag(BDFDB.ReactUtils.getValue(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, "list", BDFDB.disCN.bottagmember);
|
||||
}
|
||||
}
|
||||
|
||||
processMessageUsername (e) {
|
||||
let user = BDFDB.ReactUtils.getValue(e.instance, "props.message.author");
|
||||
if (user && typeof e.returnvalue.props.children == "function" && BDFDB.DataUtils.get(this, "settings", "showInChat")) {
|
||||
let renderChildren = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let renderedChildren = renderChildren(...args);
|
||||
this.injectRoleTag(renderedChildren.props.children, user, "chat", e.instance.props.isCompact ? BDFDB.disCN.bottagmessagecompact : BDFDB.disCN.bottagmessagecozy);
|
||||
return renderedChildren;
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
MemberListItem: "render",
|
||||
MessageHeader: "default"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
injectRoleTag (children, user, type, tagclass) {
|
||||
if (!BDFDB.ArrayUtils.is(children) || !user) return;
|
||||
let guild = BDFDB.LibraryModules.GuildStore.getGuild(BDFDB.LibraryModules.LastGuildStore.getGuildId());
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (!guild || user.bot && settings.disableForBots) return;
|
||||
let role = BDFDB.LibraryModules.PermissionRoleUtils.getHighestRole(guild, user.id);
|
||||
if (role && !role.colorString && !settings.includeColorless) {
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(guild.id, user.id);
|
||||
if (member) for (let sortedRole of BDFDB.ArrayUtils.keySort(member.roles.map(roleId => guild.getRole(roleId)), "position").reverse()) if (sortedRole.colorString) {
|
||||
role = sortedRole;
|
||||
break;
|
||||
initConstructor () {
|
||||
this.css = `
|
||||
${BDFDB.dotCNS.member + BDFDB.dotCN.namecontainercontent} {
|
||||
overflow: visible;
|
||||
}
|
||||
${BDFDB.dotCN._toproleseverywheretag} {
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
${BDFDB.dotCN._toproleseverywheremembertag} {
|
||||
max-width: 50%;
|
||||
}
|
||||
${BDFDB.dotCN._toproleseverywherebadgestyle} {
|
||||
margin-left: 0.3rem;
|
||||
}
|
||||
${BDFDB.dotCNS.messageheadercompact + BDFDB.dotCN._toproleseverywherebadgestyle} {
|
||||
margin-left: 0.1rem;
|
||||
margin-right: 0.2rem;
|
||||
}
|
||||
${BDFDB.dotCN._toproleseverywhererolestyle} {
|
||||
display: inline-flex;
|
||||
margin: 0 0 0 0.3rem;
|
||||
}
|
||||
${BDFDB.dotCNS._toproleseverywhererolestyle + BDFDB.dotCN.userpopoutrolecircle} {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
${BDFDB.dotCNS.messageheadercompact + BDFDB.dotCN._toproleseverywhererolestyle} {
|
||||
text-indent: 0;
|
||||
}`;
|
||||
|
||||
this.defaults = {
|
||||
settings: {
|
||||
showInChat: {value:true, inner:true, description:"Chat Window"},
|
||||
showInMemberList: {value:true, inner:true, description:"Member List"},
|
||||
useOtherStyle: {value:false, inner:false, description:"Use BotTag Style instead of the Role Style."},
|
||||
useBlackFont: {value:false, inner:false, description:"Instead of darkening the color for BotTag Style on bright colors use black font."},
|
||||
includeColorless: {value:false, inner:false, description:"Include colorless roles."},
|
||||
showOwnerRole: {value:false, inner:false, description:`Display Role Tag of Serverowner as "${BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER}".`},
|
||||
disableForBots: {value:false, inner:false, description:"Disable Role Tag for Bots."},
|
||||
addUserID: {value:false, inner:false, description:"Add the UserID as a Tag to the Chat Window."}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let settingspanel, settingsitems = [], inneritems = [];
|
||||
|
||||
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
className: BDFDB.disCN.marginbottom8,
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["settings", key],
|
||||
label: this.defaults.settings[key].description,
|
||||
value: settings[key]
|
||||
}));
|
||||
|
||||
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
||||
title: "Add Role Tags in:",
|
||||
first: settingsitems.length == 0,
|
||||
last: true,
|
||||
children: inneritems
|
||||
}));
|
||||
|
||||
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
||||
}
|
||||
|
||||
//legacy
|
||||
load () {}
|
||||
|
||||
start () {
|
||||
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
||||
if (libraryScript) libraryScript.remove();
|
||||
libraryScript = document.createElement("script");
|
||||
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
||||
libraryScript.setAttribute("type", "text/javascript");
|
||||
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
||||
libraryScript.setAttribute("date", performance.now());
|
||||
libraryScript.addEventListener("load", _ => {this.initialize();});
|
||||
document.head.appendChild(libraryScript);
|
||||
}
|
||||
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
||||
this.startTimeout = setTimeout(_ => {
|
||||
try {return this.initialize();}
|
||||
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
initialize () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
this.forceUpdateAll();
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
if (role && (role.colorString || settings.includeColorless)) children.push(this.createRoleTag(settings, Object.assign({}, role, {
|
||||
name: settings.showOwnerRole && user.id == guild.ownerId ? BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER : role.name
|
||||
}),type, tagclass));
|
||||
if (type == "chat" && settings.addUserID) children.push(this.createRoleTag(settings, {
|
||||
name: user.id
|
||||
}, type, tagclass));
|
||||
}
|
||||
|
||||
createRoleTag (settings, role, type, tagclass) {
|
||||
let tagcolor = BDFDB.ColorUtils.convert(role.colorString || BDFDB.DiscordConstants.Colors.PRIMARY_DARK_500, "RGB")
|
||||
let isbright = role.colorString && BDFDB.ColorUtils.isBright(tagcolor);
|
||||
tagcolor = isbright ? (settings.useBlackFont ? tagcolor : BDFDB.ColorUtils.change(tagcolor, -0.3)) : tagcolor;
|
||||
if (settings.useOtherStyle) {
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BotTag, {
|
||||
className: `${tagclass} TRE-tag TRE-bottag TRE-${type}tag`,
|
||||
tag: role.name,
|
||||
style: {
|
||||
backgroundColor: tagcolor,
|
||||
color: isbright && settings.useBlackFont ? "black" : null
|
||||
},
|
||||
|
||||
|
||||
// begin of own functions
|
||||
|
||||
onSettingsClosed () {
|
||||
if (this.SettingsUpdated) {
|
||||
delete this.SettingsUpdated;
|
||||
this.forceUpdateAll();
|
||||
}
|
||||
}
|
||||
|
||||
processMemberListItem (e) {
|
||||
if (e.instance.props.user && BDFDB.DataUtils.get(this, "settings", "showInMemberList")) {
|
||||
this.injectRoleTag(BDFDB.ReactUtils.getValue(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, "member", BDFDB.disCN.bottagmember);
|
||||
}
|
||||
}
|
||||
|
||||
processMessageHeader (e) {
|
||||
if (e.instance.props.message && BDFDB.DataUtils.get(this, "settings", "showInChat")) {
|
||||
this.injectRoleTag(BDFDB.ReactUtils.getValue(e.returnvalue, "props.children.2.props.children"), e.instance.props.message.author, "chat", e.instance.props.compact ? BDFDB.disCN.messagebottagcompact : BDFDB.disCN.messagebottagcozy);
|
||||
}
|
||||
}
|
||||
|
||||
injectRoleTag (children, user, type, tagclass) {
|
||||
if (!BDFDB.ArrayUtils.is(children) || !user) return;
|
||||
let guild = BDFDB.LibraryModules.GuildStore.getGuild(BDFDB.LibraryModules.LastGuildStore.getGuildId());
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
if (!guild || user.bot && settings.disableForBots) return;
|
||||
let role = BDFDB.LibraryModules.PermissionRoleUtils.getHighestRole(guild, user.id);
|
||||
if (role && !role.colorString && !settings.includeColorless) {
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(guild.id, user.id);
|
||||
if (member) for (let sortedRole of BDFDB.ArrayUtils.keySort(member.roles.map(roleId => guild.getRole(roleId)), "position").reverse()) if (sortedRole.colorString) {
|
||||
role = sortedRole;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (role && (role.colorString || settings.includeColorless)) children.push(this.createRoleTag(settings, Object.assign({}, role, {
|
||||
name: settings.showOwnerRole && user.id == guild.ownerId ? BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER : role.name
|
||||
}), type, tagclass));
|
||||
if (type == "chat" && settings.addUserID) children.push(this.createRoleTag(settings, {
|
||||
name: user.id
|
||||
}, type, tagclass));
|
||||
}
|
||||
|
||||
createRoleTag (settings, role, type, tagclass) {
|
||||
if (settings.useOtherStyle) {
|
||||
let tagColor = BDFDB.ColorUtils.convert(role.colorString || BDFDB.DiscordConstants.Colors.PRIMARY_DARK_500, "RGB")
|
||||
let isBright = role.colorString && BDFDB.ColorUtils.isBright(tagColor);
|
||||
tagColor = isBright ? (settings.useBlackFont ? tagColor : BDFDB.ColorUtils.change(tagColor, -0.3)) : tagColor;
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BotTag, {
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._toproleseverywheretag, BDFDB.disCN[`_toproleseverywhere${type}tag`], BDFDB.disCN._toproleseverywherebadgestyle, tagclass),
|
||||
tag: role.name,
|
||||
style: {
|
||||
backgroundColor: tagColor,
|
||||
color: isBright && settings.useBlackFont ? "black" : null
|
||||
},
|
||||
onContextMenu: role.id ? e => {this.openRoleContextMenu(e, role);} : null
|
||||
});
|
||||
}
|
||||
else return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MemberRole, {
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._toproleseverywheretag, BDFDB.disCN[`_toproleseverywhere${type}tag`], BDFDB.disCN._toproleseverywhererolestyle),
|
||||
role: role,
|
||||
onContextMenu: role.id ? e => {this.openRoleContextMenu(e, role);} : null
|
||||
});
|
||||
}
|
||||
else return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MemberRole, {
|
||||
className: `TRE-tag TRE-roletag TRE-${type}tag`,
|
||||
role: role,
|
||||
onContextMenu: role.id ? e => {this.openRoleContextMenu(e, role);} : null
|
||||
});
|
||||
}
|
||||
|
||||
openRoleContextMenu (e, role) {
|
||||
BDFDB.LibraryModules.ContextMenuUtils.openContextMenu(e, function (e) {
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.ModuleUtils.findByName("GuildRoleContextMenu"), Object.assign({}, e, {roleId: role.id}));
|
||||
});
|
||||
}
|
||||
|
||||
openRoleContextMenu (e, role) {
|
||||
BDFDB.LibraryModules.ContextMenuUtils.openContextMenu(e, function (e) {
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.ModuleUtils.findByName("GuildRoleContextMenu"), Object.assign({}, e, {
|
||||
roleId: role.id
|
||||
}));
|
||||
});
|
||||
forceUpdateAll () {
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
BDFDB.MessageUtils.rerenderAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue