This commit is contained in:
Mirco Wittrien 2019-11-11 13:54:30 +01:00
parent 5ebbba15ff
commit 48bbe11f71
4 changed files with 101 additions and 63 deletions

View File

@ -6377,7 +6377,7 @@ var BDFDB = {
});
return this.props.isCustom || this.props.isSingle || this.props.color == null ? BDFDB.ReactUtils.createElement(LibraryComponents.TooltipContainer, {
text: this.props.isCustom || this.props.isSingle ? BDFDB.LanguageUtils.LanguageStrings.CUSTOM_COLOR : BDFDB.LanguageUtils.LanguageStrings.DEFAULT,
tooltipConfig: {position: this.props.isSingle ? "top" : "bottom"},
tooltipConfig: {type: this.props.isSingle ? "top" : "bottom"},
children: swatch
}) : swatch;
}
@ -6781,8 +6781,7 @@ var BDFDB = {
return BDFDB.ReactUtils.createElement(LibraryModules.React.Fragment, {
children: BDFDB.ReactUtils.createElement(NativeSubComponents.PopoutContainer, Object.assign({}, this.props, {
children: _ => {return child;},
renderPopout: this.handleRender.bind(this),
onRequestClose: (...args) => {console.log(...args);}
renderPopout: this.handleRender.bind(this)
}))
});
}

File diff suppressed because one or more lines are too long

View File

