User:Emma/common.js: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
mNo edit summary
m (Script finished, clearing page.)
 
(57 intermediate revisions by the same user not shown)
Line 1: Line 1:
addOnloadHook(gotNewMessages);
function gotNewMessages() {
  var um = getElementsByClassName(document.getElementById('bodyContent'),'div','usermessage');
  if(um.length == 0) return
  var links = um[0].getElementsByTagName('a');
  for(var i=0;i<links.length;i++) {
    if(links[i].href.indexOf('diff=cur') != -1) {
      var penultimate = links[i].href;
    }
  }
  var mytalk = document.getElementById('pt-mytalk');
  if(!mytalk) return


  mytalk.style.fontWeight = 'bold';
  var img = 'http://zeldadungeon.net/wiki/thumb.php?f=Triforce_(Ocarina_of_Time).png&w=13';
  if(penultimate) {
    /* add a linked icon if the message contains a diff=cur */
    var plink = document.createElement('a');
    plink.setAttribute('href',penultimate);
    plink.setAttribute('title','diff to last change');
    var pimg = document.createElement('img');
    pimg.setAttribute('src',img);
    pimg.style.width = '13px';
    pimg.style.height = '13px';
    pimg.style.marginLeft = '5px';
    plink.appendChild(pimg);
    plink.appendChild(document.createTextNode(' '));
    mytalk.appendChild(plink);
  } else {
    mytalk.style.background = 'transparent url("' + img + '") no-repeat center right';
    mytalk.style.paddingRight = '16px';
  }
}

Latest revision as of 13:01, March 19, 2017