User:Splarka/stripsource.js

//script for generating a stripped version of a wikipage for local testing/modification // var getReq;

function sourcebutton { switch(skin) { case 'quartzsmoke': /* pass to quartzslate */ case 'quartzslate': addArticleBarlink('javascript:getXML("' + document.location.href + '",getsourceStateChange)','(source)'); break; case 'wow': /* pass to slate */ case 'wookie': /* pass to slate */ case 'memalpha': /* pass to slate */ case 'smoke': /* pass to slate */ case 'slate': addMSBlink('javascript:getXML("' + document.location.href + '",getsourceStateChange)','(source)'); case 'chick': /* pass to monobook */ case 'simple': /* pass to monobook */ case 'myskin': /* pass to monobook */ case 'monobook': addPortletLink('p-tb','javascript:getXML("' + document.location.href + '",getsourceStateChange)','Bare source','t-source','generate a localized version of the source of this page'); case 'classic': break; /* not supported yet */ case 'standard': break; /* not supported yet */ case 'cologneblue': break; /* not supported yet */ case 'nostaliga': break; /* not supported yet */ }   } addOnloadHook(sourcebutton);

function parsesource(data) { var source = data;

//strip out stuff like google ads, useless debug comments, sitenotice, sendtoafriend, other slowdowns //possible future stripables: edittools var rxp = [ /\<\!\-\- attempt to fetch [^>]*\-\-\>\n/ig, /\<\!\-\- right column \(google ads\) BEGIN \-\-\>[^¿]*\<\!\-\- right column \(google ads\) END \-\-\>/ig, /\<\!\-\- Served by [^¿]*\<\!\-\- analytics \(end\) \-\-\>/ig, /\.*\\<\/a\>\<\/li\>/ig, /\.*\<\/li\>\n/ig, /\[^<]{0,3}var reqSendToAFriend[^<]*\< 50[^<]*\<\/script\>/ig, /\[^¿]*\<\/script\>\<\/div\>/ig, /\\n<\/div\>/ig ] for(var i=0;i < rxp.length;i++) { source = source.replace(rxp[i],''); } source = source.replace(' ',' ');

//lazy output generation method (rewrite me as a popup?) var bod = document.getElementsByTagName('body')[0]; var sourcediv = document.createElement('div'); sourcediv.setAttribute('style','position:absolute;top:0;left:0;width:80%;height:80%;border:2px solid black;z-index:10;background-color:#ffffff;padding:1em;margin:2em;display:block;'); sourcediv.setAttribute('id','annoyingsourcebox'); var sourcekill = document.createElement('a'); sourcekill.setAttribute('href','javascript:document.getElementById("annoyingsourcebox").setAttribute("style","display:none;");'); sourcekill.setAttribute('style','text-decoration:underline;'); sourcekill.appendChild(document.createTextNode('kill popup')); var sourceta = document.createElement('textarea'); sourceta.setAttribute('style','width:100%;height:98%'); sourceta.appendChild(document.createTextNode(source)); sourcediv.appendChild(sourcekill); sourcediv.appendChild(sourceta); bod.appendChild(sourcediv); }

function getXML(url,func) { if (window.XMLHttpRequest) { // Non-IE browsers getReq = new XMLHttpRequest; } else if (window.ActiveXObject) { // IE   getReq = new ActiveXObject('Microsoft.XMLHTTP'); } if (getReq) { getReq.onreadystatechange = func; try { getReq.open('GET', url, true); getReq.send(''); } catch (e) { alert(e); } } else { alert('XMLHTTPRequest not supported'); } }

function getsourceStateChange { switch (getReq.readyState) { case 1: break; case 2: break; case 3: break; case 4: if (getReq.status == 200) { // OK response parsesource(getReq.responseText); } else { alert('Problem: ' + getReq.statusText); }     break; } }

function addMSBlink(url,text) { var msbs = document.getElementById('myStuffBar').getElementsByTagName('a')[0].parentNode; var link = document.createElement('a'); link.href = url; link.appendChild(document.createTextNode(text)); link.setAttribute('style','margin-left: 10px;'); msbs.appendChild(link); }

function addArticleBarlink(url,text) { var ab = getElementsByClassName(document,'div','articleBar'); if(ab.length < 1) return; var obj = ab[0].getElementsByTagName('div')[0]; var link = document.createElement('a'); link.style.color = 'red'; link.href = url; link.appendChild(document.createTextNode(text)); obj.appendChild(link); } //