User:Phlip/monobook.js

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
(no longer necessary)
(validate link)
Line 1: Line 1:
 +
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);
 +
      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);

Revision as of 01:48, 2 March 2006

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);
      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);
Personal tools