Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(!self.parseHTML){
- var tifr=document.createElement("iframe");
- tifr.style.position="fixed";
- tifr.style.bottom="500px";
- self.parseHTML=function(s){
- document.body.appendChild(tifr);
- var unBd=tifr.contentDocument;
- document.body.removeChild(tifr);
- unBd.documentElement.innerHTML=s;
- return unBd; //(DOM)
- };
- }
- // DOM.getElementsByTagName("script")
- //note, the variable "li" is placed next to "lev" because it's related to it, the expression if(li<3) means if last grouping character is one of these 3 opening characters: ( [ {
- var RipScript=function(s){
- var i=0,c,L=s.length, jsa=[],
- stack=[],stL,sp,
- ALL=[],ci,
- lev="([{}])",li,
- str,emc={"[":"]","{":"}","(":")"},
- ei,pci,pv,
- psj=[];
- while(i<L){
- c=s[i]; stL=stack.length-1;
- sp=!1; li=0;
- if(str){
- if(c=="\x5C") i++;
- else if(c==str){sp=!0;li=7;}
- }
- else if(c=="'"||c=='"'){
- if(!str)str=c;
- sp=!0;
- }
- else if(c=="/"){
- li=s[i+1]; if(li=="/"){ ei=s.indexOf("\r",i); pci=s.indexOf("\n",i); if(pci>ei)ei=pci; i=ei; }
- else if(li=="*"){ ei=s.indexOf("*/",i); i=ei+2; }
- //put some regex handling here?
- }
- else if((li=lev.indexOf(c))>=0) sp=!0;
- if(sp){
- if(li<3){
- stack.push(ci=[c,i]); ALL.push(ci);
- }else if(str||c==emc[stack[stL][0]]){
- if(str)str=!1;
- sp=stack.pop(); ci=[c,i,sp[1],ALL.indexOf(sp)]; sp[2]=i; sp[3]=ALL.length; ALL.push(ci);
- if(c=="}"||c=="]"){ //is bracket, test for JSON
- if(ci[3])pv=ALL[ci[3]-1];else pv=[0,0];
- sbs=s.substring(pv[1],sp[1]);
- ei=sbs.lastIndexOf("="); pci=sbs.lastIndexOf(":");
- if(pci>ei) ei=pci;
- if(ei>=0||lev.indexOf(pv[0])<2){ //YAY possible JSON found
- psj.push([sp[1],ci[1]]);
- }
- }
- }else console.log("wrong order error");
- }
- i++;
- }
- i=psj.length; pv="";
- while(i--){
- c=psj[i]
- sbs=s.substring(c[0],c[1]+1);
- if(pv.indexOf(sbs)<0){
- try{ ei=JSON.parse(sbs); jsa.unshift(ei); pv+=sbs; }catch(e){}
- }
- }
- console.log("stack length :"+stack.length);
- return {"jsa":jsa,"ALL":ALL};
- };
- self.XtracFromDoc=function(ds){
- var scrps=parseHTML(ds).getElementsByTagName("script"),oa=[],i=0,L=scrps.length,cs,cv;
- while(i<L){
- cs=scrps[i];
- if(cs.innerHTML.length){
- cv=RipScript(cs.innerHTML);
- cv.sei=i; //script element index
- oa.push(cv);
- }
- i++;
- }
- return oa;
- };
Add Comment
Please, Sign In to add comment