Difference between revisions of "MediaWiki:Common.js"

Jump to navigation Jump to search
m (allow other redirectors)
m (move arcanum searcher to widget)
ModifySidebar( 'add', 'toolbox', "Search Brandon's website for " + title, 'https://brandonsanderson.com/?s='+ title );
ModifySidebar( 'add', 'toolbox', 'Search Arcanum for '+ title, 'https://wob.coppermind.net/adv_search/?query='+ title );
});
 
/* 2017-11: functions for generating links and buttons */
// make an <a> with a url and some text
function make_a(url, text) {
const el = document.createElement('a')
el.setAttribute('href', url)
el.innerText = text
return el
}
 
// make a nice link button for the edit box
function make_edit_button(url, text, title) {
// create link element
const ln = make_a(url, text)
ln.setAttribute('target', '_blank')
// create wrap element
const el = document.createElement('span')
el.setAttribute('title', title)
el.appendChild(ln)
// style elements
// FIXME: these are copied from the oo-ui elements in the edit box
ln.className = 'oo-ui-inputWidget-input oo-ui-buttonElement-button'
el.className = 'oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget'
// return element for insertion
return el
}
 
// create a link that looks like .editsection
function make_editsection_link(url) {
// generate an edit link
const ln = make_a(url, 'edit')
// wrap the link in an '.editsection' link floated right
const el = document.createElement('span')
el.className = 'mw-editsection'
el.style.float = 'right'
// push [] around the A element into the span
el.appendChild(document.createTextNode('['))
el.appendChild(ln)
el.appendChild(document.createTextNode(']'))
return el
}
 
/* add links to edit box */
$(function () {
 
const edit_box = document.querySelector('.editButtons')
// check that there is an edit box
if (!edit_box || mw.config.get('wgCanonicalNamespace') !== '') return
 
const page_name = mw.config.get('wgPageName').replace(/[_]/g, '+')
 
// add a link to the Arcanum
const wob_url = make_edit_button('https://wob.coppermind.net/adv_search/?query='+ page_name, 'Search Arcanum', 'Search Arcanum for "'+ page_name +'"')
edit_box.appendChild(wob_url)
 
});