User:Fbstj/gadget/history-test.js

From The Coppermind
< User:Fbstj
Revision as of 18:42, 21 November 2017 by Fbstj (talk | contribs) (try this)
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Add edit buttons to templates */
$(function () {

function edit_button(i, v) {
  if (!v) return v;
  v = v.replace(/\.(\d+)/, "%$1");
  let a = "<a href='/edit/Template:" + v +"'>edit</a>";
  $('.title', this).append("<span class='mw-editsection' style='float: right;' >[" + a + "]</span>");
}

$('.navbar').attr('id', edit_button);

$('.infobox').attr('id', edit_button);

});

/* 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 pagename = mw.config.get('wgPageName')

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 +'"'))

})