Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

53 lines (45 sloc) 2.008 kB
<body>
<textarea id="textarea" rows=20 cols=50></textarea>
<br>
<input type=button onClick='compute()' value='go'/>
<br>
<div id="result">
<script>
function findAllIndexes(regex,string){
var ret = [];
var last = 0;
while(r=regex.exec(string.substring(last))){
ret.push({string: r.toString(), index: r.index});
}
return ret;
}
function getClosest(num,arr){
for(var n=arr.length-1;arr[n]>num||n>=0;n--);
return arr[n];
}
function compute(){
var result ="";
value = document.getElementById("textarea").value.replace(/\r\f/g,"");
ss = findAllIndexes(/<\s*script[^>]*>/gi,value);
es = findAllIndexes(/<\/\s*script[^>]*>/gi,value);
//sc = findAllIndexes(/<\!--/g,value);
//ec = findAllIndexes(/-->/g,value);
for(i=0;i<ss.length-1;i++){
while(ss[i+1]&&ss[i+1].index<es[i].index)ss.splice(i+1,1);
}
start = 0;
for(i = 0; i<ss.length;i++){
if(ss[i].string.search(/\ssrc\s*=\s*/)>-1)
result += "document.write('"+value.substring(start,es[i].index+es[i].string.length).replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/script/g,"scr'+'ipt").replace(/\n/g,"');\ndocument.write('")+"');\n";
else if(ss[i].string.search(/\stype\s*=\s*['"]?/)>-1&&ss[i].string.search(/\stype\s*=\s*['"]?text\/javascript/)<0)
result += "document.write('"+value.substring(start,es[i].index+es[i].string.length).replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/script/g,"scr'+'ipt").replace(/\n/g,"');\ndocument.write('")+"');\n";
else
result += "document.write('"+value.substring(start,ss[i].index).replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/\n/g,"');\ndocument.write('")+"');\n"+value.substring(ss[i].index+ss[i].string.length,es[i].index)+"\n";
start = es[i].index+es[i].string.length;
}
result += "document.write('"+value.substring(start).replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/\n/,"');\ndocument.write('")+"');\n";
var ind = [];
document.getElementById("result").innerHTML = result.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>");
}
</script>
</body>
Jump to Line
Something went wrong with that request. Please try again.