Difference between revisions of "User:Fbstj/gadget/history-test.js"
Jump to navigation
Jump to search
m (oops) |
m (tweak) |
||
Line 1: | Line 1: | ||
⚫ | |||
− | const el = document.createElement('a') |
||
− | el.setAttribute('href', url) |
||
− | el.innerText = text |
||
− | return el |
||
− | } |
||
− | |||
/* add links to edit box */ |
/* add links to edit box */ |
||
$(function () { |
$(function () { |
||
− | |||
− | function link(url, text, title) { |
||
− | 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.setAttribute('title', title) |
||
− | return el |
||
− | } |
||
− | |||
⚫ | |||
const edit_box = document.querySelector('.editButtons') |
const edit_box = document.querySelector('.editButtons') |
||
// check that there is an edit box |
// check that there is an edit box |
||
− | if (!edit_box || mw.config.get('wgCanonicalNamespace') !== |
+ | if (!edit_box || mw.config.get('wgCanonicalNamespace') !== '') return |
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
edit_box.appendChild(wob_url) |
edit_box.appendChild(wob_url) |
||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}); |
}); |
||
⚫ | |||
⚫ | |||
⚫ | |||
function add_editsection_link(box) { |
function add_editsection_link(box) { |
||
if (!box.id) return; |
if (!box.id) return; |
||
// FIXME: what does this do? |
// FIXME: what does this do? |
||
− | const id = box.id.replace(/\.(\d+)/, |
+ | const id = box.id.replace(/\.(\d+)/, '%$1') |
⚫ | |||
⚫ | |||
// get the title element |
// get the title element |
||
const title = box.querySelector('.title') |
const title = box.querySelector('.title') |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | // 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 span |
||
− | float.appendChild(document.createTextNode('[')) |
||
− | float.appendChild(a) |
||
− | float.appendChild(document.createTextNode(']')) |
||
} |
} |
||
− | |||
− | $(function () { |
||
document.querySelectorAll('.infobox,.navbar').forEach(add_editsection_link) |
document.querySelectorAll('.infobox,.navbar').forEach(add_editsection_link) |
Revision as of 20:12, 21 November 2017
/* 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') const wob_url = make_edit_button('https://wob.coppermind.net/basic_search/?query='+ page_name, 'Arcanum?', 'Search Arcanum for "'+ page_name +'"') edit_box.appendChild(wob_url) const booksearch_url = make_edit_button('http://search.coppermind.net/?search='+ page_name, 'book search', 'Search books for "'+ page_name +'"') edit_box.appendChild(booksearch_url) }); /* Add edit link to templates */ $(function () { function add_editsection_link(box) { if (!box.id) return; // FIXME: what does this do? const id = box.id.replace(/\.(\d+)/, '%$1') // generate an edit link const el = make_editsection_link('/edit/Template:'+ id) // get the title element const title = box.querySelector('.title') title.appendChild(el) } document.querySelectorAll('.infobox,.navbar').forEach(add_editsection_link) })