Difference between revisions of "User:Fbstj/gadget/history-test.js"
Jump to navigation
Jump to search
m (try this) |
m (try this) |
||
Line 17: | Line 17: | ||
}) |
}) |
||
+ | function check_for_arcanum() { |
||
⚫ | |||
− | $(function fetch_arcanum() {; |
||
const edit_box = document.querySelector('.editButtons'); |
const edit_box = document.querySelector('.editButtons'); |
||
// check that there is an edit box |
// check that there is an edit box |
||
− | if (!edit_box || mw.config.get('wgCanonicalNamespace') !== '') return 1; |
+ | if (!edit_box || mw.config.get('wgCanonicalNamespace') !== '') return -1; |
// check that it's a page creation |
// check that it's a page creation |
||
− | if (mw.config.get('wgArticleId') != 0) return 2; |
+ | if (mw.config.get('wgArticleId') != 0) return -2; |
// check that it's an Arcanum page |
// check that it's an Arcanum page |
||
const page_name = mw.config.get('wgPageName'); |
const page_name = mw.config.get('wgPageName'); |
||
− | if (!page_name.startsWith('Cite:Arcanum-')) return 3; |
+ | if (!page_name.startsWith('Cite:Arcanum-')) return -3; |
const entry = page_name.split('-')[1]; |
const entry = page_name.split('-')[1]; |
||
− | + | return 'https://wob.coppermind.net/api/entry/'+ entry +'/'; |
|
⚫ | |||
− | fetch(url).then(function(resp){return resp.json();}).then(function (json) {; |
||
⚫ | |||
− | // deal with response; |
||
− | console.log( |
+ | $(function () { console.log(check_for_arcanum()) }) |
− | console.log(json); |
||
− | }); |
||
− | |||
⚫ |
Revision as of 11:53, 22 June 2018
/* 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) }) function check_for_arcanum() { const edit_box = document.querySelector('.editButtons'); // check that there is an edit box if (!edit_box || mw.config.get('wgCanonicalNamespace') !== '') return -1; // check that it's a page creation if (mw.config.get('wgArticleId') != 0) return -2; // check that it's an Arcanum page const page_name = mw.config.get('wgPageName'); if (!page_name.startsWith('Cite:Arcanum-')) return -3; const entry = page_name.split('-')[1]; return 'https://wob.coppermind.net/api/entry/'+ entry +'/'; } /* auto-fill [[Cite: Arcanum-@entry]] pages*/ $(function () { console.log(check_for_arcanum()) })