Difference between revisions of "User:Nx/monobook.js"

From RationalWiki
Jump to navigation Jump to search
m
m (restrict bottomedit to pages with addsection)
(3 intermediate revisions by the same user not shown)
Line 39: Line 39:
  
 
addOnloadHook(addsectionbottom);
 
addOnloadHook(addsectionbottom);
 +
 +
/*
 +
getElementsByClass
 +
  needed by bottomedit
 +
*/
 +
 +
function getElementsByClass(classname,node)
 +
{
 +
  function _recGet(out, element, cname)
 +
  {
 +
    while(element)
 +
    {
 +
      if (element.nodeType == Node.ELEMENT_NODE)
 +
      {
 +
        if (element.hasAttribute("class"))
 +
        {
 +
          if (element.className == cname)
 +
          {
 +
            out.push(element);
 +
          }
 +
        }
 +
        _recGet(out,element.firstChild,cname)
 +
      }
 +
      element = element.nextSibling;
 +
    }
 +
  }
 +
 
 +
 
 +
  if (!node) node = document.documentElement;
 +
  var res = new Array();
 +
  _recGet(res,node,classname);
 +
  return res; 
 +
}
 +
 +
/*
 +
bottomedit
 +
  Add an edit section link to the bottom of a section
 +
*/
 +
 +
function bottomedit() {
 +
  if (!(document.getElementById("ca-addsection"))) return;
 +
  var bodyContent = document.getElementById("bodyContent");
 +
  var headings = getElementsByClass("mw-headline",bodyContent);
 +
  var i;
 +
  var editsection2;
 +
  var editsection;
 +
  for (i=1;i<headings.length;++i)
 +
  {
 +
    editsection2 = document.createElement("span");
 +
    editsection = headings[i-1].parentNode.firstChild.firstChild.nextSibling;
 +
    editsection2.innerHTML = "<a " + "href=\"" + editsection.getAttribute("href") +
 +
                            "\" title=\"" + editsection.getAttribute("title") + "\" >Add comment</a>"
 +
    bodyContent.insertBefore(editsection2,headings[i].parentNode);
 +
  }
 +
  if (headings.length > 0)
 +
  {
 +
    editsection2 = document.createElement("span");
 +
    editsection = headings[headings.length-1].parentNode.firstChild.firstChild.nextSibling;
 +
    editsection2.innerHTML = "<a " + "href=\"" + editsection.getAttribute("href") +
 +
                            "\" title=\"" + editsection.getAttribute("title") + "\" >Add comment</a>"
 +
    bodyContent.appendChild(editsection2);
 +
  }
 +
}
 +
 +
addOnloadHook(bottomedit);

Revision as of 00:40, 15 January 2009

/*
CUR Signature Exchanger
*/

function curse() {
  var bads = document.getElementsByTagName("a");
  var i;
  for (i=0;i<bads.length;++i)
  {
    if (bads[i].getAttribute("title")=="User:ConservapediaUndergroundResistor" && bads[i].childNodes.length > 0 && bads[i].childNodes[0].nodeName == "FONT") {
      bads[i].innerHTML = "CUR";
    }
    if (bads[i].getAttribute("title")=="User talk:ConservapediaUndergroundResistor" && bads[i].childNodes.length > 0 
        && bads[i].childNodes[0].childNodes.length > 0 && bads[i].childNodes[0].childNodes[0].nodeName == "FONT") {
      bads[i].innerHTML = "<sup>talk</sup>";
    }
  }
}

addOnloadHook(curse);

/*
addsectionbottom
  Add a new section link to the bottom of discussion pages
*/

function addsectionbottom() {
  var caplus;
  if (!(caplus = document.getElementById("ca-addsection"))) return;
  var addsection = document.createElement("span");
  addsection.innerHTML = "<h2> <a " + "href=\"" + caplus.childNodes[0].getAttribute("href") + 
                         "\" title=\"" + caplus.childNodes[0].getAttribute("title") +
                         "\" accesskey=\"" + caplus.childNodes[0].getAttribute("accesskey") + 
                         "\" > <span class> Add new section </span> </a> </h2>"
  var content;
  if (!(content = document.getElementById("content"))) return;
  content.appendChild(addsection);
}

addOnloadHook(addsectionbottom);

/*
getElementsByClass
  needed by bottomedit
*/

function getElementsByClass(classname,node) 
{
  function _recGet(out, element, cname)
  {
    while(element)
    {
      if (element.nodeType == Node.ELEMENT_NODE)
      {
        if (element.hasAttribute("class"))
        {
          if (element.className == cname)
          {
            out.push(element);
          }
        }
        _recGet(out,element.firstChild,cname)
      }
      element = element.nextSibling;
    }
  }
  
  
  if (!node) node = document.documentElement;
  var res = new Array();
  _recGet(res,node,classname);
  return res;  
}

/*
bottomedit
  Add an edit section link to the bottom of a section
*/

function bottomedit() {
  if (!(document.getElementById("ca-addsection"))) return;
  var bodyContent = document.getElementById("bodyContent");
  var headings = getElementsByClass("mw-headline",bodyContent);
  var i;
  var editsection2;
  var editsection;
  for (i=1;i<headings.length;++i)
  {
    editsection2 = document.createElement("span");
    editsection = headings[i-1].parentNode.firstChild.firstChild.nextSibling;
    editsection2.innerHTML = "<a " + "href=\"" + editsection.getAttribute("href") + 
                             "\" title=\"" + editsection.getAttribute("title") + "\" >Add comment</a>"
    bodyContent.insertBefore(editsection2,headings[i].parentNode);
  }
  if (headings.length > 0)
  {
    editsection2 = document.createElement("span");
    editsection = headings[headings.length-1].parentNode.firstChild.firstChild.nextSibling;
    editsection2.innerHTML = "<a " + "href=\"" + editsection.getAttribute("href") + 
                             "\" title=\"" + editsection.getAttribute("title") + "\" >Add comment</a>"
    bodyContent.appendChild(editsection2);
  }
}

addOnloadHook(bottomedit);