add contextmenu patch removal

This commit is contained in:
Jiiks 2018-08-22 18:39:09 +03:00
parent b8dc9c0d25
commit 4c3659f857
2 changed files with 10 additions and 3 deletions

View File

@ -56,7 +56,7 @@ export default new class EmoteModule extends BuiltinModule {
GlobalAc.add(';', this);
// Add favourite button to context menu
DiscordContextMenu.add(target => [
this.removeFavCm = DiscordContextMenu.add('BD:EmoteModule:FavCM', target => [
{
text: 'Favourite',
type: 'toggle',
@ -96,6 +96,7 @@ export default new class EmoteModule extends BuiltinModule {
for (const patch of Patcher.getPatchesByCaller('BD:EMOTEMODULE')) patch.unpatch();
// Remove ; prefix from autocomplete
GlobalAc.remove(';');
if (this.removeFavCm) this.removeFavCm();
}
/**

View File

@ -35,12 +35,18 @@ export class DiscordContextMenu {
/**
* add items to Discord context menu
* @param {any} id unique id for group
* @param {any} items items to add
* @param {Function} [filter] filter function for target filtering
*/
static add(items, filter) {
static add(id, items, filter) {
if (!this.patched) this.patch();
this.menus.push({ items, filter });
this.menus.push({ id, items, filter });
return () => this.remove(id);
}
static remove(id) {
this._menus = this._menus.filter(menu => menu.id !== id);
}
static get menus() {