User:Phlip/cologneblue.js

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
-
function getChildType(node,childtype,index)
+
// include utility functions
-
{
+
document.write('<script type="text/javascript" src="/index.php?title=User:Phlip/utilities.js&amp;action=raw&amp;ctype=text/javascript&amp;dontcountme=s"></script>');
-
  /*
+
-
  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()
function dostuff()
{
{
-
   ///////////////////////
+
   if (utilities.cologneBlueNewMessages())
-
  // 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")
+
     var div = document.createElement("div")
-
     {
+
    div.className = "newmessagesbox"; // intentionally not "usermessages" - take that, fake message boxes!
-
      b = getChildType(a[i], "P", 1);
+
     div.appendChild(document.createTextNode("You have "));
-
      if (b) b = getChildType(b, "A", 1);
+
    var a = document.createElement("a")
-
      if (b)
+
    a.href = utilities.localurl("Phlip", 3);
-
        pageUrl = b.href;
+
    a.appendChild(document.createTextNode("new messages"));
-
     }
+
    div.appendChild(a);
-
  }
+
    div.appendChild(document.createTextNode(" ("));
 +
    a = document.createElement("a")
 +
    a.href = utilities.localurl("Phlip", 3, "diff=cur");
 +
    a.appendChild(document.createTextNode("diff"));
 +
    div.appendChild(a);
 +
    div.appendChild(document.createTextNode(") ("));
 +
    a = document.createElement("a")
 +
    a.href = utilities.localurl("Phlip", 3, "action=history");
 +
     a.appendChild(document.createTextNode("history"));
 +
    div.appendChild(a);
 +
    div.appendChild(document.createTextNode(")."));
-
  // create the validation link
+
    var article = document.getElementById('article');
-
  a = document.getElementById('quickbar');
+
     article.insertBefore(div, article.firstChild);
-
  if (a)
+
-
  {
+
-
     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);
+
   }
   }
 +
  document.body.appendChild(document.createTextNode(utilities.getArticleNamespace() + ".." + utilities.getArticleTitle()));
-
   ///////////////////////
+
   if (utilities.getArticleNamespace() == 2 || utilities.getArticleNamespace() == 3)
-
  // 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 = '';
+
     var username = utilities.getArticleTitle();
-
     talknamespace = 'Talk:';
+
    var i = username.indexOf('/')
-
     istalk = 0;
+
    if (i >= 0)
 +
      username = username.substr(0, i);
 +
     var link = utilities.addCologneBlueQuickbarLink(utilities.localurl(username, 2), username, "Context");
 +
    if (link)
 +
      link.parentNode.insertBefore(document.createElement('hr'), link);
 +
     utilities.addCologneBlueQuickbarLink(utilities.localurl(username, 3), username + " talk", "Context");
 +
    utilities.addCologneBlueQuickbarLink(utilities.localurl("Contributions/" + username, -1), "Contribs", "Context");
 +
    utilities.addCologneBlueQuickbarLink(utilities.localurl("Log", -1, "user=" + username), "Show Logs (user)", "Context");
 +
    utilities.addCologneBlueQuickbarLink(utilities.localurl("Log", -1, "page=User:" + username), "Show Logs (target)", "Context");
   }
   }
-
   else
+
   utilities.addCologneBlueQuickbarLink("http://validator.w3.org/check?uri=" + escape(utilities.getArticleURL()), "Validate", "External");
-
  {
+
-
    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');
+
   utilities.addCologneBlueTopbarLink("javascript:alert('hi')", "Start", true);
-
  a.href = 'http://www.hrwiki.org/index.php/' + namespace + pageName;
+
   utilities.addCologneBlueTopbarLink("javascript:alert('hi')", "End");
-
  a.appendChild(document.createTextNode('page'));
+
   var ns = utilities.getArticleNamespace();
-
  if (!istalk) a.style.fontWeight = 'bolder';
+
   var t = utilities.getArticleTitle();
-
  where.insertBefore(a, before);
+
   if (utilities.talknamespace[ns])
-
   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');
+
-
  if (quickbar)
+
   {
   {
-
     emailuser = 0;
+
     var talklink = utilities.addCologneBlueSubtopbarLink(utilities.localurl(t, utilities.talknamespace  [ns]), utilities.namespacedescription[utilities.talknamespace  [ns]], true);
-
    for (i = 0; i < quickbar.childNodes.length; i++)
+
     if (utilities.talknamespace[ns] == ns)
-
    {
+
       talklink.style.fontWeight = "bold";
-
      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');
+
-
  if (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);
+
-
      }
+
-
    }
+
   }
   }
 +
  var pagelink = utilities.addCologneBlueSubtopbarLink(utilities.localurl(t, utilities.articlenamespace[ns]), utilities.namespacedescription[utilities.articlenamespace[ns]], true);
 +
    if (utilities.articlenamespace[ns] == ns)
 +
      pagelink.style.fontWeight = "bold";
   // highlight IP addresses (eg in Recent Changes)
   // highlight IP addresses (eg in Recent Changes)
Line 207: Line 67:
       links[i].className += " ipcontribs";
       links[i].className += " ipcontribs";
}
}
-
 
// these two lines stolen from [[User:Tom/monobook.js]]
// these two lines stolen from [[User:Tom/monobook.js]]
if (window.addEventListener) window.addEventListener("load",dostuff,false);
if (window.addEventListener) window.addEventListener("load",dostuff,false);
else if (window.attachEvent) window.attachEvent("onload",dostuff);
else if (window.attachEvent) window.attachEvent("onload",dostuff);

Revision as of 19:20, 24 May 2006

 // include utility functions
 document.write('<script type="text/javascript" src="/index.php?title=User:Phlip/utilities.js&amp;action=raw&amp;ctype=text/javascript&amp;dontcountme=s"></script>');

function dostuff()
{
  if (utilities.cologneBlueNewMessages())
  {
    var div = document.createElement("div")
    div.className = "newmessagesbox"; // intentionally not "usermessages" - take that, fake message boxes!
    div.appendChild(document.createTextNode("You have "));
    var a = document.createElement("a")
    a.href = utilities.localurl("Phlip", 3);
    a.appendChild(document.createTextNode("new messages"));
    div.appendChild(a);
    div.appendChild(document.createTextNode(" ("));
    a = document.createElement("a")
    a.href = utilities.localurl("Phlip", 3, "diff=cur");
    a.appendChild(document.createTextNode("diff"));
    div.appendChild(a);
    div.appendChild(document.createTextNode(") ("));
    a = document.createElement("a")
    a.href = utilities.localurl("Phlip", 3, "action=history");
    a.appendChild(document.createTextNode("history"));
    div.appendChild(a);
    div.appendChild(document.createTextNode(")."));

    var article = document.getElementById('article');
    article.insertBefore(div, article.firstChild);
  }
  document.body.appendChild(document.createTextNode(utilities.getArticleNamespace() + ".." + utilities.getArticleTitle()));

  if (utilities.getArticleNamespace() == 2 || utilities.getArticleNamespace() == 3)
  {
    var username = utilities.getArticleTitle();
    var i = username.indexOf('/')
    if (i >= 0)
      username = username.substr(0, i);
    var link = utilities.addCologneBlueQuickbarLink(utilities.localurl(username, 2), username, "Context");
    if (link)
      link.parentNode.insertBefore(document.createElement('hr'), link);
    utilities.addCologneBlueQuickbarLink(utilities.localurl(username, 3), username + " talk", "Context");
    utilities.addCologneBlueQuickbarLink(utilities.localurl("Contributions/" + username, -1), "Contribs", "Context");
    utilities.addCologneBlueQuickbarLink(utilities.localurl("Log", -1, "user=" + username), "Show Logs (user)", "Context");
    utilities.addCologneBlueQuickbarLink(utilities.localurl("Log", -1, "page=User:" + username), "Show Logs (target)", "Context");
  }
  utilities.addCologneBlueQuickbarLink("http://validator.w3.org/check?uri=" + escape(utilities.getArticleURL()), "Validate", "External");

  utilities.addCologneBlueTopbarLink("javascript:alert('hi')", "Start", true);
  utilities.addCologneBlueTopbarLink("javascript:alert('hi')", "End");
  var ns = utilities.getArticleNamespace();
  var t = utilities.getArticleTitle();
  if (utilities.talknamespace[ns])
  {
    var talklink = utilities.addCologneBlueSubtopbarLink(utilities.localurl(t, utilities.talknamespace   [ns]), utilities.namespacedescription[utilities.talknamespace   [ns]], true);
    if (utilities.talknamespace[ns] == ns)
      talklink.style.fontWeight = "bold";
  }
  var pagelink = utilities.addCologneBlueSubtopbarLink(utilities.localurl(t, utilities.articlenamespace[ns]), utilities.namespacedescription[utilities.articlenamespace[ns]], true);
    if (utilities.articlenamespace[ns] == ns)
      pagelink.style.fontWeight = "bold";

  // highlight IP addresses (eg in Recent Changes)
  links = document.getElementsByTagName("a");
  regex = /Special:Contributions(\/|&target=)[\d.]+$/;
  for (i = 0; i < links.length; i++)
    if (regex.test(links[i].href))
      links[i].className += " ipcontribs";
}
// 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);
Personal tools