Update UserNotes.plugin.js
This commit is contained in:
parent
5792b2d6a9
commit
5831603a66
|
@ -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"}*//
|
//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 {
|
var UserNotes = (_ => {
|
||||||
getName () {return "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.";}
|
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 = [];
|
|
||||||
|
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
constructor () {
|
||||||
type: "Button",
|
this.changelog = {
|
||||||
className: BDFDB.disCN.marginbottom8,
|
"fixed":[["Context Menu Update","Fixes for the context menu update, yaaaaaay"]]
|
||||||
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);
|
initConstructor () {
|
||||||
}
|
this.css = `
|
||||||
|
.${this.name}-modal textarea {
|
||||||
// Legacy
|
height: 50vh;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
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 () {
|
getSettingsPanel () {
|
||||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
||||||
if (this.started) return;
|
let settingsPanel, settingsItems = [];
|
||||||
BDFDB.PluginUtils.init(this);
|
|
||||||
|
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 () {
|
start () {
|
||||||
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
||||||
this.stopping = true;
|
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
||||||
|
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
||||||
BDFDB.PluginUtils.clear(this);
|
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) {
|
BDFDB.PluginUtils.clear(this);
|
||||||
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, {
|
// 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,
|
label: BDFDB.LanguageUtils.LanguageStrings.USERS + " " + BDFDB.LanguageUtils.LanguageStrings.NOTE,
|
||||||
|
id: BDFDB.ContextMenuUtils.createItemId(this.name, "user-note"),
|
||||||
action: _ => {
|
action: _ => {
|
||||||
BDFDB.ContextMenuUtils.close(e.instance);
|
BDFDB.ContextMenuUtils.close(e.instance);
|
||||||
this.openNotesModal(e.instance.props.user);
|
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);
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue