User:Phlip/cologneblue.js

From Homestar Runner Wiki

< User:Phlip(Difference between revisions)
Jump to: navigation, search
m (%2F is bad too)
 
(includes 20 intermediate revisions)
Line 1: Line 1:
-
function getChildType(node,childtype,index)
+
// Automatically clean up links without titles from #HRWiki-RC for great copy/paste justice
 +
if (document.location.pathname == "/w/index.php" && document.location.search.indexOf("title=") < 0)
{
{
-
   /*
+
   newsearch = "?title=" + encodeURIComponent(wgPageName).replace("%3A",":").replace("%2F","/");
-
  var c = node.childNodes;
+
   if (document.location.search)
-
  childtype = childtype.toLowerCase();
+
     newsearch += "&" + document.location.search.substring(1);
-
  for (var i = 0; i < c.length; i++)
+
   document.location.search = newsearch
-
   {
+
-
    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;
+
}
}
 +
 +
// 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()
function dostuff()
{
{
-
   ///////////////////////
+
   with (utilities)
-
  // 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")
+
     if (cologneBlueNewMessages())
     {
     {
-
       b = getChildType(a[i], "P", 1);
+
       var div = document.createElement("div")
-
       if (b) b = getChildType(b, "A", 1);
+
      div.className = "newmessagesbox"; // intentionally not "usermessages" - take that, fake message boxes!
-
       if (b)
+
      div.appendChild(document.createTextNode("You have "));
-
        pageUrl = b.href;
+
       var a = document.createElement("a")
 +
      a.href = localurl("Phlip", 3);
 +
      a.appendChild(document.createTextNode("new messages"));
 +
      div.appendChild(a);
 +
      div.appendChild(document.createTextNode(" ("));
 +
      a = document.createElement("a")
 +
      a.href = localurl("Phlip", 3, "diff=cur");
 +
       a.appendChild(document.createTextNode("diff"));
 +
      div.appendChild(a);
 +
      div.appendChild(document.createTextNode(") ("));
 +
      a = document.createElement("a")
 +
      a.href = 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);
     }
     }
-
  }
 
-
  // create the validation link
+
    if (getArticleNamespace() == 2 || getArticleNamespace() == 3)
-
  a = document.getElementById('quickbar');
+
-
  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);
+
-
  }
+
-
 
+
-
  ///////////////////////
+
-
  // 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 = '';
+
       var username = getArticleTitle();
-
       talknamespace = 'Talk:';
+
      var i = username.indexOf('/')
-
       istalk = 1;
+
      if (i >= 0)
 +
        username = username.substr(0, i);
 +
       var link = addCologneBlueQuickbarLink(localurl(username, 2), username, "Context");
 +
      if (link)
 +
        link.parentNode.insertBefore(document.createElement('hr'), link);
 +
       addCologneBlueQuickbarLink(localurl(username, 3), username + " talk", "Context");
 +
      addCologneBlueQuickbarLink(localurl("Contributions/" + username, -1), "Contribs", "Context");
 +
      addCologneBlueQuickbarLink(localurl("Log", -1, "user=" + username), "Show Logs (user)", "Context");
 +
      addCologneBlueQuickbarLink(localurl("Log", -1, "page=User:" + username), "Show Logs (target)", "Context");
 +
      addCologneBlueQuickbarLink(localurl("Countedits/" + username, -1), "Count edits", "Context");
     }
     }
-
     else if (namespace.substring(namespace.length - 6) == '_talk:')
+
     addCologneBlueQuickbarLink("http://www.homestarrunner.com/", "H*R", "External");
 +
    addCologneBlueQuickbarLink("http://validator.w3.org/check?uri=" + encodeURIComponent(getArticleURL()), "Validate", "External");
 +
 
 +
    var ns = getArticleNamespace();
 +
    var t = getArticleTitle();
 +
    if (talknamespace[ns])
     {
     {
-
       talknamespace = namespace;
+
       var talklink = addCologneBlueSubtopbarLink(localurl(t, talknamespace  [ns]), namespacedescription[talknamespace  [ns]], true);
-
      namespace = namespace.substring(0,namespace.length - 6) + ':';
+
       if (talknamespace[ns] == ns)
-
       istalk = 1;
+
        talklink.style.fontWeight = "bold";
     }
     }
-
     else
+
     var pagelink = addCologneBlueSubtopbarLink(localurl(t, articlenamespace[ns]), namespacedescription[articlenamespace[ns]], true);
-
    {
+
       if (articlenamespace[ns] == ns)
-
      talknamespace = namespace.substring(0,namespace.length - 1) + '_talk:';
+
        pagelink.style.fontWeight = "bold";
-
       istalk = 0;
+
-
    }
+
-
  }
+
-
  where = document.getElementById('langlinks');
+
-
  before = where.getElementsByTagName('br');
+
-
  before = before[before.length - 1];
+
-
  before = before.nextSibling;
+
-
  a = document.createElement('a');
+
    // highlight IP addresses (eg in Recent Changes)
-
  a.href = 'http://www.hrwiki.org/index.php/' + namespace + pageName;
+
    links = document.getElementsByTagName("a");
-
  a.appendChild(document.createTextNode('page'));
+
    regex = /Special:Contributions(\/|&target=)[\d.]+$/;
-
  if (!istalk) a.style.fontWeight = 'bolder';
+
    for (i = 0; i < links.length; i++)
-
  where.insertBefore(a, before);
+
      if (regex.test(links[i].href))
-
  where.insertBefore(document.createTextNode(' | '), before);
+
        links[i].className += " ipcontribs";
-
  a = document.createElement('a');
+
    // copy the serve time comment into visibility
-
  a.href = 'http://www.hrwiki.org/index.php/' + talknamespace + pageName;
+
    var a = document.body.lastChild;
-
  a.appendChild(document.createTextNode('talk'));
+
    while (a && a.nodeType != a.COMMENT_NODE)
-
  if (istalk) a.style.fontWeight = 'bolder';
+
      a = a.previousSibling;
-
  where.insertBefore(a, before);
+
    if (a.nodeType == a.COMMENT_NODE)
-
  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;
+
-
    for (i = 0; i < quickbar.childNodes.length; i++)
+
     {
     {
-
       if (quickbar.childNodes[i].tagName == "A")
+
       var div = document.createElement("div");
-
      {
+
       div.appendChild(document.createTextNode("<!--" + a.nodeValue + "-->"));
-
        if (quickbar.childNodes[i].href.indexOf("Special:Emailuser") >= 0)
+
       div.className = "servetime";
-
        {
+
       document.body.appendChild(div);
-
          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);
+
     }
     }
   }
   }
-
   ///////////////////////
+
   a = document.getElementsByTagName("a")
-
  // Add "You have new messages" box if I do indeed have new messages
+
   regex = /http:\/\/(www\.)?homestarrunner\.com\/(.*)/;
-
   ///////////////////////
+
   for (i = 0; i < a.length; i++)
-
   // find the "My talk" link
+
-
  quickbar = document.getElementById('quickbar');
+
-
  if (quickbar)
+
   {
   {
-
     talklink = 0;
+
     matches = a[i].href.match(regex);
-
    for (i = 0; i < quickbar.childNodes.length; i++)
+
     if (matches) a[i].href = "http://localhost/hr/" + matches[2];
-
    {
+
-
      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);
+
-
      }
+
-
    }
+
   }
   }
-
   // highlight IP addresses (eg in Recent Changes)
+
   wpPreview = document.getElementById('wpPreview');
-
  links = document.getElementsByTagName("a");
+
   if (wpPreview)
-
   regex = /Special:Contributions(\/|&target=)[\d.]+$/;
+
-
  for (i = 0; i < links.length; i++)
+
   {
   {
 +
    previewinmonobook = document.createElement('button');
 +
    previewinmonobook.textContent = "Preview in Monobook";
 +
    wpPreview.parentNode.insertBefore(previewinmonobook,wpPreview.nextSibling);
 +
    wpPreview.parentNode.insertBefore(document.createTextNode(' '),wpPreview.nextSibling);
 +
    previewinmonobook.addEventListener('click', function(){
 +
      useskin = document.createElement('input');
 +
      useskin.name='useskin';
 +
      useskin.type='hidden';
 +
      useskin.value='monobook';
 +
      wpPreview.parentNode.appendChild(useskin);
 +
      wpPreview.click();
 +
    },false);
   }
   }
}
}
-
 
// 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);
 +
 +
mwCustomEditButtons = [
 +
  {
 +
    imageId: "mw-editbutton-test",
 +
    imageFile: "http://forum.hrwiki.org/images/smilies/emofrown.gif",
 +
    speedTip: "Adds test notice",
 +
    tagOpen: "{"+"{subst:test|subst=subst:|diff1=[",
 +
    tagClose: "]}"+"} ~~"+"~~",
 +
    sampleText: ""
 +
  },
 +
  {
 +
    imageId: "mw-editbutton-blockwarning",
 +
    imageFile: "http://forum.hrwiki.org/images/smilies/emomad.gif",
 +
    speedTip: "Adds block warning",
 +
    tagOpen: "{"+"{subst:blockwarning|subst=subst:}"+"} ~~"+"~~",
 +
    tagClose: "",
 +
    sampleText: ""
 +
  }
 +
];

Current revision as of 16:05, 20 June 2009

// Automatically clean up links without titles from #HRWiki-RC for great copy/paste justice
if (document.location.pathname == "/w/index.php" && document.location.search.indexOf("title=") < 0)
{
  newsearch = "?title=" + encodeURIComponent(wgPageName).replace("%3A",":").replace("%2F","/");
  if (document.location.search)
    newsearch += "&" + document.location.search.substring(1);
  document.location.search = newsearch
}

 // 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()
{
  with (utilities)
  {
    if (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 = localurl("Phlip", 3);
      a.appendChild(document.createTextNode("new messages"));
      div.appendChild(a);
      div.appendChild(document.createTextNode(" ("));
      a = document.createElement("a")
      a.href = localurl("Phlip", 3, "diff=cur");
      a.appendChild(document.createTextNode("diff"));
      div.appendChild(a);
      div.appendChild(document.createTextNode(") ("));
      a = document.createElement("a")
      a.href = 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);
    }

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

    var ns = getArticleNamespace();
    var t = getArticleTitle();
    if (talknamespace[ns])
    {
      var talklink = addCologneBlueSubtopbarLink(localurl(t, talknamespace   [ns]), namespacedescription[talknamespace   [ns]], true);
      if (talknamespace[ns] == ns)
        talklink.style.fontWeight = "bold";
    }
    var pagelink = addCologneBlueSubtopbarLink(localurl(t, articlenamespace[ns]), namespacedescription[articlenamespace[ns]], true);
      if (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";

    // copy the serve time comment into visibility
    var a = document.body.lastChild;
    while (a && a.nodeType != a.COMMENT_NODE)
      a = a.previousSibling;
    if (a.nodeType == a.COMMENT_NODE)
    {
      var div = document.createElement("div");
      div.appendChild(document.createTextNode("<!--" + a.nodeValue + "-->"));
      div.className = "servetime";
      document.body.appendChild(div);
    }
  }

  a = document.getElementsByTagName("a")
  regex = /http:\/\/(www\.)?homestarrunner\.com\/(.*)/;
  for (i = 0; i < a.length; i++)
  {
    matches = a[i].href.match(regex);
    if (matches) a[i].href = "http://localhost/hr/" + matches[2];
  }

  wpPreview = document.getElementById('wpPreview');
  if (wpPreview)
  {
    previewinmonobook = document.createElement('button');
    previewinmonobook.textContent = "Preview in Monobook";
    wpPreview.parentNode.insertBefore(previewinmonobook,wpPreview.nextSibling);
    wpPreview.parentNode.insertBefore(document.createTextNode(' '),wpPreview.nextSibling);
    previewinmonobook.addEventListener('click', function(){
      useskin = document.createElement('input');
      useskin.name='useskin';
      useskin.type='hidden';
      useskin.value='monobook';
      wpPreview.parentNode.appendChild(useskin);
      wpPreview.click();
    },false);
  }
}
// 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);

mwCustomEditButtons = [
  {
    imageId: "mw-editbutton-test",
    imageFile: "http://forum.hrwiki.org/images/smilies/emofrown.gif",
    speedTip: "Adds test notice",
    tagOpen: "{"+"{subst:test|subst=subst:|diff1=[",
    tagClose: "]}"+"} ~~"+"~~",
    sampleText: ""
  },
  {
    imageId: "mw-editbutton-blockwarning",
    imageFile: "http://forum.hrwiki.org/images/smilies/emomad.gif",
    speedTip: "Adds block warning",
    tagOpen: "{"+"{subst:blockwarning|subst=subst:}"+"} ~~"+"~~",
    tagClose: "",
    sampleText: ""
  }
];
Personal tools