WikiaBartender is a utility script that enables an easier method of manipulating Fandom's WikiaBar.
Installation
Usage
Entrypoint
The script can be accessed in two ways:
- The returned object from the
dev.wikiaBarhook. This is the preferred method:
mw.hook("dev.wikiaBar").add(function(bartender) { /* your code here */ });
- The global
bartendernamespace underwindow.dev. Note that this may or may not be undefined, so the first option should be normally used, unless it isn't possible to do so for some reason:
const bartender = window.dev.bartender;
Static properties
More detailed documentation are located inside JSDoc comments within the script.
window.dev.bartender.isBarHidden: boolean- Returns a boolean for the current state of the bar (hidden or not).
window.dev.bartender.items: NodeListOf<HTMLLIElement>- Returns all the items in the toolbar in the form of a live NodeList.
window.dev.bartender.addItem(opts: {text: string, id: string, href?: string | "#", append?: Element, classes: string[]}, index: number): NodeListOf<HTMLLIElement>- Creates and appends a new item to the toolbar. An object is passed for the input argument. Options for it are as follows:
text: The text of the item.id: The ID applied to the item. This is made mandatory to prevent irresponsible element adding.href(optional): The href anchor (link) on the item. Defaults to#, which is just an empty anchor.append(optional): An HTML element to be appended to the item. Can be anything.classes(optional): Array of string(s) to be added as classes to the item.index(optional): At which index to insert the item to the toolbar. Usual JS index tricks works here. Will just append to the end if it's more than the index amount of the toolbar.
window.dev.bartender.removeItem(query: string): boolean- Removes an item from the toolbar using a simple query string.
Disabling
The script can be disabled by setting window.dev.bartender.disabled as early as possible (before the script loads). Note that this will also prevent methods on the window.dev.bartender namespace to be set, which will screw over other scripts utilizing it. Use this as needed, and don't override this if set before you.
Example
These examples assume that a constant called bartender is present in the context, see #Entrypoint for acquiring it.
- Get all list items
console.log( bartender.items );
- Check if the bar is hidden or not
console.log( bartender.isBarHidden() );
- Add a simple item
bartender.addItem({ text: "Hello world!" id: "wikiabaritem-helloworld" })
- Add a complex item
bartender.addItem({ text: "Hello world!" id: "wikiabaritem-helloworld" href: "#" append: Object.assign(document.createElement('img'), { src: '...' }) classes: ["lorem", "ipsum"] }, 0)
Dependents
See also
Text above can be found here (edit)