BetterDiscordAddons/Plugins/UserNotes/UserNotes.plugin.js

164 lines
8.2 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//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"}*//
2019-01-17 23:48:29 +01:00
class UserNotes {
getName () {return "UserNotes";}
2019-09-11 12:14:43 +02:00
getVersion () {return "1.0.3";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
getDescription () {return "Allows you to write your own user notes wihtout a character limit.";}
2019-09-11 12:14:43 +02:00
constructor () {
this.changelog = {
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
};
}
2019-01-26 22:45:19 +01:00
initConstructor () {
2019-01-17 23:48:29 +01:00
this.css = `
2019-01-24 13:37:08 +01:00
.${this.name}-modal textarea {
2019-01-17 23:48:29 +01:00
rows: 0;
cols: 0;
height: 30vw;
resize: none;
}`;
this.userNotesModalMarkup =
2019-04-18 09:28:20 +02:00
`<span class="${this.name}-modal BDFDB-modal">
2019-01-17 23:48:29 +01:00
<div class="${BDFDB.disCN.backdrop}"></div>
<div class="${BDFDB.disCN.modal}">
<div class="${BDFDB.disCN.modalinner}">
<div class="${BDFDB.disCNS.modalsub + BDFDB.disCN.modalsizemedium}">
2019-10-08 11:51:41 +02:00
<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.modalheader}" style="flex: 0 0 auto;">
2019-01-17 23:48:29 +01:00
<div class="${BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">
2019-10-19 11:41:39 +02:00
<h4 class="${BDFDB.disCNS.h4 + BDFDB.disCNS.defaultcolor + BDFDB.disCN.h4defaultmargin}">${BDFDB.LanguageUtils.LanguageStrings.USERS + " " + BDFDB.LanguageUtils.LanguageStrings.NOTE}</h4>
2019-10-09 14:18:28 +02:00
<div class="${BDFDB.disCNS.modalguildname + BDFDB.disCNS.small + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCN.primary}"></div>
2019-01-17 23:48:29 +01:00
</div>
2019-01-22 20:15:31 +01:00
<button type="button" class="${BDFDB.disCNS.modalclose + BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookblank + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCN.buttongrow}">
<div class="${BDFDB.disCN.buttoncontents}">
<svg name="Close" width="18" height="18" viewBox="0 0 12 12" style="flex: 0 1 auto;">
<g fill="none" fill-rule="evenodd">
<path d="M0 0h12v12H0"></path>
<path class="fill" fill="currentColor" d="M9.5 3.205L8.795 2.5 6 5.295 3.205 2.5l-.705.705L5.295 6 2.5 8.795l.705.705L6 6.705 8.795 9.5l.705-.705L6.705 6"></path>
</g>
</svg>
</div>
</button>
2019-01-17 23:48:29 +01:00
</div>
2019-10-09 14:18:28 +02:00
<div class="${BDFDB.disCNS.scrollerwrap + BDFDB.disCNS.modalcontent + BDFDB.disCNS.scrollerthemed + BDFDB.disCNS.scrollerthemeghosthairline + BDFDB.disCNS.inputwrapper + BDFDB.disCNS.vertical + BDFDB.disCNS.flex2 + BDFDB.disCNS.flexchild + BDFDB.disCNS.modalsubinner + BDFDB.disCN.marginbottom20}" style="flex: 1 1 auto;">
2019-01-17 23:48:29 +01:00
<textarea class="${BDFDB.disCNS.scroller + BDFDB.disCNS.inputdefault + BDFDB.disCN.input}" id="modal-inputtext"></textarea>
</div>
2019-09-18 10:19:56 +02:00
<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontalreverse + BDFDB.disCNS.horizontalreverse2 + BDFDB.disCNS.directionrowreverse + BDFDB.disCNS.justifystart + BDFDB.disCNS.alignstretch + BDFDB.disCNS.nowrap + BDFDB.disCN.modalfooter}">
2019-01-17 23:48:29 +01:00
<button type="button" class="btn-save ${BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow}">
<div class="${BDFDB.disCN.buttoncontents}"></div>
</button>
<button type="button" class="btn-cancel ${BDFDB.disCNS.button + BDFDB.disCNS.buttonlooklink + BDFDB.disCNS.buttoncolorwhite + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow}">
<div class="${BDFDB.disCN.buttoncontents}"></div>
</button>
</div>
</div>
</div>
</div>
</span>`;
}
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
getSettingsPanel () {
2019-01-22 11:28:32 +01:00
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
2019-10-22 23:04:35 +02:00
let settings = BDFDB.DataUtils.get(this, "settings");
2019-10-09 14:18:28 +02:00
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.titlesize18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 0 0 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">Remove all User Notes.</h3><button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorred + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow} remove-button" style="flex: 0 0 auto;"><div class="${BDFDB.disCN.buttoncontents}">Remove</div></button></div>`;
2019-01-17 23:48:29 +01:00
settingshtml += `</div></div>`;
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
2019-01-17 23:48:29 +01:00
BDFDB.initElements(settingspanel, this);
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".remove-button", () => {
2019-10-30 13:27:14 +01:00
BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all usernotes?", () => {
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.remove(this, "notes");
2019-01-17 23:48:29 +01:00
});
});
return settingspanel;
}
//legacy
load () {}
start () {
2019-02-04 09:13:15 +01:00
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
2019-05-26 13:55:26 +02:00
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
2019-01-17 23:48:29 +01:00
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
2019-05-26 13:55:26 +02:00
libraryScript.setAttribute("id", "BDFDBLibraryScript");
2019-01-17 23:48:29 +01:00
libraryScript.setAttribute("type", "text/javascript");
2019-10-18 10:56:41 +02:00
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
2019-01-17 23:48:29 +01:00
libraryScript.setAttribute("date", performance.now());
2019-05-26 13:55:26 +02:00
libraryScript.addEventListener("load", () => {this.initialize();});
2019-01-17 23:48:29 +01:00
document.head.appendChild(libraryScript);
}
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2019-11-01 10:27:07 +01:00
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);
2019-01-17 23:48:29 +01:00
}
initialize () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-01-22 11:05:54 +01:00
if (this.started) return;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.init(this);
2019-01-17 23:48:29 +01:00
}
2019-11-01 10:14:50 +01:00
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
2019-01-17 23:48:29 +01:00
}
stop () {
2019-01-26 22:45:19 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.clear(this);
2019-01-17 23:48:29 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
onUserContextMenu (instance, menu, returnvalue) {
2019-11-10 17:16:01 +01:00
if (instance.props && instance.props.user) {
2019-10-22 19:38:25 +02:00
let [children, index] = BDFDB.ReactUtils.findChildren(returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
2019-10-22 18:55:25 +02:00
const itemgroup = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItemGroup, {
2019-09-11 12:14:43 +02:00
children: [
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
2019-10-19 11:41:39 +02:00
label: BDFDB.LanguageUtils.LanguageStrings.USERS + " " + BDFDB.LanguageUtils.LanguageStrings.NOTE,
2019-09-11 12:14:43 +02:00
action: e => {
2019-11-01 10:14:50 +01:00
BDFDB.ContextMenuUtils.close(menu);
2019-09-11 12:14:43 +02:00
this.openNotesModal(instance.props.user);
}
})
]
2019-01-17 23:48:29 +01:00
});
2019-09-11 12:14:43 +02:00
if (index > -1) children.splice(index, 0, itemgroup);
else children.push(itemgroup);
2019-01-17 23:48:29 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
openNotesModal (info) {
2019-10-22 20:16:05 +02:00
let note = BDFDB.DataUtils.load(this, "notes", info.id) || "";
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
let userNotesModal = BDFDB.DOMUtils.create(this.userNotesModalMarkup);
2019-10-22 19:49:57 +02:00
let noteinput = userNotesModal.querySelector("#modal-inputtext");
2019-05-18 07:13:18 +02:00
userNotesModal.querySelector(BDFDB.dotCN.modalguildname).innerText = info.username || "";
2019-01-17 23:48:29 +01:00
noteinput.value = note;
noteinput.setAttribute("placeholder", note);
BDFDB.appendModal(userNotesModal);
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.addToChildren(userNotesModal, "click", ".btn-save", (e) => {
2019-01-17 23:48:29 +01:00
e.preventDefault();
2019-10-22 20:16:05 +02:00
BDFDB.DataUtils.save(noteinput.value, this, "notes", info.id);
2019-01-17 23:48:29 +01:00
});
noteinput.focus();
}
2019-05-18 07:13:18 +02:00
}