MediaWiki:Gadget-welcomer.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

try { // containerize gadget, to protect other gadgets if this one goes wrong

$(talklinkWelcomizer);
 
function talklinkWelcomizer() {
  mw.util.addCSS('a.welcometalklink {color:#ff00ff;font-weight:bold }');
//  mw.util.addCSS('ul.special li a[title ="Special:Contributions"] + a[title ^="User talk:"].new { color:#CC2200;font-weight:normal }');
  var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document.getElementById('mw-content') || document.body;
  var a = getElementsByClassName(docobj,'a','new');
  var utpat = /title\=[uU]ser_talk\:/;
  for(var i=0;i<a.length;i++) {
    var href = a[i].getAttribute('href',2);
    var frag = (href.indexOf('?') == -1) ? '?' : '&';
    if(utpat.test(href)) {
      a[i].setAttribute('href',href + frag + 'preload=MediaWiki:Gadget-welcomer-preload');
      a[i].className += " welcometalklink";
    }
  }
}

// with thanks to [[wikia:User:Splarka]]
// edit [[MediaWiki:Gadget-welcomer-preload]] to change the preload

} catch (e) { // containerize gadget, to protect other gadgets if this one goes wrong
  // ignore
}