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

From The Coppermind
Jump to navigation Jump to search
m (tweak)
m (Fbstj moved page User:Fbstj/common.js to User:Fbstj/gadget/history-test.js without leaving a redirect)
 
(136 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 edit_box = document.querySelector('.editButtons')
+
const pageid = mw.config.get('wgArticleId')
  +
const query = {
// check that there is an edit box
 
  +
// request the history of this page
if (!edit_box || mw.config.get('wgCanonicalNamespace') !== '') return
 
  +
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_name = mw.config.get('wgPageName')
 
   
  +
const page = resp.query.pages[pageid]
const wob_url = make_edit_button('https://wob.coppermind.net/basic_search/?query='+ page_name, 'Arcanum?', 'Search Arcanum for "'+ page_name +'"')
 
  +
page.revisions.forEach(console.log)
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)
 
   
 
})
 
})

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)

})

})