From 231c3665fd50b565f2c7430c58a1bf53221e2a33 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Tue, 9 Jun 2020 09:57:31 +0200 Subject: [PATCH] Update ImageZoom.plugin.js --- Plugins/ImageZoom/ImageZoom.plugin.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Plugins/ImageZoom/ImageZoom.plugin.js b/Plugins/ImageZoom/ImageZoom.plugin.js index b204973a19..2d1b508541 100644 --- a/Plugins/ImageZoom/ImageZoom.plugin.js +++ b/Plugins/ImageZoom/ImageZoom.plugin.js @@ -1,6 +1,8 @@ //META{"name":"ImageZoom","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/ImageZoom","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ImageZoom/ImageZoom.plugin.js"}*// var ImageZoom = (_ => { + var settings = {}; + return class ImageZoom { getName () {return "ImageZoom";} @@ -76,7 +78,7 @@ var ImageZoom = (_ => { if (this.started) return; BDFDB.PluginUtils.init(this); - BDFDB.ModuleUtils.forceAllUpdates(this); + this.forceUpdateAll(); } else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!"); } @@ -85,7 +87,7 @@ var ImageZoom = (_ => { if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { this.stopping = true; - BDFDB.ModuleUtils.forceAllUpdates(this); + this.forceUpdateAll(); BDFDB.PluginUtils.clear(this); } @@ -99,7 +101,6 @@ var ImageZoom = (_ => { let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props: [["className", BDFDB.disCN.downloadlink]]}); if (index > -1) { let openContext = event => { - let settings = BDFDB.DataUtils.get(this, "settings"); BDFDB.ContextMenuUtils.open(this, event, BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, { children: Object.keys(settings).map(type => BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuSliderItem, Object.assign({ id: BDFDB.ContextMenuUtils.createItemId(this.name, type), @@ -108,7 +109,8 @@ var ImageZoom = (_ => { return (this.labels[this.defaults.settings[type].label] || BDFDB.LanguageUtils.LanguageStrings[this.defaults.settings[type].label]) + ": " + value + this.defaults.settings[type].unit; }, onChange: value => { - BDFDB.DataUtils.save(value, this, "settings", type); + settings[type] = value; + BDFDB.DataUtils.save(settings, this, "settings"); } }, BDFDB.ObjectUtils.extract(this.defaults.settings[type], "digits", "minValue", "maxValue")))) })); @@ -141,7 +143,6 @@ var ImageZoom = (_ => { BDFDB.ListenerUtils.stopEvent(event); let imgRects = BDFDB.DOMUtils.getRects(e.node.firstElementChild); - let settings = BDFDB.DataUtils.get(this, "settings"); let lense = BDFDB.DOMUtils.create(`
<${e.node.firstElementChild.tagName} src="${e.instance.props.src}" style="width: ${imgRects.width * settings.zoomlevel}px; height: ${imgRects.height * settings.zoomlevel}px; position: fixed !important;"${e.node.firstElementChild.tagName == "VIDEO" ? " loop autoplay" : ""}>
`); let pane = lense.firstElementChild.firstElementChild; @@ -177,6 +178,12 @@ var ImageZoom = (_ => { }); } } + + forceUpdateAll () { + settings = BDFDB.DataUtils.get(this, "settings"); + + BDFDB.ModuleUtils.forceAllUpdates(this); + } setLabelsByLanguage () { switch (BDFDB.LanguageUtils.getLanguage().id) {