Difference between revisions of "User:Fbstj/gadget/history-test.js"
Jump to navigation
Jump to search
m (try this) |
m (Fbstj moved page User:Fbstj/common.js to User:Fbstj/gadget/history-test.js without leaving a redirect) |
||
(149 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | mw.hook('wikipage.content').add(function revs_gadget() { |
||
− | /* Add edit buttons to templates */ |
||
− | $(function () { |
||
⚫ | |||
− | function edit_button(i, v) { |
||
+ | const query = { |
||
− | if (!v) return v; |
||
+ | // request the history of this page |
||
− | v = v.replace(/\.(\d+)/, "%$1"); |
||
+ | pageids: [pageid], |
||
− | let a = "<a href='/edit/Template:" + v +"'>edit</a>"; |
||
+ | prop: 'revisions', |
||
− | $('.title', this).append("<span class='mw-editsection' style='float: right;' >[" + a + "]</span>"); |
||
+ | // 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) { |
||
− | $('.navbar').attr('id', edit_button); |
||
+ | const page = resp.query.pages[pageid] |
||
− | $('.infobox').attr('id', edit_button); |
||
+ | page.revisions.forEach(console.log) |
||
− | }) |
+ | }) |
− | |||
− | /* add links to edit box */ |
||
− | $(function () { |
||
− | |||
− | const A = (url, text) => { |
||
− | const el = document.createElement('a') |
||
− | el.setAttribute('href', url) |
||
− | el.innerText = text |
||
− | return el |
||
− | } |
||
− | |||
⚫ | |||
− | |||
− | const edit_box = document.querySelector('.editButtons') |
||
− | edit_box.appendChild(A('https://wob.coppermind.net/basic_search/?query='+ pagename, 'search Arcanum for "'+ pagename +'"')) |
||
− | edit_box.appendChild(A('http://search.coppermind.net/?search='+ pagename, 'search books for "'+ pagename +'"')) |
||
}) |
}) |
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) }) })