User:PeterL/exasperation.js

From RationalWiki
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/*
Adds a list of quick statements to the edit tools at the bottom of the edit screen (Where it says "Sign your username: ~~~~", but at the bottom). 
Click where it says "Exasperated remarks" to get a list. Add more to User:PeterL/ex.
Code from MediaWiki:Gadget-smileylist.js. PeterL, 09:25, 29 May 2012 (UTC)
*/
var exasperationList;
 
function showExasperationList()
{
  vis = (exasperationList.style.display == "block");
  if (!vis)
  {
    var toolbar = document.getElementById('editpage-specialchars');
    toolbar.appendChild(exasperationList);
    exasperationList.style.display = "block";
  } else {
    exasperationList.style.display = "none";
  }
}
 
function exasperations2()
{
 
  var toolbar = document.getElementById('editpage-specialchars');
  if (!toolbar) { return false; }
 
  var textbox = document.getElementById('wpTextbox1');
 
  var exasperationspan = document.createElement("span");
  exasperationspan.innerHTML = "<b>Exasperated remarks</b>"
  exasperationspan.id = "edittools_exasperations"
  exasperationspan.title = "Exasperated remarks";
  exasperationspan.style.cursor = "pointer";
  exasperationspan.onclick = function() {
    showExasperationList();
    return false;
  };
 
  toolbar.appendChild(exasperationspan);
 
  exasperationList = document.createElement("div");
  exasperationList.id = "exasperationList";
  exasperationList.style.position = "static";
  /*populate exasperation box*/
  var req = false;
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req) {
    req.open("GET", wgServer + wgScript + "?title=User:" + wgUserName + "/ex", true);
    //req.overrideMimeType("text/xml");
    req.onreadystatechange = function()
    {
      if (req.readyState==4 && req.status == 200) {
        var xmlhack = document.createElement("div");
        xmlhack.innerHTML = req.responseText;
        var divs = xmlhack.getElementsByTagName("div");
        //var divs = req.responseXML.documentElement.getElementsByTagName("div");
        var bci;
        var i;
        for (i=0; i<divs.length; i++ ) {
          if ( divs[i].id == "bodyContent" ) {
            bci = i;
            break;
          }
        }
        var ps = divs[bci].getElementsByTagName("p");
        while (ps.length>0)
        {
          addExasperation2(exasperationList,ps.item(0));
        }
      }
    }
    req.send(null);
  }
   
  exasperationList.style.display = "none";
 
  return true;
}
 
function addExasperation2(parent, item)
{
  item.onclick = function() {
    insertTags(item.innerHTML,'','');
    return false;
  };
  item.style.margin="4px";  
  item.style.cursor = "pointer";
  parent.appendChild(item);
}
 
hookEvent("load", exasperations2);