//META{"name":"ImageZoom","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ImageZoom","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ImageZoom/ImageZoom.plugin.js"}*// class ImageZoom { getName () {return "ImageZoom";} getVersion () {return "1.0.2";} getAuthor () {return "DevilBro";} getDescription () {return "Allows you to zoom in opened Images by holding left clicking on them in the Image Modal.";} initConstructor () { this.changelog = { "fixed":[["Lense","Fixed the issue where the lesen wouldn't properly clip the zoomed image"]] }; this.patchModules = { "ImageModal":["componentDidMount","componentWillUnmount"], "Icon":["componentDidMount","componentWillUnmount"], } this.zoomSettingsContextMarkup = `
`; this.css = ` .imagezoom-lense { border: 2px solid rgb(114, 137, 218); } .imagezoom-backdrop { position: absolute !important; top: 0 !important; right: 0 !important; bottom: 0 !important; left: 0 !important; z-index: 8000 !important; }`; this.defaults = { settings: { zoomlevel: {value:2, digits:1, min:1, max:10, unit:"x", name:"Zoom Level"}, lensesize: {value:200, digits:0, min:50, max:1000, unit:"px", name:"Lense Size"} } }; } //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#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.js"); libraryScript.setAttribute("date", performance.now()); libraryScript.addEventListener("load", () => {this.initialize();}); document.head.appendChild(libraryScript); this.libLoadTimeout = setTimeout(() => { libraryScript.remove(); require("request")("https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js", (error, response, body) => { if (body) { libraryScript = document.createElement("script"); libraryScript.setAttribute("id", "BDFDBLibraryScript"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("date", performance.now()); libraryScript.innerText = body; document.head.appendChild(libraryScript); } this.initialize(); }); }, 15000); } 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) { for (let img of document.querySelectorAll(BDFDB.dotCNS.imagewrapper + "img")) if (img.ImageZoomMouseDownListener) { img.removeEventListener("mousedown", img.ImageZoomMouseDownListener); delete img.ImageZoomMouseDownListener; img.removeAttribute("draggable"); } BDFDB.removeEles(".imagezoom-contextmenu", ".imagezoom-separator", ".imagezoom-settings", ".imagezoom-lense", ".imagezoom-backdrop"); BDFDB.unloadMessage(this); } } // begin of own functions processImageModal (instance, wrapper, methodnames) { if (methodnames.includes("componentDidMount")) { let modal = BDFDB.getParentEle(BDFDB.dotCN.modal, wrapper); if (!modal) return; let inner = modal.querySelector(BDFDB.dotCN.modalinner); if (!inner) return; let start = performance.now(); let waitForImg = setInterval(() => { let img = modal.querySelector(BDFDB.dotCNS.imagewrapper + "img," + BDFDB.dotCNS.imagewrapper + "video"); if (img && img.src && !BDFDB.containsClass(img, BDFDB.disCN.imageplaceholder)) { clearInterval(waitForImg); img.setAttribute("draggable", "false"); inner.firstElementChild.appendChild(BDFDB.htmlToElement(` | `)); let settingslink = BDFDB.htmlToElement(`Zoom ${BDFDB.LanguageStrings.SETTINGS}`); inner.firstElementChild.appendChild(settingslink); let openContext = e => { let settings = BDFDB.getAllData(this, "settings"); let zoomSettingsContext = BDFDB.htmlToElement(this.zoomSettingsContextMarkup); for (let slideritem of zoomSettingsContext.querySelectorAll(BDFDB.dotCN.contextmenuitemslider)) { let slider = slideritem.querySelector(BDFDB.dotCN.contextmenuslider); let type = slider.getAttribute("type"); let value = settings[type]; let percent = BDFDB.mapRange([this.defaults.settings[type].min, this.defaults.settings[type].max], [0, 100], value); let grabber = slider.querySelector(BDFDB.dotCN.slidergrabber); grabber.style.setProperty("left", percent + "%"); grabber.addEventListener("mousedown", e => {this.dragSlider(slider, value, e);}); slider.querySelector(BDFDB.dotCN.sliderbarfill).style.setProperty("width", percent + "%"); slider.querySelector(BDFDB.dotCN.sliderinput).value = value; slider.previousSibling.innerText = this.defaults.settings[type].name + ": " + value + this.defaults.settings[type].unit; } let zoomlevelitem = zoomSettingsContext.querySelector(".zoomlevel-item"); let lensesizeitem = zoomSettingsContext.querySelector(".lensesize-item"); BDFDB.appendContextMenu(zoomSettingsContext, e); }; settingslink.addEventListener("click", openContext); settingslink.addEventListener("contextmenu", openContext); img.ImageZoomMouseDownListener = e => { BDFDB.stopEvent(e); BDFDB.appendLocalStyle("ImageZoomCrossHair", "* {cursor: crosshair !important;}"); let imgrects = BDFDB.getRects(img); let settings = BDFDB.getAllData(this, "settings"); let lense = BDFDB.htmlToElement(`