@ -65,7 +65,7 @@ class EmojiStatistics {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let settings = BDFDB.DataUtils.get(this, "settings");
let amounts = BDFDB.DataUtils.get(this, "amounts");
let settingsitems = [], inneritems = [];
let settingsitems = [];
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
className: BDFDB.disCN.marginbottom8,
@ -168,17 +168,17 @@ class EmojiStatistics {
}));
}
if (settings.enableEmojiHovering) {
let delay = BDFDB.DataUtils.get(this, "amounts", "hoverDelay");
let amounts = BDFDB.DataUtils.get(this, "amounts");
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"LazyScroller"});
if (index > -1) for (let row of children[index].props.children) if (row.props.className && row.props.className.indexOf(BDFDB.disCN.emojipickerrow) > -1) for (let i in row.props.children) {
let emoji = row.props.children[i];
let style = emoji.props.children ? emoji.props.children.props.style : emoji.props.style;
let data = style && style.backgroundImage && this.emojiToServerList[style.backgroundImage.replace(/url\(|\)|"|'/g,"")];
if (data) row.props.children[i] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: `${BDFDB.StringUtils.htmlEscape(data.emoji)}\n${BDFDB.StringUtils.htmlEscape(data.server)}`,
text: `${data.emoji}\n${data.server}`,
tooltipConfig: {
type: "right",
delay: delay
delay: amounts.hoverDelay
},
children: emoji
});

View File

@ -3,20 +3,19 @@
class ShowImageDetails {
getName () {return "ShowImageDetails";}
getVersion () {return "1.1.5";}
getVersion () {return "1.1.6";}
getAuthor () {return "DevilBro";}
getDescription () {return "Display the name, size and dimensions of uploaded images (does not include embed 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 = {
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
};
this.patchModules = {
"LazyImageZoomable":"componentDidMount",
"StandardSidebarView":"componentWillUnmount"
LazyImage: "render"
};
}
@ -47,20 +46,37 @@ class ShowImageDetails {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let settings = BDFDB.DataUtils.get(this, "settings");
let amounts = BDFDB.DataUtils.get(this, "amounts");
let 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>`;
}
for (let key in amounts) {
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.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCN.flexchild}" style="flex: 0 0 50%;">${this.defaults.amounts[key].description}</h3><div class="${BDFDB.disCN.inputwrapper} inputNumberWrapper ${BDFDB.disCNS.vertical}" style="flex: 1 1 auto;"><span class="numberinput-buttons-zone"><span class="numberinput-button-up"></span><span class="numberinput-button-down"></span></span><input type="number"${(!isNaN(this.defaults.amounts[key].min) && this.defaults.amounts[key].min !== null ? ' min="' + this.defaults.amounts[key].min + '"' : '') + (!isNaN(this.defaults.amounts[key].max) && this.defaults.amounts[key].max !== null ? ' max="' + this.defaults.amounts[key].max + '"' : '')} option="${key}" value="${amounts[key]}" class="${BDFDB.disCNS.inputdefault + BDFDB.disCNS.input + BDFDB.disCN.titlesize16} amount-input"></div></div>`;
}
settingshtml += `</div></div>`;
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
BDFDB.initElements(settingspanel, this);
return settingspanel;
let 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 BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
}
//legacy
@ -100,8 +116,8 @@ class ShowImageDetails {
stop () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
this.stopping = true;
document.querySelectorAll(".image-details-added").forEach(image => {this.resetImage(image);});
BDFDB.ModuleUtils.forceAllUpdates(this);
BDFDB.PluginUtils.clear(this);
}
@ -110,43 +126,66 @@ class ShowImageDetails {
// begin of own functions
resetImage (image) {
BDFDB.DOMUtils.removeClass(image, "image-details-added");
image.removeEventListener("mouseenter", image.mouseenterShowImageDetails);
let wrapper = image.parentElement;
if (BDFDB.DOMUtils.containsClass(wrapper, "image-details-wrapper")) {
wrapper.parentElement.insertBefore(image, wrapper);
wrapper.remove();
}
}
processLazyImageZoomable (instance, image, returnvalue) {
let attachment = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.return.memoizedProps.attachment");
if (attachment && !attachment.filename.endsWith(".bdemote.png") && !attachment.filename.endsWith(".bdemote.gif")) {
if (BDFDB.DOMUtils.containsClass(image.parentElement.parentElement, BDFDB.disCN.spoilercontainer, BDFDB.disCN.spoilertext, false)) image = image.parentElement.parentElement;
BDFDB.DOMUtils.addClass(image, "image-details-added");
image.removeEventListener("mouseenter", image.mouseenterShowImageDetails);
if (BDFDB.DataUtils.get(this, "settings", "showOnHover")) {
image.mouseenterShowImageDetails = () => {
BDFDB.TooltipUtils.create(image, `<div class="image-details-tooltip-name">${attachment.filename}</div><div class="image-details-tooltip-size">${BDFDB.formatBytes(attachment.size)}</div><div class="image-details-tooltip-dimensions">${attachment.width}x${attachment.height}px</div>`, {type:"right", html:true, selector:"image-details-tooltip", delay:BDFDB.DataUtils.get(this, "amounts", "hoverDelay")});
};
image.addEventListener("mouseenter", image.mouseenterShowImageDetails);
}
else {
let imagedetailswrapper = BDFDB.DOMUtils.create(`<div class="image-details-wrapper"><div class="image-details"><a class="${BDFDB.disCNS.anchor + BDFDB.disCN.anchorunderlineonhover} image-details-link" title="${attachment.url}" href="${attachment.url}" target="_blank" rel="noreferrer noopener">${attachment.filename}</a><label class="image-details-size ${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">${BDFDB.formatBytes(attachment.size)}</label><label class="image-details-dimensions ${BDFDB.disCNS.description + BDFDB.disCNS.formtext + BDFDB.disCNS.note + BDFDB.disCNS.modedefault + BDFDB.disCN.primary}">${attachment.width}x${attachment.height}px</label></div></div>`);
image.parentElement.insertBefore(imagedetailswrapper, image);
imagedetailswrapper.appendChild(image);
let scroller = BDFDB.DOMUtils.getParent(BDFDB.dotCN.messages, image);
if (scroller) scroller.scrollTop += BDFDB.DOMUtils.getRects(imagedetailswrapper).height - BDFDB.DOMUtils.getRects(image).height;
}
}
}
processStandardSidebarView (instance) {
onSettingsClosed () {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
document.querySelectorAll(".image-details-added").forEach(image => {this.resetImage(image);});
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) {
this.injectDetails(e);
if (!e.instance.props.size) BDFDB.LibraryRequires.request(e.instance.props.original, (error, response, result) => {
if (response) {
e.instance.props.size = response.headers["content-length"];
BDFDB.ReactUtils.forceUpdate(e.instance);
}
});
}
}
injectDetails (e) {
let settings = BDFDB.DataUtils.get(this, "settings");
let amounts = BDFDB.DataUtils.get(this, "amounts");
let renderChildren = e.returnvalue.props.children;
e.returnvalue.props.children = () => {
let renderedChildren = renderChildren(e.instance);
if (settings.showOnHover) return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: `${e.instance.props.original.split("/").slice(-1)}\n${BDFDB.NumberUtils.formatBytes(e.instance.props.size)}\n${e.instance.props.width}x${e.instance.props.height}px`,
tooltipConfig: {
type: "right",
delay: amounts.hoverDelay
},
children: renderedChildren
});
else return [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
className: "image-details",
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: e.instance.props.original.split("/").slice(-1)
})
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
color: BDFDB.LibraryComponents.TextElement.Colors.PRIMARY,
children: BDFDB.NumberUtils.formatBytes(e.instance.props.size)
})
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
color: BDFDB.LibraryComponents.TextElement.Colors.PRIMARY,
children: `${e.instance.props.width}x${e.instance.props.height}px`
})
})
]
}),
renderedChildren
];
};
}
}