87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
/**
|
|
* BetterDiscord Menu Module
|
|
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
|
* All rights reserved.
|
|
* https://betterdiscord.net
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import { Utils } from 'common';
|
|
|
|
let items = 0;
|
|
|
|
const BdMenuItems = new class {
|
|
|
|
constructor() {
|
|
window.bdmenu = this;
|
|
|
|
this.items = [];
|
|
|
|
this.addSettingsSet('Internal', 'core', 'Core');
|
|
this.addSettingsSet('Internal', 'ui', 'UI');
|
|
this.addSettingsSet('Internal', 'emotes', 'Emotes');
|
|
|
|
this.add({category: 'Internal', contentid: 'css', text: 'CSS Editor'});
|
|
this.add({category: 'External', contentid: 'plugins', text: 'Plugins'});
|
|
this.add({category: 'External', contentid: 'themes', text: 'Themes'});
|
|
}
|
|
|
|
/**
|
|
* Adds an item to the menu.
|
|
* @param {Object} item The item to add to the menu
|
|
* @return {Object}
|
|
*/
|
|
add(item) {
|
|
if (this.items.includes(item)) return item;
|
|
|
|
item.id = items++;
|
|
item.contentid = item.contentid || (items++ + '');
|
|
item.active = false;
|
|
item.hidden = item.hidden || false;
|
|
item._type = item._type || 'button';
|
|
|
|
this.items.push(item);
|
|
return item;
|
|
}
|
|
|
|
/**
|
|
* Adds a settings set to the menu.
|
|
* @param {String} category The category to display this item under
|
|
* @param {SettingsSet} set The settings set to display when this item is active
|
|
* @param {String} text The text to display in the menu (optional)
|
|
* @return {Object} The item that was added
|
|
*/
|
|
addSettingsSet(category, set, text) {
|
|
return this.add({
|
|
category, set,
|
|
text: text || set.text
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Adds a Vue component to the menu.
|
|
* @param {String} category The category to display this item under
|
|
* @param {String} text The text to display in the menu
|
|
* @param {Object} component The Vue component to display when this item is active
|
|
* @return {Object} The item that was added
|
|
*/
|
|
addVueComponent(category, text, component) {
|
|
return this.add({
|
|
category, text, component
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Removes an item from the menu.
|
|
* @param {Object} item The item to remove from the menu
|
|
*/
|
|
remove(item) {
|
|
Utils.removeFromArray(this.items, item);
|
|
}
|
|
|
|
};
|
|
|
|
export { BdMenuItems };
|