ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
User:Lupin/editblind.js - Wikipedia, the free encyclopedia

User:Lupin/editblind.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

//DOWNLOADER
 
function newXml() {      
  return window.XMLHttpRequest ? new XMLHttpRequest()
    : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP")
    : false;
}
 
function blind_download(bundle) {
  // mandatory: bundle.url
  // bundle.onSuccess 
  // bundle.onFailure
  // bundle.otherStuff OK too
 
  var x = newXml();
  if (x) {
    if (x.overrideMimeType) { x.overrideMimeType('text/xml'); }
    // else alert('Unable to override mime type - this will probably fail.');
    x.onreadystatechange=function() {
      x.readyState==4 && blind_downloadComplete(x,bundle);
    };
    x.open("GET",bundle.url,true);
    // x.setRequestHeader('Accept','text/*');
    x.send(null); 
  }
}
 
function blind_downloadComplete(x,bundle) {
  x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true )
  || ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText));
}
 
function blind_post(bundle) {
  // mandatory: bundle.url
  // bundle.onSuccess 
  // bundle.onFailure
  // bundle.data (to be sent) - array of objects { name: 'wpStartTime', data: '20051111091512' }
  // bundle.otherStuff OK too
 
  var x = newXml();
  if (x) {
    x.onreadystatechange=function() {
      x.readyState==4 && blind_downloadComplete(x,bundle);
    };
    x.open("POST",bundle.url,true);
    var sendMe='';
    for (var i=0; i<bundle.data.length; ++i) {
      if (!bundle.data[i]) continue;
      if (sendMe.length>0) sendMe+='&';
      sendMe+=URLEncode(bundle.data[i].name) + '=' + URLEncode(bundle.data[i].data);
    }
    x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    //alert(sendMe);
    x.send(sendMe);
  }
}
 
// Source: http://www.albionresearch.com/misc/urlencode.php
function URLEncode( plaintext ) {
  // The Javascript escape and unescape functions do not correspond
  // with what browsers actually do...
  var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";
  var HEX = "0123456789ABCDEF";
  var encoded = "";
  for (var i = 0; i < plaintext.length; i++ ) {
    var ch = plaintext.charAt(i);
    if (ch == " ") {
      encoded += "+";				// x-www-urlencoded, rather than %20
    } else if (SAFECHARS.indexOf(ch) != -1) {
      encoded += ch;
    } else {
      var charCode = ch.charCodeAt(0);
      if (charCode > 255) {
        alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
               "(URL encoding only supports 8-bit characters.)\n" + 
               "A space (+) will be substituted." );
        encoded += "+";
      } else {
        encoded += "%";
        encoded += HEX.charAt((charCode >> 4) & 0xF);
        encoded += HEX.charAt(charCode & 0xF);
      }
    }
  } // for
  return encoded;
}
 
window.harvestNamedChildren=function(node) {
  var ret=[];
  for (var i=0; i<node.childNodes.length; ++i) {
    var child=node.childNodes[i];
    if (child.nodeType != 1) continue;
    var childName=child.getAttribute('name');
    if (!childName || typeof childName != typeof '') continue;
    if (childName=='wpTextbox1') {
      var wikiData=child.childNodes[0].data;
      ret.push({name: 'wpTextbox1', data: wikiData});
    } else if (child.getAttribute('checked')) {
      ret.push({name: childName, data: (child.getAttribute('checked')=='checked' ? 'on' : 'off') });      
    } else {
      ret.push({name: child.getAttribute('name'), data: child.getAttribute('value')});
    }
    if (child.childNodes.length > 0) ret=ret.concat(harvestNamedChildren(child));
  }
  return ret;
}
 
window.getXmlObj=function(req) {
  if(req.responseXML && req.responseXML.documentElement) return req.responseXML;
  // Note: this doesn't work in konqueror, and the natural fix
  // var doc=document.implementation.createDocument(); doc.loadXML(req.responseXML)
  // results in a segfault :-(
  try {
    doc=new ActiveXObject("Microsoft.XMLDOM");
    doc.async="false";
    doc.loadXML(req.responseText);
  } catch (err) {return null;}
  return doc;
}
 
window.processEditPage=function(req, bundle){  
  //  alert(req.responseText);
  //  alert(req.responseXML);
  var xmlobj=getXmlObj(req);
  if(!xmlobj) { alert('could not get xml :-('); }
  var doc=xmlobj.documentElement;
  if(!doc) { alert('could not get xml documentElement. grrrr'); }
  var forms=doc.getElementsByTagName('form');
  if (!forms.length) alert('No forms found. Bailing...');
  var form=null;
  for (var i=0; i<forms.length; ++i) {
    if (forms[i].getAttribute('name')=='editform') {
      form=forms[i]; break;
    }
  }
  if (!form) alert('No edit form found. Darn.');
  var action=form.getAttribute('action');
  var postUrl=action;
  // if the url doesn't include the hostname, we have to fix that. probably.
  if (action.indexOf('http')!=0) {
    postUrl=bundle.url.split('/');
    postUrl=[ postUrl[0], postUrl[1], postUrl[2]].join('/') + action;
  }
  //alert(postUrl);
  var formData=harvestNamedChildren(form);
  for (var i=0; i<formData.length; ++i) {
    if (!formData[i]) continue;
    switch (formData[i].name) {
    case 'wpTextbox1': if(bundle.processWikiData) {
      formData[i].data=bundle.processWikiData(formData[i].data);
    }
      break;
    case 'wpPreview': case 'wpDiff':
      formData[i]=null;
      break;
    }
  }
  blind_post({data: formData, url:postUrl, onSuccess: function(req, b){alert(req.responseText);}});
}
 
function testblind() {
  var url='http://en.wikipedia.org/wiki/User:Lupin/sandbox?action=edit';  
  blind_download({url: url, onSuccess: processEditPage, processWikiData: function(txt) {return 'hello!'+Math.random() + '\n\n'+txt;}});
}
 
/// Local Variables: ///
/// mode:c ///
/// End: ///


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -