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

m (oops)
m (Fbstj moved page User:Fbstj/common.js to User:Fbstj/gadget/history-test.js without leaving a redirect)
 
(137 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.hook('wikipage.content').add(function revs_gadget() {
function A(url, text) {
const el = document.createElement('a')
el.setAttribute('href', url)
el.innerText = text
return el
}


const pageid = mw.config.get('wgArticleId')
/* add links to edit box */
const query = {
$(function () {
// request the history of this page

pageids: [pageid],
function link(url, text, title) {
prop: 'revisions',
const el = document.createElement('span')
// request the oldest edits first
const ln = A(url, text)
rvdir: 'newer',
ln.className = "oo-ui-inputWidget-input oo-ui-buttonElement-button"
// request as many as you can at once
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"
rvlimit: 'max',
el.appendChild(ln)
// properties to fetch:
el.setAttribute('title', title)
rvprop: [ 'ids', 'user', 'timestamp', 'size', 'tags', ],
return el
}
}
const api = new mw.Api({ parameters: query, })


api.get().then(function old_hist(resp) {
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(']'))
}


const page = resp.query.pages[pageid]
$(function () {
page.revisions.forEach(console.log)


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


})
})

Latest revision as of 19:54, 20 August 2019

mw.hook('wikipage.content').add(function revs_gadget() {

const pageid = mw.config.get('wgArticleId')
const query = {
  // request the history of this page
  pageids: [pageid],
  prop: 'revisions',
   // request the oldest edits first
   rvdir: 'newer',
   // request as many as you can at once
   rvlimit: 'max',
   // properties to fetch:
   rvprop: [ 'ids', 'user', 'timestamp', 'size', 'tags', ],
}
const api = new mw.Api({ parameters: query, })

api.get().then(function old_hist(resp) {

const page = resp.query.pages[pageid]
page.revisions.forEach(console.log)

})

})