User:EnDumEn/doublepage.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

var xmlhttp;

function compare(url) {
  if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=xmlhttpChange;
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
  }
}

function xmlhttpChange() {
  if (xmlhttp.readyState==4) {
    if (xmlhttp.status==200) {
      var content = document.getElementById('content');

      var table = document.createElement('table');
      var tr = document.createElement('tr');
      tr.setAttribute('valign', 'top');

      var td = document.createElement('td');
      td.setAttribute('width', '50%');
      var bodycontent = document.getElementById('bodyContent');
      td.appendChild(bodycontent);
      tr.appendChild(td);

      td = document.createElement('t');
      td.setAttribute('width', '50%');

      var viewdiv = document.createElement('div');
      viewdiv.innerHTML = xmlhttp.responseText.match("<!-- start content -->(.|\n)*<!-- end content -->");

      td.appendChild(viewdiv);
      tr.appendChild(td);

      table.appendChild(tr);
      content.appendChild(table);
    } else {
      alert("Problem retrieving XML data" + xmlhttp.status);
    }
  }
}

/* add form */
function addcompareform() {
  var form = document.createElement('form');
  form.setAttribute('id', 'compareForm');

  var inp = document.createElement('input');
  inp.setAttribute('id', 'compareInput');  
  inp.setAttribute('type', 'text');
  form.appendChild(inp); 

  inp = document.createElement('input');
  inp.setAttribute('id', 'compareButton');  
  inp.setAttribute('type', 'button');
  inp.setAttribute('value', 'show');
  inp.onclick = function() { compare("http://en.wikisource.org/wiki/"
                           + document.getElementById('compareInput').value) };

  form.appendChild(inp);

  var tabs = document.getElementById('contentSub');
  tabs.appendChild(form);
}

if (window.addEventListener) window.addEventListener("load",addcompareform,false);
else if (window.attachEvent) window.attachEvent("onload",addcompareform);