User:Phlip/monobook.js

From Homestar Runner Wiki

< User:Phlip
Revision as of 13:01, 18 March 2006 by Phlip (Talk | contribs)
Jump to: navigation, search

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

  • Mozilla / Firefox: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac)
  • Safari: press Cmd-Option-E
  • 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.
function getChildType(node,childtype,index)
{
  var c = node.childNodes;
  childtype = childtype.toLowerCase();
  for (var i = 0; i < c.length; i++)
  {
    if (c[i].tagName && childtype == c[i].tagName.toLowerCase())
    {
      index--;
      if (index <= 0) return c[i];
    }
  }
  return null;
}
function addValidateLink()
{
  // find the print footer, it has a canonical page URL in it
  // DON'T use window.location, as it can have tags like ?action=edit and things which will mess us up
  var a = document.getElementsByTagName('DIV');
  var pageUrl = ""
  for (var i = 0; i < a.length; i++)
  {
    if (a[i].className == "printfooter")
    {
      b = getChildType(a[i], "A", 1);
      if (b)
        pageUrl = b.href;
    }
  }

  // create the validation link
  a = document.getElementById('p-cactions');
  a = getChildType(a, 'ul', 1);
  li = document.createElement('li');
  li.id = 'ca-valid';
  li.style.marginLeft = "1.6em";
  a.appendChild(li);
  link = document.createElement('a');
  link.href = "http://validator.w3.org/check?uri=" + escape(pageUrl);
  // link.className = "external" // only works in #bodyContent
  link.style.color = "#06F";
  /* this messes up the margins and paddings, and breaks hover
  link.style.background = "url(/skins/monobook/external.png) center right no-repeat";
  link.style.paddingRight = "13px";
  link.style.marginRight = "0.8em"; // this used to be in the padding, but we need that for the icon
  link.style.marginLeft = "0.8em"; link.style.paddingLeft = "0"; // make symmetrical
  */
  li.appendChild(link);
  link.appendChild(document.createTextNode('Validate '));
  img = document.createElement('img');
  img.src = "/skins/monobook/external.png";
  link.appendChild(img);
}

// these two lines stolen from [[User:Tom/monobook.js]]
if (window.addEventListener) window.addEventListener("load",addValidateLink,false);
else if (window.attachEvent) window.attachEvent("onload",addValidateLink);

function killfakeusermessage()
{
  var a = document.getElementsByTagName('DIV');
  for (var i = 0; i < a.length; i++)
  {
    if (a[i].className == "usermessage")
    {
      b = getChildType(a[i], "A", 1);
      if (b && b.href != "/index.php/User_talk:Phlip")
        a[i].style.background = "inherit";
    }
  }
}