stuff
This commit is contained in:
parent
f967e246ea
commit
72768fc8c5
|
@ -88,7 +88,6 @@ https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/S
|
||||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ServerFolders/ServerFolders.plugin.js
|
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ServerFolders/ServerFolders.plugin.js
|
||||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ServerHider/ServerHider.plugin.js
|
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ServerHider/ServerHider.plugin.js
|
||||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ShowHiddenChannels/ShowHiddenChannels.plugin.js
|
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ShowHiddenChannels/ShowHiddenChannels.plugin.js
|
||||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ShowImageDetails/ShowImageDetails.plugin.js
|
|
||||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SpellCheck/SpellCheck.plugin.js
|
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SpellCheck/SpellCheck.plugin.js
|
||||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SpotifyControls/SpotifyControls.plugin.js
|
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SpotifyControls/SpotifyControls.plugin.js
|
||||||
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SteamProfileLink/SteamProfileLink.plugin.js
|
https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SteamProfileLink/SteamProfileLink.plugin.js
|
||||||
|
|
|
@ -9,4 +9,4 @@
|
||||||
[patreon-badge]: https://img.shields.io/badge/Patreon-Support!-%23F96854.svg?logo=patreon&style=flat
|
[patreon-badge]: https://img.shields.io/badge/Patreon-Support!-%23F96854.svg?logo=patreon&style=flat
|
||||||
[patreon-link]: https://patreon.com/MircoWittrien
|
[patreon-link]: https://patreon.com/MircoWittrien
|
||||||
|
|
||||||
Display the name, size and dimensions of uploaded images (does not include embed images) in the chat as an header or as a tooltip.
|
DISCONTINUED
|
||||||
|
|
|
@ -1,50 +1,6 @@
|
||||||
//META{"name":"ShowImageDetails","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowImageDetails","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ShowImageDetails/ShowImageDetails.plugin.js"}*//
|
//META{"name":"ShowImageDetails","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowImageDetails","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ShowImageDetails/ShowImageDetails.plugin.js"}*//
|
||||||
|
|
||||||
var ShowImageDetails = (_ => {
|
var ShowImageDetails = (_ => {
|
||||||
var settings = {}, amounts = {};
|
|
||||||
|
|
||||||
const ImageDetails = class ImageDetails extends BdApi.React.Component {
|
|
||||||
componentDidMount() {
|
|
||||||
this.props.attachment = BDFDB.ReactUtils.findValue(BDFDB.ReactUtils.getValue(this, "_reactInternalFiber.return"), "attachment", {up: true});
|
|
||||||
BDFDB.ReactUtils.forceUpdate(this);
|
|
||||||
}
|
|
||||||
componentDidUpdate() {
|
|
||||||
if ((!this.props.attachment || !this.props.attachment.size) && !this.props.loaded) {
|
|
||||||
this.props.loaded = true;
|
|
||||||
this.props.attachment = BDFDB.ReactUtils.findValue(BDFDB.ReactUtils.getValue(this, "_reactInternalFiber.return"), "attachment", {up: true});
|
|
||||||
BDFDB.ReactUtils.forceUpdate(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return !this.props.attachment ? null : 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: this.props.original,
|
|
||||||
href: this.props.original,
|
|
||||||
children: this.props.attachment.filename,
|
|
||||||
onClick: event => {
|
|
||||||
BDFDB.ListenerUtils.stopEvent(event);
|
|
||||||
BDFDB.DiscordUtils.openLink(this.props.original);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
|
||||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
|
|
||||||
children: BDFDB.NumberUtils.formatBytes(this.props.attachment.size)
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
|
||||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextElement, {
|
|
||||||
children: `${this.props.attachment.width}x${this.props.attachment.height}px`
|
|
||||||
})
|
|
||||||
})
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return class ShowImageDetails {
|
return class ShowImageDetails {
|
||||||
getName () {return "ShowImageDetails";}
|
getName () {return "ShowImageDetails";}
|
||||||
|
|
||||||
|
@ -52,78 +8,7 @@ var ShowImageDetails = (_ => {
|
||||||
|
|
||||||
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 "DISCONTINUED";}
|
||||||
|
|
||||||
constructor () {
|
|
||||||
this.changelog = {
|
|
||||||
"fixed":[["Image Link","Clicking an image link in the details now properly opens the image in a new window"]],
|
|
||||||
"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: 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
|
// Legacy
|
||||||
load () {}
|
load () {}
|
||||||
|
@ -153,12 +38,6 @@ var ShowImageDetails = (_ => {
|
||||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||||
if (this.started) return;
|
if (this.started) return;
|
||||||
BDFDB.PluginUtils.init(this);
|
BDFDB.PluginUtils.init(this);
|
||||||
|
|
||||||
BDFDB.ModuleUtils.patch(this, (BDFDB.ModuleUtils.findByName("renderImageComponent", false).exports || {}), "renderImageComponent", {after: e => {
|
|
||||||
if (e.returnValue && e.returnValue.type && (e.returnValue.type.displayName == "LazyImageZoomable" || e.returnValue.type.displayName == "LazyImage") && e.methodArguments[0].original && e.methodArguments[0].src.indexOf("https://media.discordapp.net/attachments") == 0) return this.injectImageDetails(e.methodArguments[0], e.returnValue);
|
|
||||||
}});
|
|
||||||
|
|
||||||
this.forceUpdateAll();
|
|
||||||
}
|
}
|
||||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||||
}
|
}
|
||||||
|
@ -167,69 +46,12 @@ var ShowImageDetails = (_ => {
|
||||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||||
this.stopping = true;
|
this.stopping = true;
|
||||||
|
|
||||||
this.forceUpdateAll();
|
|
||||||
|
|
||||||
BDFDB.PluginUtils.clear(this);
|
BDFDB.PluginUtils.clear(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Begin of own functions
|
// Begin of own functions
|
||||||
|
|
||||||
onSettingsClosed () {
|
|
||||||
if (this.SettingsUpdated) {
|
|
||||||
delete this.SettingsUpdated;
|
|
||||||
this.forceUpdateAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
injectImageDetails (props, child) {
|
|
||||||
if (!settings.showOnHover) {
|
|
||||||
props.detailsAdded = true;
|
|
||||||
return BDFDB.ReactUtils.createElement("div", {
|
|
||||||
className: BDFDB.disCN.embedwrapper,
|
|
||||||
children: [
|
|
||||||
BDFDB.ReactUtils.createElement(ImageDetails, {
|
|
||||||
original: props.original,
|
|
||||||
attachment: {
|
|
||||||
height: 0,
|
|
||||||
width: 0,
|
|
||||||
filename: "unknown.png"
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
child
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
|
|
||||||
processLazyImage (e) {
|
|
||||||
if (e.instance.props.original && e.instance.props.src.indexOf("https://media.discordapp.net/attachments") == 0 && typeof e.returnvalue.props.children == "function") {
|
|
||||||
let attachment = BDFDB.ReactUtils.findValue(e.instance, "attachment", {up:true});
|
|
||||||
if (!attachment) return;
|
|
||||||
if (settings.showOnHover) {
|
|
||||||
let renderChildren = e.returnvalue.props.children;
|
|
||||||
e.returnvalue.props.children = (...args) => {
|
|
||||||
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: renderChildren(...args)
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
forceUpdateAll () {
|
|
||||||
settings = BDFDB.DataUtils.get(this, "settings");
|
|
||||||
amounts = BDFDB.DataUtils.get(this, "amounts");
|
|
||||||
|
|
||||||
BDFDB.MessageUtils.rerenderAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue