//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";} getVersion () {return "1.1.4";} 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.";} initConstructor () { this.changelog = { "fixed":[["Spoilers","Properly works with images that are marked as spoilers now"],["Spoiler Crash","Fixed crash occuring when trying to reveal an inline spoiler"]] }; this.patchModules = { "LazyImageZoomable":"componentDidMount", "StandardSidebarView":"componentWillUnmount" }; this.css = ` .image-details .image-details-size { margin: 0 10px; } .image-details-tooltip { max-width: 500px; } .image-details-tooltip .image-details-tooltip-size { margin: 10px 0; } `; 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 (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; let settings = BDFDB.getAllData(this, "settings"); let amounts = BDFDB.getAllData(this, "amounts"); let settingshtml = `
${this.name}
`; for (let key in settings) { settingshtml += `

${this.defaults.settings[key].description}

`; } for (let key in amounts) { settingshtml += `

${this.defaults.amounts[key].description}

`; } settingshtml += `
`; let settingspanel = BDFDB.htmlToElement(settingshtml); BDFDB.initElements(settingspanel, this); return settingspanel; } //legacy load () {} start () { if (!global.BDFDB) global.BDFDB = {myPlugins:{}}; if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this; var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) { if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); libraryScript.setAttribute("date", performance.now()); libraryScript.addEventListener("load", () => {if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();}); document.head.appendChild(libraryScript); } else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize(); this.startTimeout = setTimeout(() => {this.initialize();}, 30000); } initialize () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (this.started) return; BDFDB.loadMessage(this); BDFDB.WebModules.forceAllUpdates(this); } else { console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); } } stop () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { document.querySelectorAll(".image-details-added").forEach(image => {this.resetImage(image);}); BDFDB.unloadMessage(this); } } // begin of own functions resetImage (image) { BDFDB.removeClass(image, "image-details-added"); image.removeEventListener("mouseenter", image.mouseenterShowImageDetails); let wrapper = image.parentElement; if (BDFDB.containsClass(wrapper, "image-details-wrapper")) { wrapper.parentElement.insertBefore(image, wrapper); wrapper.remove(); } } processLazyImageZoomable (instance, image) { let attachment = BDFDB.getReactValue(instance, "_reactInternalFiber.return.return.memoizedProps.attachment"); if (attachment && !attachment.filename.endsWith(".bdemote.png") && !attachment.filename.endsWith(".bdemote.gif")) { if (BDFDB.containsClass(image.parentElement.parentElement, BDFDB.disCN.spoilercontainer, BDFDB.disCN.spoilertext, false)) image = image.parentElement.parentElement; BDFDB.addClass(image, "image-details-added"); image.removeEventListener("mouseenter", image.mouseenterShowImageDetails); if (BDFDB.getData("showOnHover", this, "settings")) { image.mouseenterShowImageDetails = () => { BDFDB.createTooltip(`
${attachment.filename}
${BDFDB.formatBytes(attachment.size)}
${attachment.width}x${attachment.height}px
`, image, {type:"right", html:true, selector:"image-details-tooltip", delay:BDFDB.getData("hoverDelay", this, "amounts")}); }; image.addEventListener("mouseenter", image.mouseenterShowImageDetails); } else { let imagedetailswrapper = BDFDB.htmlToElement(`
${attachment.filename}
`); image.parentElement.insertBefore(imagedetailswrapper, image); imagedetailswrapper.appendChild(image); let scroller = BDFDB.getParentEle(BDFDB.dotCN.messages, image); if (scroller) scroller.scrollTop += BDFDB.getRects(imagedetailswrapper).height - BDFDB.getRects(image).height; } } } processStandardSidebarView (instance) { if (this.SettingsUpdated) { delete this.SettingsUpdated; document.querySelectorAll(".image-details-added").forEach(image => {this.resetImage(image);}); BDFDB.WebModules.forceAllUpdates(this); } } }