From 5831603a66b606c343924046d756739189cc07c7 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Tue, 19 May 2020 17:17:03 +0200 Subject: [PATCH] Update UserNotes.plugin.js --- Plugins/UserNotes/UserNotes.plugin.js | 219 +++++++++++++------------- 1 file changed, 109 insertions(+), 110 deletions(-) diff --git a/Plugins/UserNotes/UserNotes.plugin.js b/Plugins/UserNotes/UserNotes.plugin.js index 50ff18b26c..9a45d99892 100644 --- a/Plugins/UserNotes/UserNotes.plugin.js +++ b/Plugins/UserNotes/UserNotes.plugin.js @@ -1,135 +1,134 @@ //META{"name":"UserNotes","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/UserNotes","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/UserNotes/UserNotes.plugin.js"}*// -class UserNotes { - getName () {return "UserNotes";} +var UserNotes = (_ => { + return class UserNotes { + getName () {return "UserNotes";} - getVersion () {return "1.0.4";} + getVersion () {return "1.0.5";} - getAuthor () {return "DevilBro";} + getAuthor () {return "DevilBro";} - getDescription () {return "Allows you to write your own user notes wihtout a character limit.";} - - constructor () { - this.changelog = { - "improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]] - }; - } - - initConstructor () { - this.css = ` - .${this.name}-modal textarea { - height: 50vh; - }`; - } - - getSettingsPanel () { - if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; - let settingsPanel, settingsItems = []; + getDescription () {return "Allows you to write your own user notes wihtout a character limit.";} - settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { - type: "Button", - className: BDFDB.disCN.marginbottom8, - color: BDFDB.LibraryComponents.Button.Colors.RED, - label: "Delete all Usernotes", - onClick: _ => { - BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all usernotes?", _ => { - BDFDB.DataUtils.remove(this, "notes"); - }); - }, - children: BDFDB.LanguageUtils.LanguageStrings.DELETE - })); + constructor () { + this.changelog = { + "fixed":[["Context Menu Update","Fixes for the context menu update, yaaaaaay"]] + }; + } - return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems); - } - - // Legacy - load () {} - - start () { - if (!window.BDFDB) window.BDFDB = {myPlugins:{}}; - if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this; - let 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.min.js"); - libraryScript.setAttribute("date", performance.now()); - libraryScript.addEventListener("load", _ => {this.initialize();}); - document.head.appendChild(libraryScript); + initConstructor () { + this.css = ` + .${this.name}-modal textarea { + height: 50vh; + }`; } - else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize(); - this.startTimeout = setTimeout(_ => { - try {return this.initialize();} - catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);} - }, 30000); - } - initialize () { - if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { - if (this.started) return; - BDFDB.PluginUtils.init(this); + getSettingsPanel () { + if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; + let settingsPanel, settingsItems = []; + + settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { + type: "Button", + className: BDFDB.disCN.marginbottom8, + color: BDFDB.LibraryComponents.Button.Colors.RED, + label: "Delete all Usernotes", + onClick: _ => { + BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all usernotes?", _ => { + BDFDB.DataUtils.remove(this, "notes"); + }); + }, + children: BDFDB.LanguageUtils.LanguageStrings.DELETE + })); + + return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems); } - else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!"); - } + // Legacy + load () {} - stop () { - if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { - this.stopping = true; - - BDFDB.PluginUtils.clear(this); + start () { + if (!window.BDFDB) window.BDFDB = {myPlugins:{}}; + if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this; + let 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.min.js"); + libraryScript.setAttribute("date", performance.now()); + libraryScript.addEventListener("load", _ => {this.initialize();}); + document.head.appendChild(libraryScript); + } + else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize(); + this.startTimeout = setTimeout(_ => { + try {return this.initialize();} + catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);} + }, 30000); + } + + initialize () { + if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { + if (this.started) return; + BDFDB.PluginUtils.init(this); + } + else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!"); } - } - // Begin of own functions + stop () { + if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { + this.stopping = true; - onUserContextMenu (e) { - if (e.instance.props.user) { - let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]}); - const itemgroup = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, { - children: [ - BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, { + BDFDB.PluginUtils.clear(this); + } + } + + + // Begin of own functions + + onUserContextMenu (e) { + if (e.instance.props.user) { + let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["id", "devmode-copy-id"]]}); + children.splice(index > -1 ? index : children.length, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuGroup, { + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuItem, { label: BDFDB.LanguageUtils.LanguageStrings.USERS + " " + BDFDB.LanguageUtils.LanguageStrings.NOTE, + id: BDFDB.ContextMenuUtils.createItemId(this.name, "user-note"), action: _ => { BDFDB.ContextMenuUtils.close(e.instance); this.openNotesModal(e.instance.props.user); } }) - ] + })); + } + } + + openNotesModal (user) { + let note = BDFDB.DataUtils.load(this, "notes", user.id); + + BDFDB.ModalUtils.open(this, { + size: "LARGE", + header: BDFDB.LanguageUtils.LanguageStrings.USERS + " " + BDFDB.LanguageUtils.LanguageStrings.NOTE, + subheader: user.username, + scroller: false, + children: [ + BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextArea, { + value: note, + placeholder: note, + autoFocus: true + }) + ], + buttons: [{ + contents: BDFDB.LanguageUtils.LanguageStrings.SAVE, + color: "BRAND", + close: true, + click: modal => { + note = modal.querySelector("textarea").value; + if (note) BDFDB.DataUtils.save(note, this, "notes", user.id); + else BDFDB.DataUtils.remove(this, "notes", user.id); + } + }] }); - if (index > -1) children.splice(index, 0, itemgroup); - else children.push(itemgroup); } } - - openNotesModal (user) { - let note = BDFDB.DataUtils.load(this, "notes", user.id); - - BDFDB.ModalUtils.open(this, { - size: "LARGE", - header: BDFDB.LanguageUtils.LanguageStrings.USERS + " " + BDFDB.LanguageUtils.LanguageStrings.NOTE, - subheader: user.username, - scroller: false, - children: [ - BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextArea, { - value: note, - placeholder: note, - autoFocus: true - }) - ], - buttons: [{ - contents: BDFDB.LanguageUtils.LanguageStrings.SAVE, - color: "BRAND", - close: true, - click: modal => { - note = modal.querySelector("textarea").value; - if (note) BDFDB.DataUtils.save(note, this, "notes", user.id); - else BDFDB.DataUtils.remove(this, "notes", user.id); - } - }] - }); - } -} +})(); \ No newline at end of file