User:Phlip/cologneblue.js

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
m (oops, didn't mean to leave those there...)
(I miss these from monobook)
Line 51: Line 51:
   img.src = "/skins/monobook/external.png";
   img.src = "/skins/monobook/external.png";
   link.appendChild(img);
   link.appendChild(img);
 +
 +
  ///////////////////////
 +
  // Add links to the content page and the talk page in the top bar
 +
  ///////////////////////
 +
  pageName = pageUrl.substr(32); // "http://www.hrwiki.org/index.php/".length == 32
 +
  i = pageName.indexOf(':');
 +
  if (i < 0)
 +
  {
 +
    namespace = '';
 +
    talknamespace = 'Talk:';
 +
    istalk = 0;
 +
  }
 +
  else
 +
  {
 +
    namespace = pageName.substring(0,i+1);
 +
    pageName = pageName.substring(i+1);
 +
    if (namespace == 'Talk:')
 +
    {
 +
      namespace = '';
 +
      talknamespace = 'Talk:';
 +
      istalk = 1;
 +
    }
 +
    else if (namespace.substring(namespace.length - 6) == '_talk:')
 +
    {
 +
      talknamespace = namespace;
 +
      namespace = namespace.substring(0,namespace.length - 6) + ':';
 +
      istalk = 1;
 +
    }
 +
    else
 +
    {
 +
      talknamespace = namespace.substring(0,namespace.length - 1) + '_talk:';
 +
      istalk = 0;
 +
    }
 +
  }
 +
  where = document.getElementById('langlinks');
 +
  before = where.getElementsByTagName('br');
 +
  before = before[before.length - 1];
 +
  before = before.nextSibling;
 +
 +
  a = document.createElement('a');
 +
  a.href = 'http://www.hrwiki.org/index.php/' + namespace + pageName;
 +
  a.appendChild(document.createTextNode('page'));
 +
  if (!istalk) a.style.fontWeight = 'bolder';
 +
  where.insertBefore(a, before);
 +
  where.insertBefore(document.createTextNode(' | '), before);
 +
 +
  a = document.createElement('a');
 +
  a.href = 'http://www.hrwiki.org/index.php/' + talknamespace + pageName;
 +
  a.appendChild(document.createTextNode('talk'));
 +
  if (istalk) a.style.fontWeight = 'bolder';
 +
  where.insertBefore(a, before);
 +
  where.insertBefore(document.createTextNode(' | '), before);
   ///////////////////////
   ///////////////////////

Revision as of 21:32, 27 April 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;
  */
  a = node.getElementsByTagName(childtype);
  if (a.length >= index)
    return a[index - 1];
  else
    return null;
}

