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

From The Coppermind
Jump to navigation Jump to search
m (ooui buttons)
m (Fbstj moved page User:Fbstj/common.js to User:Fbstj/gadget/history-test.js without leaving a redirect)
 
(147 intermediate revisions by the same user not shown)
Line 1: Line 1:
  +
mw.hook('wikipage.content').add(function revs_gadget() {
/* add links to edit box */
 
$(function () {
 
   
  +
const pageid = mw.config.get('wgArticleId')
function A(url, text) {
 
const el = document.createElement('a')
+
const query = {
  +
// request the history of this page
el.setAttribute('href', url)
 
  +
pageids: [pageid],
el.innerText = text
 
  +
prop: 'revisions',
el.className = "oo-ui-inputWidget-input oo-ui-buttonElement-button"
 
  +
// request the oldest edits first
return el
 
  +
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, })
   
function wrap(kid) {
+
api.get().then(function old_hist(resp) {
const el = document.createElement('span')
 
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(kid)
 
return el
 
}
 
   
const pagename = mw.config.get('wgPageName')
+
const page = resp.query.pages[pageid]
  +
page.revisions.forEach(console.log)
   
 
})
const edit_box = document.querySelector('.editButtons')
 
const wob_url = A('https://wob.coppermind.net/basic_search/?query='+ pagename, 'search Arcanum for "'+ pagename +'"')
 
const book_url = A('http://search.coppermind.net/?search='+ pagename, 'search books for "'+ pagename +'"')
 
edit_box.appendChild(wrap(wob_url))
 
edit_box.appendChild(wrap(book_url))
 
   
});
+
})

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)

})

})