Difference between revisions of "User:Fbstj/gadget/history-test.js"
Jump to navigation
Jump to search
m (rearange) |
m (try this) |
||
Line 26: | Line 26: | ||
edit_box.appendChild(wob_url) |
edit_box.appendChild(wob_url) |
||
edit_box.appendChild(book_url) |
edit_box.appendChild(book_url) |
||
+ | |||
+ | }); |
||
+ | |||
+ | |||
+ | /* Add edit buttons to templates */ |
||
+ | $(function () { |
||
+ | |||
+ | function edit_button(box) { |
||
+ | if (!box.id) return |
||
+ | // FIXME: what does this do? |
||
+ | const v = box.id.replace(/\.(\d+)/, "%$1") |
||
+ | // get the title element |
||
+ | const title = box.querySelector('.title') |
||
+ | // generate an edit link |
||
+ | const a = A('/edit/Template:'+ v, 'edit') |
||
+ | // wrap the link in an '.editSection' link floated right |
||
+ | const float = document.createElement('span') |
||
+ | float.className = 'mw-editSection' |
||
+ | float.style.float = 'right' |
||
+ | title.appendChild(float) |
||
+ | // push "[]" around the A element into the spantr |
||
+ | float.appendChild(document.createTextNode('[')) |
||
+ | float.appendChild(a) |
||
+ | float.appendChild(document.createTextNode(']') |
||
+ | } |
||
+ | |||
+ | // loop over all .infobox and .navbar elements to |
||
+ | const boxes = [...document.querySelectorAll('.infobox'), ...document.querySelectorAll('.navbar')] |
||
+ | for (const box of boxes) |
||
+ | edit_button(box) |
||
}); |
}); |
Revision as of 19:15, 21 November 2017
function A(url, text) { const el = document.createElement('a') el.setAttribute('href', url) el.innerText = text return el } /* add links to edit box */ $(function () { function link(url, text) { const el = document.createElement('span') const ln = A(url, text) 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" el.appendChild(ln) return el } const pagename = mw.config.get('wgPageName') const edit_box = document.querySelector('.editButtons') const wob_url = link('https://wob.coppermind.net/basic_search/?query='+ pagename, 'search Arcanum for "'+ pagename +'"') const book_url = link('http://search.coppermind.net/?search='+ pagename, 'search books for "'+ pagename +'"') edit_box.appendChild(wob_url) edit_box.appendChild(book_url) }); /* Add edit buttons to templates */ $(function () { function edit_button(box) { if (!box.id) return // FIXME: what does this do? const v = box.id.replace(/\.(\d+)/, "%$1") // get the title element const title = box.querySelector('.title') // generate an edit link const a = A('/edit/Template:'+ v, 'edit') // wrap the link in an '.editSection' link floated right const float = document.createElement('span') float.className = 'mw-editSection' float.style.float = 'right' title.appendChild(float) // push "[]" around the A element into the spantr float.appendChild(document.createTextNode('[')) float.appendChild(a) float.appendChild(document.createTextNode(']') } // loop over all .infobox and .navbar elements to const boxes = [...document.querySelectorAll('.infobox'), ...document.querySelectorAll('.navbar')] for (const box of boxes) edit_button(box) });