function dostuff()
{
  ///////////////////////
  // Add a "Validate link to the sidebar
  ///////////////////////
  // 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], "P", 1);
      if (b) b = getChildType(b, "A", 1);
      if (b)
        pageUrl = b.href;
    }
  }

  // create the validation link
  a = document.getElementById('quickbar');
  link = document.createElement('a');
  link.href = "http://validator.w3.org/check?uri=" + escape(pageUrl);
  a.appendChild(link);
  a.appendChild(document.createElement('br'));
  link.appendChild(document.createTextNode('Validate '));
  img = document.createElement('img');
  img.src = "/skins/monobook/external.png";
  link.appendChild(img);

  ///////////////////////
  // Add links to the content page and the talk page in the top bar
  ///////////////////////
  pageName = pageUrl.substr(32); // "http://www.hrwiki.org/index.php/".length == 32
  i = pageName.indexOf(':');
  if (i < 0)
  {
    namespace = '';
    talknamespace = 'Talk:';
    istalk = 0;
  }
  else
  {
    namespace = pageName.substring(0,i+1);
    pageName = pageName.substring(i+1);
    if (namespace == 'Talk:')
    {
      namespace = '';
      talknamespace = 'Talk:';
      istalk = 1;
    }
    else if (namespace.substring(namespace.length - 6) == '_talk:')
    {
      talknamespace = namespace;
      namespace = namespace.substring(0,namespace.length - 6) + ':';
      istalk = 1;
    }
    else
    {
      talknamespace = namespace.substring(0,namespace.length - 1) + '_talk:';
      istalk = 0;
    }
  }
  where = document.getElementById('langlinks');
  before = where.getElementsByTagName('br');
  before = before[before.length - 1];
  before = before.nextSibling;

  a = document.createElement('a');
  a.href = 'http://www.hrwiki.org/index.php/' + namespace + pageName;
  a.appendChild(document.createTextNode('page'));
  if (!istalk) a.style.fontWeight = 'bolder';
  where.insertBefore(a, before);
  where.insertBefore(document.createTextNode(' | '), before);

  a = document.createElement('a');
  a.href = 'http://www.hrwiki.org/index.php/' + talknamespace + pageName;
  a.appendChild(document.createTextNode('talk'));
  if (istalk) a.style.fontWeight = 'bolder';
  where.insertBefore(a, before);
  where.insertBefore(document.createTextNode(' | '), before);

  ///////////////////////
  // Add Show Logs and Count Edits on user pages
  ///////////////////////
  // find the "Email user" link
  quickbar = document.getElementById('quickbar');
  emailuser = 0;
  for (i = 0; i < quickbar.childNodes.length; i++)
  {
    if (quickbar.childNodes[i].tagName == "A")
    {
      if (quickbar.childNodes[i].href.indexOf("Special:Emailuser") >= 0)
      {
        emailuser = quickbar.childNodes[i];
        break;
      }
    }
  }

  if (emailuser)
  {
    // we're looking at a userpage - get the username
    a = emailuser.href;
    i = a.indexOf("Special:Emailuser");
    username = a.substr(i+25);

    a = document.createElement('a');
    a.href="/index.php/Special:Log?user="+username;
    a.appendChild(document.createTextNode('Show Logs (user)'));
    emailuser.parentNode.insertBefore(a, emailuser);
    emailuser.parentNode.insertBefore(document.createElement('br'), emailuser);

    a = document.createElement('a');
    a.href="/index.php/Special:Log?page=User:"+username;
    a.appendChild(document.createTextNode('Show Logs (target)'));
    emailuser.parentNode.insertBefore(a, emailuser);
    emailuser.parentNode.insertBefore(document.createElement('br'), emailuser);

    a = document.createElement('a');
    a.href="/index.php/Special:Countedits/"+username;
    a.appendChild(document.createTextNode('Count edits'));
    emailuser.parentNode.insertBefore(a, emailuser);
    emailuser.parentNode.insertBefore(document.createElement('br'), emailuser);
  }

  ///////////////////////
  // Add "You have new messages" box if I do indeed have new messages
  ///////////////////////
  // find the "My talk" link
  quickbar = document.getElementById('quickbar');
  talklink = 0;
  for (i = 0; i < quickbar.childNodes.length; i++)
  {
    if (quickbar.childNodes[i].tagName == "A")
    {
      if (quickbar.childNodes[i].href.match(/User_talk:Phlip$/))
      {
        talklink = quickbar.childNodes[i];
        break;
      }
    }
  }

  if (talklink)
  {
    // check if I have a message
    // nodeType 3 is "Text node" (nodeType 1 is "Element node")
    if (talklink.nextSibling.nodeType == 3 && talklink.nextSibling.nodeValue.indexOf('*') >= 0)
    {
      div = document.createElement("div")
      div.className = "newmessagesbox"; // intentionally not "usermessages" - take that, fake message boxes!
      div.appendChild(document.createTextNode("You have "));
      a = document.createElement("a")
      a.href = "http://www.hrwiki.org/index.php/User_talk:Phlip";
      a.appendChild(document.createTextNode("new messages"));
      div.appendChild(a);
      div.appendChild(document.createTextNode(" ("));
      a = document.createElement("a")
      a.href = "http://www.hrwiki.org/index.php/User_talk:Phlip?action=history";
      a.appendChild(document.createTextNode("history"));
      div.appendChild(a);
      div.appendChild(document.createTextNode(")."));

      article = document.getElementById('article');
      article.parentNode.insertBefore(div, article);
    }
  }
}

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