Difference between revisions of "User:Fbstj/gadget/history-test.js"

From The Coppermind
Jump to navigation Jump to search
m (tweak)
m (fix editsections styling, add titles to buttons?)
Line 9: Line 9:
 
$(function () {
 
$(function () {
   
function link(url, text) {
+
function link(url, text, title) {
 
const el = document.createElement('span')
 
const el = document.createElement('span')
 
const ln = A(url, text)
 
const ln = A(url, text)
Line 15: Line 15:
 
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.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)
 
el.appendChild(ln)
  +
el.setAttribute('title', title)
 
return el
 
return el
 
}
 
}
Line 24: Line 25:
 
if (!edit_box || mw.config.get('wgCanonicalNamespace') !== "") return
 
if (!edit_box || mw.config.get('wgCanonicalNamespace') !== "") return
   
const wob_url = link('https://wob.coppermind.net/basic_search/?query='+ pagename, 'search Arcanum for "'+ pagename +'"')
+
const wob_url = link('https://wob.coppermind.net/basic_search/?query='+ pagename, 'Arcanum', 'search Arcanum for "'+ pagename +'"')
const book_url = link('http://search.coppermind.net/?search='+ pagename, 'search books for "'+ pagename +'"')
+
const book_url = link('http://search.coppermind.net/?search='+ pagename, 'book search' 'search books for "'+ pagename +'"')
 
edit_box.appendChild(wob_url)
 
edit_box.appendChild(wob_url)
 
edit_box.appendChild(book_url)
 
edit_box.appendChild(book_url)
Line 32: Line 33:
   
   
/* Add edit buttons to templates */
+
/* Add edit link to templates */
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?
Line 41: Line 42:
 
// generate an edit link
 
// generate an edit link
 
const a = A('/edit/Template:'+ id, 'edit')
 
const a = A('/edit/Template:'+ id, 'edit')
// wrap the link in an '.editSection' link floated right
+
// wrap the link in an '.editsection' link floated right
 
const float = document.createElement('span')
 
const float = document.createElement('span')
float.className = 'mw-editSection'
+
float.className = 'mw-editsection'
 
float.style.float = 'right'
 
float.style.float = 'right'
 
title.appendChild(float)
 
title.appendChild(float)
Line 54: Line 55:
 
$(function () {
 
$(function () {
   
document.querySelectorAll('.infobox,.navbar').forEach(add_editSection_link)
+
document.querySelectorAll('.infobox,.navbar').forEach(add_editsection_link)
 
if (!mw.config.get('wgIsArticle') || mw.config.get('wgCanonicalNamespace') !== '')
 
return;
 
if (mw.config.get('wgCategories').includes('Meta'))
 
return;
 
   
 
})
 
})

Revision as of 19:45, 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, 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.appendChild(ln)
 el.setAttribute('title', title)
 return el
}

const pagename = mw.config.get('wgPageName')

const edit_box = document.querySelector('.editButtons')
// check that there is an edit box
if (!edit_box || mw.config.get('wgCanonicalNamespace') !== "") return

const wob_url = link('https://wob.coppermind.net/basic_search/?query='+ pagename, 'Arcanum', 'search Arcanum for "'+ pagename +'"')
const book_url = link('http://search.coppermind.net/?search='+ pagename, 'book search' 'search books for "'+ pagename +'"')
edit_box.appendChild(wob_url)
edit_box.appendChild(book_url)

});


/* Add edit link to templates */
function add_editsection_link(box) {
 if (!box.id) return;
 // FIXME: what does this do?
 const id = box.id.replace(/\.(\d+)/, "%$1")
 // get the title element
 const title = box.querySelector('.title')
 // generate an edit link
 const a = A('/edit/Template:'+ id, '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 span
 float.appendChild(document.createTextNode('['))
 float.appendChild(a)
 float.appendChild(document.createTextNode(']'))
}

$(function () {

document.querySelectorAll('.infobox,.navbar').forEach(add_editsection_link)

})