BetterDiscordAddons/Plugins/PersonalPins/PersonalPins.plugin.js

944 lines
51 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"PersonalPins","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/PersonalPins","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PersonalPins/PersonalPins.plugin.js"}*//
2018-12-28 14:28:50 +01:00
class PersonalPins {
2019-01-17 23:48:29 +01:00
getName () {return "PersonalPins";}
getDescription () {return "Similar to normal pins. Lets you save messages as notes for yourself.";}
2019-10-25 18:51:09 +02:00
getVersion () {return "1.8.3";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor () {
2019-02-03 19:02:15 +01:00
this.changelog = {
2019-10-25 18:51:09 +02:00
"fixed":[["Popout","Fixed bug where the popout would not properly open"]]
2019-02-03 19:02:15 +01:00
};
2019-09-04 12:34:02 +02:00
2018-12-28 14:28:50 +01:00
this.patchModules = {
"HeaderBar":["componentDidMount","componentDidUpdate"],
2019-04-23 14:03:21 +02:00
"HeaderBarContainer":["componentDidMount","componentDidUpdate"],
2019-09-11 12:14:43 +02:00
"Message":"componentDidMount"
2018-12-28 14:28:50 +01:00
};
2019-09-04 12:34:02 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
initConstructor () {
this.notesButtonMarkup =
2019-04-24 08:08:33 +02:00
`<div class="${BDFDB.disCNS.channelheadericonwrapper + BDFDB.disCN.channelheadericonclickable} notes-button">
2019-04-23 20:52:22 +02:00
<svg class="${BDFDB.disCN.channelheadericon}" name="Note" width="24" height="24" viewBox="-1 -1 23 23">
2019-04-23 13:53:19 +02:00
<path fill="currentColor" d="M 4.618, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 s 0.573 -0.256, 0.573 -0.573 V 0.573 C 5.191, 0.256, 4.935, 0, 4.618, 0 z"/>
<path fill="currentColor" d="M 8.053, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 s 0.573 -0.256, 0.573 -0.573 V 0.573 C 8.626, 0.256, 8.37, 0, 8.053, 0 z"/>
<path fill="currentColor" d="M 11.489, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 c 0.316, 0, 0.573 -0.256, 0.573 -0.573 V 0.573 C 12.061, 0.256, 11.805, 0, 11.489, 0 z "/>
<path fill="currentColor" d="M 14.924, 0 c -0.316, 0 -0.573, 0.256 -0.573, 0.573 v 1.145 c 0, 0.316, 0.256, 0.573, 0.573, 0.573 c 0.316, 0, 0.573 -0.256, 0.573 -0.573 V 0.573 C 15.496, 0.256, 15.24, 0, 14.924, 0 z"/>
<path fill="currentColor" d="M 16.641, 1.25 V 1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 c 0, 0.947 -0.77, 1.718 -1.718, 1.718 c -0.947, 0 -1.718 -0.77 -1.718 -1.718 V 1.25 C 2.236, 1.488, 1.756, 2.117, 1.756, 2.863 v 14.962 c 0, 0.947, 0.77, 1.718, 1.718, 1.718 h 12.595 c 0.947, 0, 1.718 -0.77, 1.718 -1.718 V 2.863 C 17.786, 2.117, 17.306, 1.488, 16.641, 1.25 z M 14.924, 16.679 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 c 0 -0.316, 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 C 15.496, 16.423, 15.24, 16.679, 14.924, 16.679 z M 14.924, 13.244 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 c 0 -0.316, 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 C 15.496, 12.988, 15.24, 13.244, 14.924, 13.244 z M 14.924, 9.733 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 s 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 S 15.24, 9.733, 14.924, 9.733 z M 14.924, 6.298 H 4.618 c -0.316, 0 -0.573 -0.256 -0.573 -0.573 s 0.256 -0.573, 0.573 -0.573 h 10.305 c 0.316, 0, 0.573, 0.256, 0.573, 0.573 S 15.24, 6.298, 14.924, 6.298 z"/>
</svg>
</div>`;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this.notesPopoutMarkup =
2019-04-18 09:28:20 +02:00
`<div class="${BDFDB.disCNS.popout + BDFDB.disCNS.popoutbottomright + BDFDB.disCNS.popoutnoarrow + BDFDB.disCN.popoutnoshadow} popout-personalpins-notes BDFDB-modal" style="z-index: 1000; visibility: visible; left: 544.844px; top: 35.9896px; transform: translateX(-100%) translateY(0%) translateZ(0px);">
2018-12-28 14:28:50 +01:00
<div class="${BDFDB.disCNS.messagespopoutwrap + BDFDB.disCNS.recentmentionspopout + BDFDB.disCN.popoutthemedpopout}" style="max-height: 740px; width: 500px;">
<div class="${BDFDB.disCNS.recentmentionsheader + BDFDB.disCNS.popoutheader + BDFDB.disCN.messagespopoutheader}" style="padding-bottom: 0;">
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.margintop8}" style="flex: 0 0 auto;">
<div class="${BDFDB.disCNS.popouttitle + BDFDB.disCN.messagespopouttitle}">REPLACE_popout_note_text</div>
2018-12-28 14:28:50 +01:00
</div>
<div class="${BDFDB.disCN.tabbarheadercontainer}" style="flex: 0 0 auto;">
<div class="${BDFDB.disCNS.tabbarheader + BDFDB.disCN.tabbartop}">
2019-04-23 08:26:48 +02:00
<div tab="channel" class="${BDFDB.disCNS.settingsitem + BDFDB.disCN.tabbarheaderitem}">REPLACE_popout_channel_text</div>
<div tab="server" class="${BDFDB.disCNS.settingsitem + BDFDB.disCN.tabbarheaderitem}">REPLACE_popout_server_text</div>
<div tab="allservers" class="${BDFDB.disCNS.settingsitem + BDFDB.disCN.tabbarheaderitem}">REPLACE_popout_allservers_text</div>
</div>
<div class="${BDFDB.disCN.recentmentionsmentionfilter}" style="padding-right: 15px;">
<div class="${BDFDB.disCN.recentmentionsmentionfilterlabel}">REPLACE_popout_sort_text:</div>
<div option="timestamp" class="${BDFDB.disCN.recentmentionsmentionfiltervalue}" style="text-transform: none;">REPLACE_popout_messagesort_text</div>
2018-12-28 14:28:50 +01:00
</div>
</div>
</div>
<div class="${BDFDB.disCN.scrollerwrap}">
<div class="${BDFDB.disCNS.messagespopout + BDFDB.disCN.scroller}">
<div class="${BDFDB.disCN.messagespopoutemptyplaceholder}">
<div class="${BDFDB.disCN.messagespopoutimage}"></div>
<div class="${BDFDB.disCN.messagespopoutbody}"></div>
</div>
</div>
</div>
</div>
</div>`;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this.sortPopoutMarkup =
`<div class="${BDFDB.disCNS.popout + BDFDB.disCNS.popoutbottomright + BDFDB.disCN.popoutnoshadow} personalpins-sort-popout" style="z-index: 1100; visibility: visible; transform: translateX(-100%) translateY(0%) translateZ(0px);">
<div>
2019-09-11 12:14:43 +02:00
<div class="${BDFDB.disCN.contextmenu} BDFDB-quickSelectPopout">
2018-12-28 14:28:50 +01:00
<div class="${BDFDB.disCN.contextmenuitemgroup}">
2019-09-11 12:14:43 +02:00
<div option="timestamp" class="${BDFDB.disCNS.contextmenuitem + BDFDB.disCN.contextmenuitemclickable}">REPLACE_popout_messagesort_text</div>
<div option="addedat" class="${BDFDB.disCNS.contextmenuitem + BDFDB.disCN.contextmenuitemclickable}">REPLACE_popout_datesort_text</div>
2018-12-28 14:28:50 +01:00
</div>
</div>
</div>
</div>`;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this.messageDividerMarkup =
`<div class="${BDFDB.disCN.messagespopoutchannelseparator}">
<span tabindex="0" class="${BDFDB.disCN.messagespopoutchannelname}" role="button"></span>
2019-09-11 12:14:43 +02:00
<span class="${BDFDB.disCN.messagespopoutguildname}"></span>
2018-12-28 14:28:50 +01:00
</div>`;
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this.messageMarkup =
`<div class="${BDFDB.disCN.messagespopoutmessagegroupwrapper}">
<div class="${BDFDB.disCN.messagespopoutmessagegroupwrapperoffsetcorrection}">
<div class="${BDFDB.disCNS.messagespopoutcontainercozybounded + BDFDB.disCNS.messagegroup + BDFDB.disCN.messagegroupcozy}">
2019-09-11 12:14:43 +02:00
<div class="${BDFDB.disCN.messagespopoutmessagegroupcozy}" aria-disabled="true">
2018-12-28 14:28:50 +01:00
<div class="${BDFDB.disCN.messageheadercozy}">
2019-07-20 12:04:11 +02:00
<div class="${BDFDB.disCN.messageavatar}" aria-hidden="true">
<div class="${BDFDB.disCN.avatarwrapper}" role="img" aria-hidden="true" style="width: 40px; height: 40px;">
<svg width="49" height="40" viewBox="0 0 49 40" class="${BDFDB.disCN.avatarmask}" aria-hidden="true">
<foreignObject x="0" y="0" width="40" height="40" mask="url(#svg-mask-avatar-default)">
<img src="" alt=" " class="${BDFDB.disCN.avatar}" aria-hidden="true">
</foreignObject>
</svg>
</div>
2018-12-28 14:28:50 +01:00
</div>
<h2 class="${BDFDB.disCN.messageheadercozymeta}">
<span class="">
<strong tabindex="0" class="${BDFDB.disCN.messageusername}" role="button"></strong>
</span>
<time class="${BDFDB.disCN.messagetimestampcozy}"></time>
</h2>
</div>
<div class="${BDFDB.disCNS.messagecontentcozy + BDFDB.disCN.messagecontent}">
<div class="${BDFDB.disCNS.messagebodycozy + BDFDB.disCN.messagebody}">
<div class="${BDFDB.disCN.messagemarkup}"></div>
</div>
<div class="${BDFDB.disCNS.messagespopoutaccessories + BDFDB.disCNS.messageaccessorycozy + BDFDB.disCN.messageaccessory}"></div>
</div>
</div>
<div class="${BDFDB.disCNS.sinkinteractions + BDFDB.disCN.clickable}"></div>
<div class="${BDFDB.disCN.messagespopoutactionbuttons}">
<div tabindex="0" class="${BDFDB.disCN.messagespopoutjumpbutton} jump" role="button">
<div class="${BDFDB.disCN.messagespopouttext}">REPLACE_popout_jump_text</div>
</div>
<div tabindex="0" class="${BDFDB.disCN.messagespopoutjumpbutton} copy" aria-label="Jump" role="button">
<div class="${BDFDB.disCN.messagespopouttext}">REPLACE_popout_copy_text</div>
</div>
<button type="button" class="${BDFDB.disCNS.button + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCNS.buttonlookblank + BDFDB.disCN.buttongrow}">
<div class="${BDFDB.disCN.buttoncontents}">
<div class="${BDFDB.disCN.messagespopoutclosebutton}"></div>
</div>
</button>
</div>
<hr aria-hidden="true" class="${BDFDB.disCNS.messagedividerenabled + BDFDB.disCN.messagedivider}">
</div>
</div>
</div>`;
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
getSettingsPanel () {
2019-01-22 11:28:32 +01:00
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
2019-10-09 14:18:28 +02:00
let 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;">Delete all Notes.</h3><button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorred + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow} reset-button" style="flex: 0 0 auto;"><div class="${BDFDB.disCN.buttoncontents}">Reset</div></button></div>`;
2018-12-28 14:28:50 +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);
2018-12-28 14:28:50 +01:00
2019-01-17 23:48:29 +01:00
BDFDB.initElements(settingspanel, this);
2018-12-28 14:28:50 +01:00
settingspanel.querySelector(".reset-button").addEventListener("click", () => {
2019-10-30 13:27:14 +01:00
BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all pinned notes?", () => {
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.remove(this, "pins");
});
});
2018-12-28 14:28:50 +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) {
2018-12-28 14:28:50 +01:00
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
2019-05-26 13:55:26 +02:00
libraryScript.setAttribute("id", "BDFDBLibraryScript");
2018-12-28 14:28:50 +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();});
2018-12-28 14:28:50 +01:00
document.head.appendChild(libraryScript);
}
2019-01-17 23:48:29 +01:00
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);
2018-12-28 14:28:50 +01:00
}
initialize () {
2019-01-17 23:48:29 +01:00
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-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.forceAllUpdates(this);
2018-12-28 14:28:50 +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!");
2018-12-28 14:28:50 +01:00
}
stop () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(".popout-personalpins-notes", ".personalpins-sort-popout", ".notes-button");
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.clear(this);
2018-12-28 14:28:50 +01:00
}
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
changeLanguageStrings () {
this.notesPopoutMarkup = this.notesPopoutMarkup.replace("REPLACE_popout_note_text", this.labels.popout_note_text);
this.notesPopoutMarkup = this.notesPopoutMarkup.replace("REPLACE_popout_channel_text", this.labels.popout_channel_text);
this.notesPopoutMarkup = this.notesPopoutMarkup.replace("REPLACE_popout_server_text", this.labels.popout_server_text);
this.notesPopoutMarkup = this.notesPopoutMarkup.replace("REPLACE_popout_allservers_text", this.labels.popout_allservers_text);
this.notesPopoutMarkup = this.notesPopoutMarkup.replace("REPLACE_popout_sort_text", this.labels.popout_sort_text);
this.notesPopoutMarkup = this.notesPopoutMarkup.replace("REPLACE_popout_messagesort_text", this.labels.popout_messagesort_text);
2019-01-26 22:45:19 +01:00
2019-10-19 11:41:39 +02:00
this.messageMarkup = this.messageMarkup.replace("REPLACE_popout_jump_text", BDFDB.LanguageUtils.LanguageStrings.JUMP);
this.messageMarkup = this.messageMarkup.replace("REPLACE_popout_copy_text", BDFDB.LanguageUtils.LanguageStrings.COPY);
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
this.sortPopoutMarkup = this.sortPopoutMarkup.replace("REPLACE_popout_messagesort_text", this.labels.popout_messagesort_text);
this.sortPopoutMarkup = this.sortPopoutMarkup.replace("REPLACE_popout_datesort_text", this.labels.popout_datesort_text);
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
onMessageContextMenu (instance, menu, returnvalue) {
if (instance.props && instance.props.message && instance.props.channel && instance.props.target && !menu.querySelector(`${this.name}-contextMenuItem`)) {
2019-09-03 12:37:14 +02:00
let {messagediv, pos} = this.getMessageAndPos(instance.props.target);
if (!messagediv || pos == -1) return;
let note = this.getNoteData(instance.props.message, instance.props.target, instance.props.channel);
2019-10-22 19:38:25 +02:00
let [children, index] = BDFDB.ReactUtils.findChildren(returnvalue, {name:"MessagePinItem"});
2019-10-22 18:55:25 +02:00
const pinUnpinItem = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
2019-09-11 12:14:43 +02:00
label: this.labels[note ? "context_unpinoption_text" : "context_pinoption_text"],
2019-10-23 11:10:01 +02:00
hint: BDFDB.BDUtils.isPluginEnabled("MessageUtilities") ? BDFDB.BDUtils.getPlugin("MessageUtilities").getActiveShortcutString("__Note_Message") : null,
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.addMessageToNotes(instance.props.message, instance.props.target, instance.props.channel);
}
});
2019-09-11 12:14:43 +02:00
if (index > -1) children.splice(index, 0, pinUnpinItem);
else children.push(pinUnpinItem);
if (note) {
let newmarkup = this.getMarkup(messagediv).innerHTML;
let newaccessory = messagediv.querySelector(BDFDB.dotCN.messageaccessory).innerHTML;
if (note.markup != newmarkup || note.accessory != newaccessory) {
2019-10-22 18:55:25 +02:00
const updateItem = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
2019-09-11 12:14:43 +02:00
label: this.labels.context_updateoption_text,
action: e => {
2019-11-01 10:14:50 +01:00
BDFDB.ContextMenuUtils.close(menu);
2019-09-11 12:14:43 +02:00
this.updateNoteData(note, newmarkup, newaccessory);
}
});
if (index > -1) children.splice(index, 0, updateItem);
else children.push(updateItem);
}
2019-09-03 12:37:14 +02:00
}
2019-09-11 12:14:43 +02:00
}
}
onMessageOptionPopout (instance, popout, returnvalue) {
if (instance.props.message && instance.props.channel && instance.props.target && !popout.querySelector(`${this.name}-popoutMenuItem`)) {
let {messagediv, pos} = this.getMessageAndPos(instance.props.target);
if (!messagediv || pos == -1) return;
let note = this.getNoteData(instance.props.message, instance.props.target, instance.props.channel);
2019-10-22 19:38:25 +02:00
let [children, index] = BDFDB.ReactUtils.findChildren(returnvalue, {props:[["label", [BDFDB.LanguageUtils.LanguageStrings.PIN, BDFDB.LanguageUtils.LanguageStrings.UNPIN]]]});
2019-11-07 22:33:27 +01:00
children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
2019-09-11 12:14:43 +02:00
label: this.labels[note ? "context_unpinoption_text" : "popout_pinoption_text"],
2019-11-07 22:33:27 +01:00
className: BDFDB.disCN.optionpopoutitem,
2019-09-11 12:14:43 +02:00
action: e => {
this.addMessageToNotes(instance.props.message, instance.props.target, instance.props.channel);
instance.props.onClose();
}
2019-11-07 22:33:27 +01:00
}));
2019-09-03 12:37:14 +02:00
if (note) {
let newmarkup = this.getMarkup(messagediv).innerHTML;
let newaccessory = messagediv.querySelector(BDFDB.dotCN.messageaccessory).innerHTML;
if (note.markup != newmarkup || note.accessory != newaccessory) {
2019-11-07 22:33:27 +01:00
children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
2019-09-11 12:14:43 +02:00
label: this.labels.context_updateoption_text,
2019-11-07 22:33:27 +01:00
className: BDFDB.disCN.optionpopoutitem,
2019-09-11 12:14:43 +02:00
action: e => {
this.updateNoteData(note, newmarkup, newaccessory);
instance.props.onClose();
}
2019-11-07 22:33:27 +01:00
}));
2019-09-03 12:37:14 +02:00
}
2018-12-28 14:28:50 +01:00
}
}
}
2019-09-04 12:34:02 +02:00
2019-09-11 12:14:43 +02:00
processHeaderBarContainer (instance, wrapper, returnvalue) {
2019-04-23 14:03:21 +02:00
this.processHeaderBar(instance, wrapper);
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processHeaderBar (instance, wrapper, returnvalue) {
2019-06-12 09:09:03 +02:00
if (wrapper.querySelector(".notes-button")) return;
let search = wrapper.querySelector(BDFDB.dotCN.channelheadersearch);
if (!search) return;
2019-10-23 11:10:01 +02:00
let notesbutton = BDFDB.DOMUtils.create(this.notesButtonMarkup);
search.parentElement.insertBefore(notesbutton, search);
let icon = notesbutton.querySelector(BDFDB.dotCN.channelheadericon);
icon.addEventListener("click", () => {
2019-04-23 13:53:19 +02:00
this.openNotesPopout(icon.parentElement);
});
icon.addEventListener("mouseenter", () => {
2019-10-22 18:55:25 +02:00
BDFDB.TooltipUtils.create(icon, this.labels.popout_note_text, {type:"bottom",selector:"note-button-tooltip"});
});
2018-12-28 14:28:50 +01:00
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processMessage (instance, wrapper, returnvalue) {
2019-10-22 18:55:25 +02:00
if (instance.props && typeof instance.props.renderButtons == "function" && !wrapper.querySelector(BDFDB.dotCN.optionpopoutbutton) && BDFDB.ReactUtils.getValue(instance, "props.message.author.id") != 1) {
2018-12-28 14:28:50 +01:00
let buttonwrap = wrapper.querySelector(BDFDB.dotCN.messagebuttoncontainer);
if (buttonwrap) {
2019-10-23 11:10:01 +02:00
let optionPopoutButton = BDFDB.DOMUtils.create(`<div tabindex="0" class="${BDFDB.disCN.optionpopoutbutton}" aria-label="More Options" role="button"><svg name="OverflowMenu" class="${BDFDB.disCN.optionpopoutbuttonicon}" aria-hidden="false" width="24" height="24" viewBox="0 0 24 24"><g fill="none" fill-rule="evenodd"><path d="M24 0v24H0V0z"></path><path fill="currentColor" d="M12 16c1.1045695 0 2 .8954305 2 2s-.8954305 2-2 2-2-.8954305-2-2 .8954305-2 2-2zm0-6c1.1045695 0 2 .8954305 2 2s-.8954305 2-2 2-2-.8954305-2-2 .8954305-2 2-2zm0-6c1.1045695 0 2 .8954305 2 2s-.8954305 2-2 2-2-.8954305-2-2 .8954305-2 2-2z"></path></g></svg></div>`);
optionPopoutButton.addEventListener("click", () => {BDFDB.createMessageOptionPopout(optionPopoutButton);});
buttonwrap.appendChild(optionPopoutButton);
2018-12-28 14:28:50 +01:00
}
}
2019-04-23 13:53:19 +02:00
}
2019-01-26 22:45:19 +01:00
openNotesPopout (button) {
let container = document.querySelector(BDFDB.dotCN.popouts);
2019-10-23 11:10:01 +02:00
if (!container || BDFDB.DOMUtils.containsClass(button, BDFDB.disCN.channelheadericonselected)) return;
BDFDB.DOMUtils.addClass(button, BDFDB.disCN.channelheadericonselected);
let notespopout = BDFDB.DOMUtils.create(this.notesPopoutMarkup);
2019-04-23 13:53:19 +02:00
notespopout.querySelector(BDFDB.dotCN.popoutheader).firstElementChild.appendChild(BDFDB.createSearchBar("small"));
container.appendChild(notespopout);
2019-01-26 22:45:19 +01:00
BDFDB.initElements(notespopout, this);
2019-10-23 11:10:01 +02:00
let buttonrects = BDFDB.DOMUtils.getRects(button);
notespopout.style.setProperty("left", buttonrects.left + buttonrects.width/2 + "px");
2019-10-25 18:51:09 +02:00
notespopout.style.setProperty("top", buttonrects.top + buttonrects.height + "px");
notespopout.querySelectorAll(BDFDB.dotCN.tabbarheaderitem).forEach(tab => {tab.addEventListener("click", () => {
this.addNotes(notespopout);
});});
notespopout.querySelector(BDFDB.dotCN.searchbarinput).addEventListener("keyup", () => {
2019-11-01 11:09:32 +01:00
BDFDB.TimeUtils.clear(notespopout.searchTimeout);
notespopout.searchTimeout = BDFDB.TimeUtils.timeout(() => {this.addNotes(notespopout);},1000);
2018-12-28 14:28:50 +01:00
});
notespopout.querySelector(BDFDB.dotCN.searchbarclear).addEventListener("click", e => {
2019-11-01 11:09:32 +01:00
BDFDB.TimeUtils.clear(notespopout.searchTimeout);
notespopout.searchTimeout = BDFDB.TimeUtils.timeout(() => {this.addNotes(notespopout);},1000);
2018-12-28 14:28:50 +01:00
});
notespopout.querySelector(BDFDB.dotCN.recentmentionsmentionfilter).addEventListener("click", e => {
BDFDB.createSortPopout(e.currentTarget, this.sortPopoutMarkup, () => {this.addNotes(notespopout);});
});
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
var removePopout = e => {
2019-10-23 11:10:01 +02:00
if (!notespopout.contains(e.target) && !BDFDB.DOMUtils.getParent(".personalpins-sort-popout", e.target)) {
document.removeEventListener("mousedown", removePopout);
notespopout.remove();
2019-11-01 11:09:32 +01:00
BDFDB.TimeUtils.timeout(() => {BDFDB.DOMUtils.removeClass(button, BDFDB.disCN.channelheadericonselected);},300);
2018-12-28 14:28:50 +01:00
}
};
document.addEventListener("mousedown", removePopout);
2019-01-26 22:45:19 +01:00
this.addNotes(notespopout);
2018-12-28 14:28:50 +01:00
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
addNotes (notespopout) {
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(notespopout.querySelectorAll(BDFDB.dotCNC.messagegroupwrapper + BDFDB.dotCN.messagespopoutchannelseparator));
2019-10-22 18:55:25 +02:00
let channel = BDFDB.ChannelUtils.getSelected();
if (channel) {
let guild_id = channel.guild_id ? channel.guild_id : "@me";
2019-10-22 19:49:57 +02:00
let pins = BDFDB.DataUtils.load(this, "pins");
2019-10-22 18:55:25 +02:00
if (!BDFDB.ObjectUtils.isEmpty(pins)) {
2018-12-28 14:28:50 +01:00
let container = notespopout.querySelector(BDFDB.dotCN.messagespopout);
let placeholder = notespopout.querySelector(BDFDB.dotCN.messagespopoutemptyplaceholder);
if (!container || !placeholder) return;
2019-10-22 18:55:25 +02:00
placeholder.querySelector(BDFDB.dotCN.messagespopoutimage).style.setProperty("background-image", `url(${BDFDB.DiscordUtils.getTheme() == BDFDB.disCN.themelight ? "/assets/03c7541028afafafd1a9f6a81cb7f149.svg" : "/assets/6793e022dc1b065b21f12d6df02f91bd.svg"})`);
let notes = {};
switch (notespopout.querySelector(BDFDB.dotCN.tabbarheaderitem + BDFDB.dotCN.settingsitemselected).getAttribute("tab")) {
2018-12-28 14:28:50 +01:00
case "channel":
notes = pins[guild_id] && pins[guild_id][channel.id] ? pins[guild_id][channel.id] : {};
2018-12-28 14:28:50 +01:00
break;
case "server":
2019-09-04 12:34:02 +02:00
if (pins[guild_id]) for (let channel in pins[guild_id]) notes = Object.assign(notes, pins[guild_id][channel]);
2018-12-28 14:28:50 +01:00
break;
case "allservers":
2019-09-04 12:34:02 +02:00
for (let server in pins) if (pins[server]) for (let channel in pins[server]) notes = Object.assign(notes, pins[server][channel]);
2018-12-28 14:28:50 +01:00
break;
}
let noteArray = [];
for (let id in notes) {noteArray.push(notes[id]);}
2019-10-22 18:55:25 +02:00
BDFDB.ArrayUtils.keySort(noteArray, notespopout.querySelector(BDFDB.dotCN.recentmentionsmentionfiltervalue).getAttribute("option"));
2019-05-26 13:55:26 +02:00
for (let noteData of noteArray) this.appendNote(notespopout, container, noteData, placeholder);
let searchstring = notespopout.querySelector(BDFDB.dotCN.searchbarinput).value.replace(/[<|>]/g, "");
if (searchstring) for (let note of notespopout.querySelectorAll(BDFDB.dotCN.messagegroupwrapper)) {
note.innerHTML = BDFDB.highlightText(note.innerHTML, searchstring);
if (!note.querySelector(BDFDB.dotCN.highlight)) {
note.previousSibling.remove();
note.remove();
2018-12-28 14:28:50 +01:00
}
}
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.toggle(placeholder, container.firstElementChild == placeholder);
}
}
}
2019-01-26 22:45:19 +01:00
2019-05-26 13:55:26 +02:00
appendNote (notespopout, container, noteData, placeholder) {
if (!container || !noteData) return;
2019-09-11 12:14:43 +02:00
let server = BDFDB.LibraryModules.GuildStore.getGuild(noteData.guild_id) || {};
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(noteData.channel_id) || {};
let user = BDFDB.LibraryModules.UserStore.getUser(noteData.author_id) || {};
let member = BDFDB.LibraryModules.MemberStore.getMember(noteData.guild_id, noteData.author_id) || {};
let date = new Date(noteData.timestamp);
2019-10-23 11:10:01 +02:00
let message = BDFDB.DOMUtils.create(this.messageMarkup);
let messagedivider = BDFDB.DOMUtils.create(this.messageDividerMarkup);
container.insertBefore(message, container.firstChild);
container.insertBefore(messagedivider, container.firstChild);
let channelname = messagedivider.querySelector(BDFDB.dotCN.messagespopoutchannelname);
channelname.innerText = (noteData.guild_id == "@me" ? " @" : " #") + (channel.name || noteData.channel_name);
2019-10-23 11:10:01 +02:00
if (noteData.guild_id != "@me" && BDFDB.BDUtils.isPluginEnabled("EditChannels")) {
BDFDB.BDUtils.getPlugin("EditChannels").changeChannel2({id:noteData.channel_id,name:noteData.channel_name}, channelname);
}
2019-10-23 11:10:01 +02:00
else if (noteData.guild_id == "@me" && BDFDB.BDUtils.isPluginEnabled("EditUsers")) {
let dmuser_id = channel && channel.type == 1 ? channel.recipients[0] : noteData.dmuser_id;
if (dmuser_id) {
2019-10-23 11:10:01 +02:00
BDFDB.BDUtils.getPlugin("EditUsers").changeName2({id:dmuser_id,username:noteData.channel_name}, channelname);
if (channelname.innerText.indexOf("@") != 0) channelname.innerText = "@" + channelname.innerText;
}
}
let guildname = messagedivider.querySelector(BDFDB.dotCN.messagespopoutguildname);
guildname.innerText = server.name || noteData.guild_name;
2019-07-20 12:04:11 +02:00
let avatar = message.querySelector(BDFDB.dotCN.avatar);
2019-10-22 18:55:25 +02:00
avatar.setAttribute("src", `${user.id ? BDFDB.UserUtils.getAvatar(user.id) : noteData.avatar}`);
let username = message.querySelector(BDFDB.dotCN.messageusername);
username.innerText = user.username || noteData.author_name;
username.style.setProperty("color", member.colorString || noteData.color);
2019-10-23 11:10:01 +02:00
if (BDFDB.BDUtils.isPluginEnabled("EditUsers")) {
let EditUsers = BDFDB.BDUtils.getPlugin("EditUsers");
2019-09-25 21:37:08 +02:00
EditUsers.changeName({id:noteData.author_id,username:noteData.author_name}, username, noteData.guild_id);
if (user.id) EditUsers.changeAvatar({id:noteData.author_id,username:noteData.author_name}, avatar);
EditUsers.addTag({id:noteData.author_id,username:noteData.author_name}, username.parentElement, " " + BDFDB.disCN.bottagnametag);
}
let timestamp = message.querySelector(BDFDB.dotCN.messagetimestampcozy);
2019-10-24 11:47:57 +02:00
timestamp.innerText = date.toLocaleString(BDFDB.LanguageUtils.getLanguage().id);
timestamp.setAttribute("datetime", date);
2019-10-25 18:51:09 +02:00
if (BDFDB.BDUtils.isPluginEnabled("CompleteTimestamps") && BDFDB.DataUtils.load("CompleteTimestamps", "settings", "showInChat")) {
2019-10-23 11:10:01 +02:00
BDFDB.BDUtils.getPlugin("CompleteTimestamps").changeTimestamp(timestamp);
2019-02-03 18:03:02 +01:00
}
message.querySelector(BDFDB.dotCN.messagemarkup).innerHTML = noteData.markup.replace(`<span class="edited">`,`<span class="${BDFDB.disCN.messageedited}">`);
message.querySelector(BDFDB.dotCN.messageaccessory).innerHTML = noteData.accessory;
if (noteData.accessory) {
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.addToChildren(message, "click", BDFDB.dotCN.iconplay, e => {this.startYoutubeVideo(e.currentTarget);});
let ytvideo = message.querySelector(BDFDB.dotCN.embed + " iframe[src*='https://www.youtube.com']");
if (ytvideo) {
let ytlink = ytvideo.parentElement.parentElement.querySelector(BDFDB.dotCN.embedtitle).href;
let wrapper = ytvideo.parentElement;
ytvideo.remove();
2019-09-11 12:14:43 +02:00
BDFDB.LibraryRequires.request(ytlink, (error, response, result) => {
if (result) {
wrapper.innerHTML = `<div class="${BDFDB.disCNS.imagewrapper + BDFDB.disCNS.imageclickable + BDFDB.disCN.embedvideoimagecomponent}" style="width: 400px; height: 225px;"><img alt="" src="${result.split('<link itemprop="thumbnailUrl" href="')[1].split('"')[0]}" style="width: 400px; height: 225px;"></div><div class="${BDFDB.disCN.embedvideoactions}"><div class="${BDFDB.disCN.embedcentercontent}"><div class="${BDFDB.disCN.iconactionswrapper}"><div tabindex="0" class="${BDFDB.disCNS.iconwrapper + BDFDB.disCN.iconwrapperactive}" role="button"><svg name="Play" class="${BDFDB.disCNS.iconplay + BDFDB.disCN.icon}" width="16" height="16" viewBox="0 0 24 24"><polygon fill="currentColor" points="0 0 0 14 11 7" transform="translate(7 5)"></polygon></svg></div><a class="${BDFDB.disCNS.anchor + BDFDB.disCNS.anchorunderlineonhover + BDFDB.disCNS.iconwrapper + BDFDB.disCN.iconwrapperactive}" href="${ytlink}" rel="noreferrer noopener" target="_blank"><svg name="OpenExternal" class="${BDFDB.disCNS.iconexternalmargins + BDFDB.disCN.icon}" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" transform="translate(3.000000, 4.000000)" d="M16 0H2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h4v-2H2V4h14v10h-4v2h4c1.1 0 2-.9 2-2V2a2 2 0 0 0-2-2zM9 6l-4 4h3v6h2v-6h3L9 6z"></path></svg></a></div></div></div>`;
wrapper.querySelector(BDFDB.dotCN.iconplay).addEventListener("click", e => {this.startYoutubeVideo(e.currentTarget);});
2018-12-28 14:28:50 +01:00
}
});
}
}
2019-01-17 23:48:29 +01:00
messagedivider.querySelector(BDFDB.dotCN.messagespopoutchannelname).addEventListener("click", e => {
2019-10-22 18:55:25 +02:00
if (!BDFDB.ObjectUtils.isEmpty(channel)) {
notespopout.remove();
2019-09-11 12:14:43 +02:00
BDFDB.LibraryModules.SelectChannelUtils.selectChannel(server.id, channel.id);
}
else BDFDB.shake();
});
2019-01-17 23:48:29 +01:00
message.querySelector(BDFDB.dotCN.messagespopoutclosebutton).addEventListener("click", e => {
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(messagedivider, message);
this.removeNoteData(noteData);
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.toggle(placeholder, container.firstElementChild == placeholder);
});
2019-01-17 23:48:29 +01:00
message.querySelector(BDFDB.dotCN.messagespopoutjumpbutton + ".jump").addEventListener("click", e => {
2019-09-11 12:14:43 +02:00
BDFDB.LibraryModules.HistoryUtils.transitionTo(BDFDB.DiscordConstants.Routes.CHANNEL(noteData.guild_id, noteData.channel_id, noteData.id));
});
2019-01-17 23:48:29 +01:00
message.querySelector(BDFDB.dotCN.messagespopoutjumpbutton + ".copy").addEventListener("click", e => {
2019-02-03 19:02:15 +01:00
if (noteData.content) {
let text = noteData.content;
for (let file of message.querySelectorAll(BDFDB.dotCN.filenamelink)) text += ("\n" + file.href);
2019-09-11 12:14:43 +02:00
BDFDB.LibraryRequires.electron.clipboard.write({text});
2019-02-03 19:02:15 +01:00
}
else {
let image = message.querySelector(BDFDB.dotCNS.imagewrapper + "img");
2019-09-11 12:14:43 +02:00
if (image) BDFDB.LibraryRequires.request({url: image.src, encoding: null}, (error, response, buffer) => {
2019-02-03 19:02:15 +01:00
if (buffer) {
2019-09-11 12:14:43 +02:00
if (BDFDB.LibraryRequires.process.platform === "win32" || BDFDB.LibraryRequires.process.platform === "darwin") {
BDFDB.LibraryRequires.electron.clipboard.write({image: BDFDB.LibraryRequires.electron.nativeImage.createFromBuffer(buffer)});
}
2019-02-03 19:02:15 +01:00
else {
2019-09-11 12:14:43 +02:00
let file = BDFDB.LibraryRequires.path.join(BDFDB.LibraryRequires.process.env["HOME"], "personalpinstemp.png");
BDFDB.LibraryRequires.fs.writeFileSync(file, buffer, {encoding: null});
BDFDB.LibraryRequires.electron.clipboard.write({image: file});
BDFDB.LibraryRequires.fs.unlinkSync(file);
2019-02-03 19:02:15 +01:00
}
}
});
}
});
}
2019-01-26 22:45:19 +01:00
startYoutubeVideo (button) {
2019-10-23 11:10:01 +02:00
let embedwrapper = BDFDB.DOMUtils.getParent(BDFDB.dotCN.embedvideo, button);
let ytlink = embedwrapper.parentElement.querySelector(BDFDB.dotCN.embedtitle).href;
2019-09-11 12:14:43 +02:00
BDFDB.LibraryRequires.request(ytlink, (error, response, result) => {
if (result && response.headers && typeof response.headers.server == "string" && response.headers.server.toUpperCase() == "YOUTUBE FRONTEND PROXY") {
while (embedwrapper.firstChild) embedwrapper.firstChild.remove();
let width = 400;
let height = Math.round(width*(result.split('<meta itemprop="height" content="')[1].split('"')[0]/result.split('<meta itemprop="width" content="')[1].split('"')[0]));
2019-10-23 11:10:01 +02:00
embedwrapper.appendChild(BDFDB.DOMUtils.create(`<iframe src="${result.split('<link itemprop="embedURL" href="')[1].split('"')[0]}?start=0&amp;autoplay=1&amp;auto_play=1" width="${width}" height="${height}" frameborder="0" allowfullscreen=""></iframe>`));
}
});
}
2019-01-26 22:45:19 +01:00
addMessageToNotes (message, target, channel) {
if (!message || !target) return;
let {messagediv, pos} = this.getMessageAndPos(target);
if (!messagediv || pos == -1) return;
2019-10-22 19:49:57 +02:00
let pins = BDFDB.DataUtils.load(this, "pins");
2019-09-11 12:14:43 +02:00
let guild = BDFDB.LibraryModules.GuildStore.getGuild(channel.guild_id) || {};
let guild_id = guild.id ? guild.id : "@me";
2019-09-11 12:14:43 +02:00
channel = channel ? channel : BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
pins[guild_id] = pins[guild_id] || {}
pins[guild_id][channel.id] = pins[guild_id][channel.id] || {}
if (!pins[guild_id][channel.id][message.id + "_" + pos]) {
2019-02-03 19:02:15 +01:00
for (let spoiler of messagediv.querySelectorAll(BDFDB.dotCN.spoilerhidden)) spoiler.click();
let channelname = channel.name;
if (!channelname && channel.recipients.length > 0) {
for (let dmuser_id of channel.recipients) {
channelname = channelname ? channelname + ", @" : channelname;
2019-09-11 12:14:43 +02:00
channelname = channelname + BDFDB.LibraryModules.UserStore.getUser(dmuser_id).username;
2018-12-28 14:28:50 +01:00
}
}
2019-10-22 18:55:25 +02:00
pins[guild_id][channel.id][message.id + "_" + pos] = BDFDB.ObjectUtils.sort({
"guild_id": guild_id,
"guild_name": guild.name ? guild.name : "Direct Messages",
"channel_id": channel.id,
"channel_name": channelname,
"dmuser_id": channel.type == 1 ? channel.recipients[0] : null,
"id": message.id,
"pos": pos,
"timestamp": message.timestamp._i.getTime(),
"addedat": new Date().getTime(),
"color": message.colorString,
"author_id": message.author.id,
"author_name": message.author.username,
2019-10-22 18:55:25 +02:00
"avatar": BDFDB.UserUtils.getAvatar(message.author.id),
"content": message.content,
2019-09-03 12:37:14 +02:00
"markup": this.getMarkup(messagediv).innerHTML,
"accessory": messagediv.querySelector(BDFDB.dotCN.messageaccessory).innerHTML
});
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.save(pins, this, "pins");
2019-10-22 18:55:25 +02:00
BDFDB.NotificationUtils.toast(this.labels.toast_noteadd_text, {type:"success"});
2018-12-28 14:28:50 +01:00
}
else this.removeNoteData(pins[guild_id][channel.id][message.id + "_" + pos]);
2018-12-28 14:28:50 +01:00
}
2019-09-04 12:34:02 +02:00
2019-09-03 12:37:14 +02:00
updateNoteData (note, markup, accessory) {
2019-10-22 19:49:57 +02:00
let pins = BDFDB.DataUtils.load(this, "pins");
2019-09-03 12:37:14 +02:00
pins[note.guild_id][note.channel_id][note.id + "_" + note.pos].markup = markup;
pins[note.guild_id][note.channel_id][note.id + "_" + note.pos].accessory = accessory;
2019-10-22 18:55:25 +02:00
pins[note.guild_id][note.channel_id][note.id + "_" + note.pos] = BDFDB.ObjectUtils.sort(pins[note.guild_id][note.channel_id][note.id + "_" + note.pos]);
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.save(pins, this, "pins");
2019-10-22 18:55:25 +02:00
BDFDB.NotificationUtils.toast(this.labels.toast_noteupdate_text, {type:"info"});
2019-09-03 12:37:14 +02:00
}
2019-09-04 12:34:02 +02:00
2019-09-03 12:37:14 +02:00
getMarkup (messagediv) {
let markup = messagediv.querySelector(BDFDB.dotCN.messagemarkup).cloneNode(true);
markup.querySelectorAll(BDFDB.dotCN.messageheadercompact).forEach(h2 => {h2.remove();});
return markup;
}
2019-01-26 22:45:19 +01:00
getNoteData (message, target, channel) {
if (!message || !target) return;
let {messagediv, pos} = this.getMessageAndPos(target);
if (!messagediv || pos == -1) return;
2019-09-11 12:14:43 +02:00
channel = channel ? channel : BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
2019-10-22 19:49:57 +02:00
let pins = BDFDB.DataUtils.load(this, "pins");
let guildid = channel.guild_id ? channel.guild_id : "@me";
return pins[guildid] && pins[guildid][channel.id] && pins[guildid][channel.id][message.id + "_" + pos] ? pins[guildid][channel.id][message.id + "_" + pos] : null;
}
2019-01-26 22:45:19 +01:00
removeNoteData (noteData) {
2019-10-22 19:49:57 +02:00
let pins = BDFDB.DataUtils.load(this, "pins");
delete pins[noteData.guild_id][noteData.channel_id][noteData.id + "_" + noteData.pos];
2019-10-22 18:55:25 +02:00
if (BDFDB.ObjectUtils.isEmpty(pins[noteData.guild_id][noteData.channel_id])) {
delete pins[noteData.guild_id][noteData.channel_id];
2019-10-22 18:55:25 +02:00
if (BDFDB.ObjectUtils.isEmpty(pins[noteData.guild_id])) delete pins[noteData.guild_id];
2018-12-28 14:28:50 +01:00
}
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.save(pins, this, "pins");
2019-10-22 18:55:25 +02:00
BDFDB.NotificationUtils.toast(this.labels.toast_noteremove_text, {type:"danger"});
2018-12-28 14:28:50 +01:00
}
2019-09-11 12:14:43 +02:00
getMessageAndPos (target) {
2019-11-08 14:36:57 +01:00
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.messagegroup + "> [aria-disabled]," + BDFDB.dotCN.messagegroup + "> * > [aria-disabled]", target);
2019-09-11 12:14:43 +02:00
let pos = messagediv ? Array.from(messagediv.parentElement.childNodes).filter(n => n.nodeType != Node.TEXT_NODE).indexOf(messagediv) : -1;
return {messagediv, pos};
}
2019-01-26 22:45:19 +01:00
2018-12-28 14:28:50 +01:00
setLabelsByLanguage () {
2019-10-24 11:47:57 +02:00
switch (BDFDB.LanguageUtils.getLanguage().id) {
2018-12-28 14:28:50 +01:00
case "hr": //croatian
return {
popout_note_text: "Bilješke",
popout_channel_text: "Kanal",
popout_server_text: "Poslužavnik",
popout_allservers_text: "Svi poslužitelji",
popout_sort_text: "Poredaj po",
popout_messagesort_text: "Vijesti-Datum",
popout_datesort_text: "Bilješka-Datum",
context_pinoption_text: "Napominjemo poruku",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Ažuriraj bilješku",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Uklonite bilješku",
popout_pinoption_text: "Bilješka",
toast_noteadd_text: "Poruka dodana u bilježnicu.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Poruka je ažurirana u bilježnici.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Poruka uklonjena iz bilježnice."
};
case "da": //danish
return {
popout_note_text: "Noter",
popout_channel_text: "Kanal",
popout_server_text: "Server",
popout_allservers_text: "Alle servere",
popout_sort_text: "Sorter efter",
popout_messagesort_text: "Meddelelse-Dato",
popout_datesort_text: "Note-Dato",
context_pinoption_text: "Noter besked",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Opdater note",
context_unpinoption_text: "Fjern note",
2018-12-28 14:28:50 +01:00
popout_pinoption_text: "Noter",
toast_noteadd_text: "Meddelelse tilføjet til notesbog.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Meddelelse opdateret i den notesbog.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Meddelelse fjernet fra notesbog."
};
case "de": //german
return {
popout_note_text: "Notizen",
popout_channel_text: "Kanal",
popout_server_text: "Server",
popout_allservers_text: "Alle Server",
popout_sort_text: "Sortieren nach",
popout_messagesort_text: "Nachrichten-Datum",
popout_datesort_text: "Notiz-Datum",
context_pinoption_text: "Nachricht notieren",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Notiz aktualisieren",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Notiz entfernen",
popout_pinoption_text: "Notieren",
toast_noteadd_text: "Nachricht zum Notizbuch hinzugefügt.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Nachricht im Notizbuch aktualisiert.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Nachricht aus dem Notizbuch entfernt."
};
case "es": //spanish
return {
popout_note_text: "Notas",
popout_channel_text: "Canal",
popout_server_text: "Servidor",
popout_allservers_text: "Todos los servidores",
popout_sort_text: "Ordenar por",
popout_messagesort_text: "Mensaje-Fecha",
popout_datesort_text: "Nota-Fecha",
context_pinoption_text: "Anotar mensaje",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Actualiza la nota",
context_unpinoption_text: "Eliminar la nota",
2018-12-28 14:28:50 +01:00
popout_pinoption_text: "Anotar",
toast_noteadd_text: "Mensaje agregado al cuaderno.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Mensaje actualizado en el cuaderno.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Mensaje eliminado del cuaderno."
};
case "fr": //french
return {
popout_note_text: "Notes",
popout_channel_text: "Canal",
popout_server_text: "Serveur",
popout_allservers_text: "Tous les serveurs",
popout_sort_text: "Trier par",
popout_messagesort_text: "Message-Date",
popout_datesort_text: "Note-Date",
context_pinoption_text: "Noter le message",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Mettre à jour la note",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Enlevez la note",
popout_pinoption_text: "Noter",
2019-09-03 12:37:14 +02:00
toast_noteadd_text: "Message ajouté au cahier.",
toast_noteupdate_text: "Message mis à jour dans le cahier.",
toast_noteremove_text: "Message supprimé du cahier."
2018-12-28 14:28:50 +01:00
};
case "it": //italian
return {
popout_note_text: "Note",
popout_channel_text: "Canale",
popout_server_text: "Server",
popout_allservers_text: "Tutti i server",
popout_sort_text: "Ordina per",
popout_messagesort_text: "Messaggio-Data",
popout_datesort_text: "Nota-Data",
context_pinoption_text: "Annotare il messaggio",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Aggiorna la nota",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Rimuovi la nota",
popout_pinoption_text: "Annotare",
toast_noteadd_text: "Messaggio aggiunto al blocco note.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Messaggio aggiornato nel blocco note.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Messaggio rimosso dal blocco note."
};
case "nl": //dutch
return {
popout_note_text: "Notities",
popout_channel_text: "Kanaal",
popout_server_text: "Server",
popout_allservers_text: "Alle servers",
popout_sort_text: "Sorteer op",
popout_messagesort_text: "Bericht-Datum",
popout_datesort_text: "Notitie-Datum",
context_pinoption_text: "Noteer bericht",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Update de notitie",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Verwijder de notitie",
popout_pinoption_text: "Noteer",
toast_noteadd_text: "Bericht toegevoegd aan notitieblok.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Bericht bijgewerkt in het notitieblok.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Bericht verwijderd van notitieblok."
};
case "no": //norwegian
return {
popout_note_text: "Notatene",
popout_channel_text: "Kanal",
popout_server_text: "Server",
popout_allservers_text: "Alle servere",
popout_sort_text: "Sorter etter",
popout_messagesort_text: "Melding-Dato",
popout_datesort_text: "Merknad-Dato",
context_pinoption_text: "Notat ned meldingen",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Oppdater notatet",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Fjern notatet",
popout_pinoption_text: "Notere",
toast_noteadd_text: "Melding lagt til i notisboken.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Melding oppdatert i notisbok.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Melding fjernet fra notatboken."
};
case "pl": //polish
return {
popout_note_text: "Notatki",
popout_channel_text: "Kanał",
popout_server_text: "Serwer",
popout_allservers_text: "Wszystkie serwery",
popout_sort_text: "Sortuj według",
popout_messagesort_text: "Wiadomość-Data",
popout_datesort_text: "Notatka-Data",
context_pinoption_text: "Notuj wiadomość",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Zaktualizuj notatkę",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Usuń notatkę",
popout_pinoption_text: "Notuj",
toast_noteadd_text: "Wiadomość została dodana do notatnika.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Wiadomość zaktualizowana w notatniku.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Wiadomość została usunięta z notatnika."
};
case "pt-BR": //portuguese (brazil)
return {
popout_note_text: "Notas",
popout_channel_text: "Canal",
popout_server_text: "Servidor",
popout_allservers_text: "Todos os servidores",
popout_sort_text: "Ordenar por",
popout_messagesort_text: "Mensagem-Data",
popout_datesort_text: "Nota-Data",
context_pinoption_text: "Anote a mensagem",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Atualize a nota",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Remova a nota",
popout_pinoption_text: "Anotar",
toast_noteadd_text: "Mensagem adicionada ao caderno.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Mensagem atualizada no caderno.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Mensagem removida do caderno."
};
case "fi": //finnish
return {
popout_note_text: "Muistiinpanot",
popout_channel_text: "Kanava",
popout_server_text: "Palvelin",
popout_allservers_text: "Kaikki palvelimet",
popout_sort_text: "Järjestä",
popout_messagesort_text: "Viesti-Päivämäärä",
popout_datesort_text: "Huomaa-Päivämäärä",
context_pinoption_text: "Huomaa viesti",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Päivitä muistiinpano",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Poista muistiinpano",
popout_pinoption_text: "Huomaa",
toast_noteadd_text: "Viesti lisätty muistikirjaan.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Viesti päivitetty muistikirjaan.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Viesti poistettiin muistikirjaan."
};
case "sv": //swedish
return {
popout_note_text: "Anteckningarna",
popout_channel_text: "Kanal",
popout_server_text: "Server",
popout_allservers_text: "Alla servrar",
popout_sort_text: "Sortera efter",
popout_messagesort_text: "Meddelande-Datum",
popout_datesort_text: "Anteckningen-Datum",
context_pinoption_text: "Anteckna meddelande",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Uppdatera noten",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Ta bort noten",
popout_pinoption_text: "Anteckna",
toast_noteadd_text: "Meddelandet läggs till i anteckningsboken.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Meddelandet uppdateras i anteckningsboken.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Meddelande borttaget från anteckningsboken."
};
case "tr": //turkish
return {
popout_note_text: "Notlar",
popout_channel_text: "Kanal",
popout_server_text: "Sunucu",
popout_allservers_text: "Tüm Sunucular",
popout_sort_text: "Göre sırala",
popout_messagesort_text: "Mesaj-Tarih",
popout_datesort_text: "Not-Tarih",
context_pinoption_text: "Mesajı not alın",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Notu güncelle",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Notu kaldırmak",
popout_pinoption_text: "Not almak",
toast_noteadd_text: "Mesaj not defteri'ya eklendi.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Mesaj defterde güncellendi.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Mesaj not defteri'dan kaldırıldı."
};
case "cs": //czech
return {
popout_note_text: "Poznámky",
popout_channel_text: "Kanál",
popout_server_text: "Server",
popout_allservers_text: "Všechny servery",
popout_sort_text: "Seřazeno podle",
popout_messagesort_text: "Zpráva-datum",
popout_datesort_text: "Poznámka-datum",
context_pinoption_text: "Poznámka dolů zprávu",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Aktualizujte poznámku",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Odstraňte poznámku",
popout_pinoption_text: "Poznámka dolů",
toast_noteadd_text: "Zpráva byla přidána do notebooku.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Zpráva byla v notebooku aktualizována.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Zpráva byla odebrána z notebooku."
};
case "bg": //bulgarian
return {
popout_note_text: "бележките",
popout_channel_text: "Канал",
popout_server_text: "Сървър",
popout_allservers_text: "Всички сървъри",
popout_sort_text: "Сортиране по",
popout_messagesort_text: "Съобщение-Дата",
popout_datesort_text: "Забележка-Дата",
context_pinoption_text: "Oтбележете съобщението",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Актуализирайте бележката",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Премахнете бележката",
popout_pinoption_text: "Oтбележете",
toast_noteadd_text: "Съобщението бе добавено към бележника.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Съобщението е актуализирано в бележника.",
toast_noteremove_text: "Съобщението е премахнато от преносимия бележника."
2018-12-28 14:28:50 +01:00
};
case "ru": //russian
return {
popout_note_text: "Заметки",
popout_channel_text: "Канал",
popout_server_text: "Cервер",
popout_allservers_text: "Все серверы",
popout_sort_text: "Сортировать по",
popout_messagesort_text: "Сообщение-дата",
popout_datesort_text: "Заметки-Дата",
context_pinoption_text: "Записывать вниз",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Обновить заметку",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Удалить заметку",
popout_pinoption_text: "Записывать",
toast_noteadd_text: "Сообщение добавлено в блокнот.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Сообщение обновлено в записной блокнот.",
toast_noteremove_text: "Сообщение удалено из записной блокнот."
2018-12-28 14:28:50 +01:00
};
case "uk": //ukrainian
return {
popout_note_text: "Замітки",
popout_channel_text: "Канал",
popout_server_text: "Сервер",
popout_allservers_text: "Всі сервери",
popout_sort_text: "Сортувати за",
popout_messagesort_text: "Повідомлення-дата",
popout_datesort_text: "Примітка-дата",
context_pinoption_text: "Зверніть увагу на повідомлення",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Оновіть нотатку",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Видаліть нотатку",
popout_pinoption_text: "Занотуйте",
toast_noteadd_text: "Повідомлення додається до ноутбука.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Повідомлення оновлено в ноутбука.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Повідомлення видалено з ноутбука."
};
case "ja": //japanese
return {
popout_note_text: "ノート",
popout_channel_text: "チャネル",
popout_server_text: "サーバ",
popout_allservers_text: "すべてのサーバー",
popout_sort_text: "並び替え",
popout_messagesort_text: "メッセージ-日付",
popout_datesort_text: "注-日付",
context_pinoption_text: "ノートダウンメッセージ",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "メモを更新する",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "メモを削除",
popout_pinoption_text: "書き留める",
toast_noteadd_text: "ノートブックにメッセージが追加されました.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "ノートブックで更新されたメッセージ.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "ノートブックからメッセージが削除されました."
};
case "zh-TW": //chinese (traditional)
return {
popout_note_text: "筆記",
popout_channel_text: "渠道",
popout_server_text: "服務器",
popout_allservers_text: "所有服務器",
popout_sort_text: "排序方式",
popout_messagesort_text: "消息-日期",
popout_datesort_text: "注-日期",
context_pinoption_text: "記下下來的消息",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "更新說明",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "刪除備註",
popout_pinoption_text: "記下",
toast_noteadd_text: "消息添加到筆記本.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "消息在筆記本中更新.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "消息從筆記本中刪除."
};
case "ko": //korean
return {
popout_note_text: "노트",
popout_channel_text: "채널",
popout_server_text: "섬기는 사람",
popout_allservers_text: "모든 서버",
popout_sort_text: "정렬 기준",
popout_messagesort_text: "메시지-날짜",
popout_datesort_text: "주-날짜",
context_pinoption_text: "메모 다운 메시지",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "메모 업데이트",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "메모 삭제",
popout_pinoption_text: "메모하다",
toast_noteadd_text: "노트북에 메시지 추가됨.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "노트북에서 메시지가 업데이트되었습니다.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "노트에서 메시지 삭제됨."
};
default: //default: english
return {
popout_note_text: "Notes",
popout_channel_text: "Channel",
popout_server_text: "Server",
popout_allservers_text: "All Servers",
popout_sort_text: "Sort by",
popout_messagesort_text: "Message-Date",
popout_datesort_text: "Note-Date",
context_pinoption_text: "Note Message",
2019-09-03 12:37:14 +02:00
context_updateoption_text: "Update Note",
2018-12-28 14:28:50 +01:00
context_unpinoption_text: "Remove Note",
popout_pinoption_text: "Note",
toast_noteadd_text: "Message added to notebook.",
2019-09-03 12:37:14 +02:00
toast_noteupdate_text: "Message updated in the notebook.",
2018-12-28 14:28:50 +01:00
toast_noteremove_text: "Message removed from notebook."
};
}
}
}