This commit is contained in:
Mirco Wittrien 2021-05-26 23:00:39 +02:00
parent 3026fc7485
commit f6c0229296
4 changed files with 65 additions and 46 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB * @name BDFDB
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.6.5 * @version 1.6.6
* @description Required Library for DevilBro's Plugins * @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -19,10 +19,20 @@ module.exports = (_ => {
"info": { "info": {
"name": "BDFDB", "name": "BDFDB",
"author": "DevilBro", "author": "DevilBro",
"version": "1.6.5", "version": "1.6.6",
"description": "Required Library for DevilBro's Plugins" "description": "Required Library for DevilBro's Plugins"
}, },
"rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js` "rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js`,
"changeLog": {
"improved": {
"Patron Badges": "All Badges will now say that they are from by BDFDB Patreon, even the T3 Custom Badges",
"Toasts": "You can now hover Toasts to stop them from disappearing"
},
"fixed": {
"Color Picker": "Copy Pasting a 6-digit HEX Color, when the alpha channel is enabled will autocomplete it to a 8-digit HEXA Color",
"Tooltips": "Fixed some rendering Issues with Tooltips"
}
}
}; };
const DiscordObjects = {}; const DiscordObjects = {};
@ -3177,29 +3187,31 @@ module.exports = (_ => {
if (conv == "RGBCOMP") { if (conv == "RGBCOMP") {
switch (type) { switch (type) {
case "RGBCOMP": case "RGBCOMP":
if (color.length == 3) return processRGB(color); var rgbComp = [].concat(color);
else if (color.length == 4) { if (rgbComp.length == 3) return processRGB(rgbComp);
let a = processA(color.pop()); else if (rgbComp.length == 4) {
return processRGB(color).concat(a); let a = processA(rgbComp.pop());
return processRGB(rgbComp).concat(a);
} }
break; break;
case "RGB": case "RGB":
return processRGB(color.replace(/\s/g, "").slice(4, -1).split(",")); return processRGB(color.replace(/\s/g, "").slice(4, -1).split(","));
case "RGBA": case "RGBA":
let comp = color.replace(/\s/g, "").slice(5, -1).split(","); var rgbComp = color.replace(/\s/g, "").slice(5, -1).split(",");
let a = processA(comp.pop()); var a = processA(rgbComp.pop());
return processRGB(comp).concat(a); return processRGB(rgbComp).concat(a);
case "HSLCOMP": case "HSLCOMP":
if (color.length == 3) return BDFDB.ColorUtils.convert(`hsl(${processHSL(color).join(",")})`, "RGBCOMP"); var hslComp = [].concat(color);
else if (color.length == 4) { if (hslComp.length == 3) return BDFDB.ColorUtils.convert(`hsl(${processHSL(hslComp).join(",")})`, "RGBCOMP");
let a = processA(color.pop()); else if (hslComp.length == 4) {
return BDFDB.ColorUtils.convert(`hsl(${processHSL(color).join(",")})`, "RGBCOMP").concat(a); let a = processA(hslComp.pop());
return BDFDB.ColorUtils.convert(`hsl(${processHSL(hslComp).join(",")})`, "RGBCOMP").concat(a);
} }
break; break;
case "HSL": case "HSL":
var hslcomp = processHSL(color.replace(/\s/g, "").slice(4, -1).split(",")); var hslComp = processHSL(color.replace(/\s/g, "").slice(4, -1).split(","));
var r, g, b, m, c, x, p, q; var r, g, b, m, c, x, p, q;
var h = hslcomp[0] / 360, l = parseInt(hslcomp[1]) / 100, s = parseInt(hslcomp[2]) / 100; m = Math.floor(h * 6); c = h * 6 - m; x = s * (1 - l); p = s * (1 - c * l); q = s * (1 - (1 - c) * l); var h = hslComp[0] / 360, l = parseInt(hslComp[1]) / 100, s = parseInt(hslComp[2]) / 100; m = Math.floor(h * 6); c = h * 6 - m; x = s * (1 - l); p = s * (1 - c * l); q = s * (1 - (1 - c) * l);
switch (m % 6) { switch (m % 6) {
case 0: r = s, g = q, b = x; break; case 0: r = s, g = q, b = x; break;
case 1: r = p, g = s, b = x; break; case 1: r = p, g = s, b = x; break;
@ -3210,8 +3222,8 @@ module.exports = (_ => {
} }
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]; return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
case "HSLA": case "HSLA":
var hslcomp = color.replace(/\s/g, "").slice(5, -1).split(","); var hslComp = color.replace(/\s/g, "").slice(5, -1).split(",");
return BDFDB.ColorUtils.convert(`hsl(${hslcomp.slice(0, 3).join(",")})`, "RGBCOMP").concat(processA(hslcomp.pop())); return BDFDB.ColorUtils.convert(`hsl(${hslComp.slice(0, 3).join(",")})`, "RGBCOMP").concat(processA(hslComp.pop()));
case "HEX": case "HEX":
var hex = /^#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$|^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color); var hex = /^#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$|^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color);
return [parseInt(hex[1] + hex[1] || hex[4], 16), parseInt(hex[2] + hex[2] || hex[5], 16), parseInt(hex[3] + hex[3] || hex[6], 16)]; return [parseInt(hex[1] + hex[1] || hex[4], 16), parseInt(hex[2] + hex[2] || hex[5], 16), parseInt(hex[3] + hex[3] || hex[6], 16)];
@ -3300,25 +3312,25 @@ module.exports = (_ => {
return newcolor; return newcolor;
} }
else { else {
let comp = BDFDB.ColorUtils.convert(color, "RGBCOMP"); let rgbComp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) { if (rgbComp) {
a = a.toString(); a = a.toString();
a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, "")); a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));
a = isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a; a = isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a;
comp[3] = a; rgbComp[3] = a;
conv = (conv || BDFDB.ColorUtils.getType(color)).toUpperCase(); conv = (conv || BDFDB.ColorUtils.getType(color)).toUpperCase();
conv = conv == "RGB" || conv == "HSL" || conv == "HEX" ? conv + "A" : conv; conv = conv == "RGB" || conv == "HSL" || conv == "HEX" ? conv + "A" : conv;
return BDFDB.ColorUtils.convert(comp, conv); return BDFDB.ColorUtils.convert(rgbComp, conv);
} }
} }
return null; return null;
}; };
BDFDB.ColorUtils.getAlpha = function (color) { BDFDB.ColorUtils.getAlpha = function (color) {
let comp = BDFDB.ColorUtils.convert(color, "RGBCOMP"); let rgbComp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) { if (rgbComp) {
if (comp.length == 3) return 1; if (rgbComp.length == 3) return 1;
else if (comp.length == 4) { else if (rgbComp.length == 4) {
let a = comp[3].toString(); let a = rgbComp[3].toString();
a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, "")); a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));
return isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a; return isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a;
} }
@ -3334,21 +3346,22 @@ module.exports = (_ => {
return newColor; return newColor;
} }
else { else {
let comp = BDFDB.ColorUtils.convert(color, "RGBCOMP"); let rgbComp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) { if (rgbComp) {
let a = BDFDB.ColorUtils.getAlpha(rgbComp);
if (parseInt(value) !== value) { if (parseInt(value) !== value) {
value = value.toString(); value = value.toString();
value = (value.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(value.replace(/[^0-9\.\-]/g, "")); value = (value.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(value.replace(/[^0-9\.\-]/g, ""));
value = isNaN(value) ? 0 : value; value = isNaN(value) ? 0 : value;
return BDFDB.ColorUtils.convert([].concat(comp).map(c => { return BDFDB.ColorUtils.convert([].concat(rgbComp).slice(0, 3).map(c => {
c = Math.round(c * (1 + value)); c = Math.round(c * (1 + value));
return c > 255 ? 255 : c < 0 ? 0 : c; return c > 255 ? 255 : c < 0 ? 0 : c;
}), conv || BDFDB.ColorUtils.getType(color)); }).concat(a), conv || BDFDB.ColorUtils.getType(color));
} }
else return BDFDB.ColorUtils.convert([].concat(comp).map(c => { else return BDFDB.ColorUtils.convert([].concat(rgbComp).slice(0, 3).map(c => {
c = Math.round(c + value); c = Math.round(c + value);
return c > 255 ? 255 : c < 0 ? 0 : c; return c > 255 ? 255 : c < 0 ? 0 : c;
}), conv || BDFDB.ColorUtils.getType(color)); }).concat(a), conv || BDFDB.ColorUtils.getType(color));
} }
} }
} }
@ -5160,6 +5173,9 @@ module.exports = (_ => {
let a = BDFDB.ColorUtils.getAlpha(selectedColor); let a = BDFDB.ColorUtils.getAlpha(selectedColor);
a = a == null ? 1 : a; a = a == null ? 1 : a;
let hexColor = BDFDB.ColorUtils.convert(selectedColor, this.props.alpha ? "HEXA" : "HEX");
let hexLength = hexColor.length;
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.PopoutFocusLock, { return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.PopoutFocusLock, {
className: BDFDB.disCNS.colorpickerwrapper + BDFDB.disCN.colorpicker, className: BDFDB.disCNS.colorpickerwrapper + BDFDB.disCN.colorpicker,
children: [ children: [
@ -5392,9 +5408,12 @@ module.exports = (_ => {
className: BDFDB.disCNS.colorpickerhexinput + BDFDB.disCN.margintop8, className: BDFDB.disCNS.colorpickerhexinput + BDFDB.disCN.margintop8,
maxLength: this.props.alpha ? 9 : 7, maxLength: this.props.alpha ? 9 : 7,
valuePrefix: "#", valuePrefix: "#",
value: BDFDB.ColorUtils.convert(selectedColor, this.props.alpha ? "HEXA" : "HEX"), value: hexColor,
autoFocus: true, autoFocus: true,
onChange: value => { onChange: value => {
const oldLength = hexLength;
hexLength = (value || "").length;
if (this.props.alpha && (oldLength > 8 || oldLength < 6) && hexLength == 7) value += "FF";
if (hexRegex.test(value)) this.handleColorChange(value); if (hexRegex.test(value)) this.handleColorChange(value);
}, },
inputChildren: this.props.gradient && BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TooltipContainer, { inputChildren: this.props.gradient && BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TooltipContainer, {
@ -5611,7 +5630,7 @@ module.exports = (_ => {
} }
renderInfoButton(text, style) { renderInfoButton(text, style) {
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TooltipContainer, { return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TooltipContainer, {
text: text, text: [text].flat(10).filter(n => n).map(n => BDFDB.ReactUtils.createElement("div", {children: n})),
tooltipConfig: { tooltipConfig: {
type: "bottom", type: "bottom",
zIndex: 1009, zIndex: 1009,
@ -5672,7 +5691,7 @@ module.exports = (_ => {
"$agoAmount will be replaced with ('Today', 'Yesterday', 'x days/weeks/months ago')", "$agoAmount will be replaced with ('Today', 'Yesterday', 'x days/weeks/months ago')",
"$agoDays will be replaced with ('Today', 'Yesterday', 'x days ago')", "$agoDays will be replaced with ('Today', 'Yesterday', 'x days ago')",
"$agoDate will be replaced with ('Today', 'Yesterday', $date)" "$agoDate will be replaced with ('Today', 'Yesterday', $date)"
].join("\n"), {marginRight: 6}), ], {marginRight: 6}),
this.renderFormatButton({ this.renderFormatButton({
name: BDFDB.LanguageUtils.LanguageStrings.DATE, name: BDFDB.LanguageUtils.LanguageStrings.DATE,
svgName: InternalComponents.LibraryComponents.SvgIcon.Names.CALENDAR, svgName: InternalComponents.LibraryComponents.SvgIcon.Names.CALENDAR,
@ -5687,7 +5706,7 @@ module.exports = (_ => {
"$yyyy will be replaced with the Year (4-Digit)", "$yyyy will be replaced with the Year (4-Digit)",
"$month will be replaced with the Month Name", "$month will be replaced with the Month Name",
"$monthS will be replaced with the Month Name (Short Form)", "$monthS will be replaced with the Month Name (Short Form)",
].join("\n"), ],
onChange: value => { onChange: value => {
this.props.dateString = value; this.props.dateString = value;
this.handleChange.apply(this, []); this.handleChange.apply(this, []);
@ -5708,7 +5727,7 @@ module.exports = (_ => {
"$ss will be replaced with the Seconds (Forced Zeros)", "$ss will be replaced with the Seconds (Forced Zeros)",
"$u will be replaced with the Milliseconds", "$u will be replaced with the Milliseconds",
"$uu will be replaced with the Milliseconds (Forced Zeros)" "$uu will be replaced with the Milliseconds (Forced Zeros)"
].join("\n"), ],
onChange: value => { onChange: value => {
this.props.timeString = value; this.props.timeString = value;
this.handleChange.apply(this, []); this.handleChange.apply(this, []);

View File

@ -1303,7 +1303,7 @@
"UserBadges": {"props": ["profileBadgeStaff", "profileBadgePremium"]}, "UserBadges": {"props": ["profileBadgeStaff", "profileBadgePremium"]},
"UserInfo": {"props": ["userInfo", "discordTag"]}, "UserInfo": {"props": ["userInfo", "discordTag"]},
"UserPopout": {"props": ["headerNormal", "profileBadges"]}, "UserPopout": {"props": ["headerNormal", "profileBadges"]},
"UserPopoutWrapper": {"props": ["userPopout", "headerPlaying"]}, "UserPopoutWrapper": {"props": ["userPopout", "rolesList"]},
"UserProfile": {"props": ["topSectionNormal", "tabBarContainer"]}, "UserProfile": {"props": ["topSectionNormal", "tabBarContainer"]},
"UserSettingsAppearancePreview": {"props": ["preview", "firstMessage"]}, "UserSettingsAppearancePreview": {"props": ["preview", "firstMessage"]},
"UserSummaryItem": {"props": ["avatarContainerMasked", "container"]}, "UserSummaryItem": {"props": ["avatarContainerMasked", "container"]},

View File

@ -290,7 +290,7 @@ module.exports = (_ => {
let channelName = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "AutocompleteRowHeading"}); let channelName = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "AutocompleteRowHeading"});
if (channelName) this.changeChannelColor(channelName, e.instance.props.channel.id); if (channelName) this.changeChannelColor(channelName, e.instance.props.channel.id);
let channelIcon = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.autocompleteicon]]}); let channelIcon = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.autocompleteicon]]});
if (channelIcon) this.changeChannelIconColor(channelIcon, e.instance.props.channel.id, {alpha: 0.6}); if (channelIcon) this.changeChannelIconColor(channelIcon, e.instance.props.channel.id);
if (e.instance.props.category) { if (e.instance.props.category) {
let categoryName = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "AutocompleteRowContentSecondary"}); let categoryName = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "AutocompleteRowContentSecondary"});
if (categoryName) this.changeChannelColor(categoryName, e.instance.props.category.id); if (categoryName) this.changeChannelColor(categoryName, e.instance.props.category.id);
@ -336,7 +336,7 @@ module.exports = (_ => {
let icon = BDFDB.ReactUtils.createElement(children[index].props.icon, { let icon = BDFDB.ReactUtils.createElement(children[index].props.icon, {
className: BDFDB.disCN.channelheadericon className: BDFDB.disCN.channelheadericon
}); });
this.changeChannelIconColor(icon, channel.id, {alpha: 0.6}); this.changeChannelIconColor(icon, channel.id);
children[index] = BDFDB.ReactUtils.createElement("div", { children[index] = BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.channelheadericonwrapper, className: BDFDB.disCN.channelheadericonwrapper,
children: icon children: icon
@ -372,7 +372,7 @@ module.exports = (_ => {
this.changeChannelColor(BDFDB.ArrayUtils.is(name) ? name.find(c => c.type == "strong") || name[0] : name, channelId, modify); this.changeChannelColor(BDFDB.ArrayUtils.is(name) ? name.find(c => c.type == "strong") || name[0] : name, channelId, modify);
} }
let icon = iconClass && BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", iconClass]]}); let icon = iconClass && BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", iconClass]]});
if (icon) this.changeChannelIconColor(icon, channelId, Object.assign({alpha: 0.6}, modify)); if (icon) this.changeChannelIconColor(icon, channelId, modify);
} }
let categoryId = (BDFDB.LibraryModules.ChannelStore.getChannel(channelId) || {}).parent_id; let categoryId = (BDFDB.LibraryModules.ChannelStore.getChannel(channelId) || {}).parent_id;
if (categoryId && changedChannels[categoryId]) { if (categoryId && changedChannels[categoryId]) {
@ -406,7 +406,7 @@ module.exports = (_ => {
let childrenRender = returnValue.props.children; let childrenRender = returnValue.props.children;
returnValue.props.children = (...args2) => { returnValue.props.children = (...args2) => {
let renderedChildren = childrenRender(...args2); let renderedChildren = childrenRender(...args2);
this.changeChannelIconColor(renderedChildren.props.children, e.instance.props.channel.id, Object.assign({alpha: 0.6}, modify)); this.changeChannelIconColor(renderedChildren.props.children, e.instance.props.channel.id, modify);
return renderedChildren; return renderedChildren;
}; };
} }
@ -453,7 +453,7 @@ module.exports = (_ => {
let channelName = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.quickswitchresultmatch]]}); let channelName = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.quickswitchresultmatch]]});
if (channelName) this.changeChannelColor(channelName, e.instance.props.channel.id, modify); if (channelName) this.changeChannelColor(channelName, e.instance.props.channel.id, modify);
let channelIcon = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.quickswitchresulticon]]}); let channelIcon = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.quickswitchresulticon]]});
if (channelIcon) this.changeChannelIconColor(channelIcon, e.instance.props.channel.id, Object.assign({alpha: 0.6}, modify)); if (channelIcon) this.changeChannelIconColor(channelIcon, e.instance.props.channel.id, modify);
if (e.instance.props.category) { if (e.instance.props.category) {
let categoryName = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.quickswitchresultnote]]}); let categoryName = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.quickswitchresultnote]]});
if (categoryName) this.changeChannelColor(categoryName, e.instance.props.category.id); if (categoryName) this.changeChannelColor(categoryName, e.instance.props.category.id);
@ -561,7 +561,7 @@ module.exports = (_ => {
} }
if (data.color) { if (data.color) {
let mentioned = mention.props.mentioned; let mentioned = mention.props.mentioned;
let color = BDFDB.ColorUtils.convert(BDFDB.ObjectUtils.is(data.color) ? data.color1[0] : data.color1, "RGBA"); let color = BDFDB.ColorUtils.convert(BDFDB.ObjectUtils.is(data.color) ? data.color[0] : data.color, "RGBA");
let color_200 = BDFDB.ColorUtils.change(color, 200); let color_200 = BDFDB.ColorUtils.change(color, 200);
let color_a30 = BDFDB.ColorUtils.setAlpha(color, 0.3, "RGBA"); let color_a30 = BDFDB.ColorUtils.setAlpha(color, 0.3, "RGBA");
mention.props.style = Object.assign({}, mention.props.style, { mention.props.style = Object.assign({}, mention.props.style, {

View File

@ -23,7 +23,7 @@ module.exports = (_ => {
"changeLog": { "changeLog": {
"improved": { "improved": {
"Added some extra Info": "New Info on how to control the Observer List better" "Added some extra Info": "New Info on how to control the Observer List better"
}, }
} }
}; };