//META {"name":"UserNotes","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";}
getVersion () {return "1.0.3";}
getAuthor () {return "DevilBro";}
getDescription () {return "Allows you to write your own user notes wihtout a character limit.";}
constructor () {
this.changelog = {
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
};
}
initConstructor () {
this.css = `
.${this.name}-modal textarea {
rows: 0;
cols: 0;
height: 30vw;
resize: none;
}`;
this.userNotesModalMarkup =
`
`;
}
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
var settings = BDFDB.getAllData(this, "settings");
var settingshtml = `
${this.name}
`;
settingshtml += `
Remove all User Notes.
`;
settingshtml += `
`;
let settingspanel = BDFDB.htmlToElement(settingshtml);
BDFDB.initElements(settingspanel, this);
BDFDB.addEventListener(this, settingspanel, "click", ".remove-button", () => {
BDFDB.openConfirmModal(this, "Are you sure you want to remove all usernotes?", () => {
BDFDB.removeAllData(this, "notes");
});
});
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#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();
BDFDB.LibraryRequires.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);
}
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) {
BDFDB.unloadMessage(this);
}
}
// begin of own functions
onUserContextMenu (instance, menu, returnvalue) {
if (instance.props && instance.props.user && !menu.querySelector(`${this.name}-contextMenuItem`)) {
let [children, index] = BDFDB.getContextMenuGroupAndIndex(returnvalue, ["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]);
const itemgroup = BDFDB.React.createElement(BDFDB.LibraryComponents.ContextMenuItemGroup, {
className: `BDFDB-contextMenuItemGroup ${this.name}-contextMenuItemGroup`,
children: [
BDFDB.React.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
label: BDFDB.LanguageStrings.USERS + " " + BDFDB.LanguageStrings.NOTE,
className: `BDFDB-contextMenuItem ${this.name}-contextMenuItem ${this.name}-usernote-contextMenuItem`,
action: e => {
BDFDB.closeContextMenu(menu);
this.openNotesModal(instance.props.user);
}
})
]
});
if (index > -1) children.splice(index, 0, itemgroup);
else children.push(itemgroup);
}
}
openNotesModal (info) {
let note = BDFDB.loadData(info.id, this, "notes") || "";
let userNotesModal = BDFDB.htmlToElement(this.userNotesModalMarkup);
let noteinput = userNotesModal.querySelector("#modal-inputtext")
userNotesModal.querySelector(BDFDB.dotCN.modalguildname).innerText = info.username || "";
noteinput.value = note;
noteinput.setAttribute("placeholder", note);
BDFDB.appendModal(userNotesModal);
BDFDB.addChildEventListener(userNotesModal, "click", ".btn-save", (e) => {
e.preventDefault();
BDFDB.saveData(info.id, noteinput.value, this, "notes")
});
noteinput.focus();
}
}