IWBH_01

wayback machine save page api?

May 8th, 2021 (edited)
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //run this on a web.archive.org page
  2.  
  3. //new version:    https://tinyurl.com/waybackapi
  4.  
  5. /*
  6. (the page can itself be an iframe created by javascript that has src set to a web.archive.org/web/[datenumber]im_/https://yourwebsite.com/archire_org_api.html page that has postMessage capabilities to receive and respond to javscript archive requests.
  7. */
  8. var ifr1=document.getElementById("ifr1"),
  9. frm2=document.getElementById("spn-form"),
  10. frm_u=frm2.querySelector("input[type=text]"),
  11.  
  12. xhr=new XMLHttpRequest(),
  13. xhrbr=0,
  14.  
  15. qry=location.search.substr(1).split("&"),qi=qry.length,torg,b;
  16.  
  17. while(qi--){ b=qry[qi].indexOf("="); if(qry[qi].substr(0,b)=="torg") torg=qry.substr(b+1); }
  18.  
  19.  
  20. document.getElementById("orgb").innerText=location.origin;
  21.  
  22. xhr.onload=function xhrL0(){
  23.   if(xhr.readyState!=4){
  24.     xhrbr++;
  25.     if(xhrbr<150)setTimeout(xhrL0,2000);
  26.     return 0;
  27.   }else{
  28.     xhrbr=0;
  29.     self.parent.postMessage({"type":"fetchresult","response":xhr.response,"url":xhr.responseURL},torg);
  30.   }
  31. };
  32.  
  33.  
  34. var savedURL=function(url){
  35.   return url.substr(url.indexOf("http",4));
  36. };
  37.  
  38. getContentLinks=function(){
  39. var non,rel=[],as=ifr1.contentDocument.querySelectorAll("a");
  40. while(i--){ non=as[i].href.indexOf("/web/"); if(non+1&&(as[i].href.indexOf("/http",non)+1)) rel.push(as[i].href);  }
  41.  
  42. var rsc=ifr1.contentDocument.getElementById("spn-resources");
  43. if(rsc&&rsc.value.length>7){ rel=rel.concat(rsc.value.split("\n")); }
  44. return rel;
  45. };
  46.  
  47.  
  48. var ifr_l0d=function(){
  49. var ti1=ifr1.contentDocument.getElementById("spn-result"),oes=HTMLElement.prototype.__lookupSetter__("innerHTML");
  50.  
  51. ti1.__defineSetter__("innerHTML",function(){ oes.apply(this,arguments);
  52.   //has loaded?
  53.   var cont=getContentLinks();
  54.   self.parent.postMessage({"type":"saveresult","links":cont},torg);
  55.  });
  56.  
  57. ti1.__defineGetter__("innerHTML",HTMLElement.prototype.__lookupGetter__("innerHTML"));
  58. };
  59. ifr1.addEventListener("load",ifr_l0d);
  60.  
  61.  
  62. var omsg=function(e){
  63.  if(!torg)torg=e.origin;
  64.  var dat=e.data,opr=dat.opr;
  65.  if(opr=="savepage"){
  66.    if(frm_u=dat.url) frm2.submit();
  67.  }
  68.  else if(opr=="fetch"){
  69.    if(dat.url){
  70.      xhr.open("GET",dat.url);
  71.      //https://web.archive.org/cdx/?url=r5---sn-a5mekn7d.googlevideo.com/*&limit=100&filter=mimetype:video/mp4&filter=url:.*AOq0QJ8wRgIhAI6WhGhZqezkzZQbgdiQl5JOWF8R7.*
  72.      xhr.responseType=dat.responseType||"text";
  73.      xhr.send();
  74.    }
  75.  }
  76. };
  77.  
  78. self.addEventListener("onmessage",omsg);
  79.  
  80. //saved in-page content links
  81. //self.lal_=ifr1.contentDocument.querySelectorAll("textarea")[0].value; self.in_page_content=lal_.split("\n");
  82.  
  83. //frm2.querySelectorAll("input[type=text]")
  84.  
  85.  
  86.  
  87.  
  88. /*
  89. //form copy
  90. self.forms=ifr1.contentDocument.getElementsByTagName("form");
  91. self.i=forms.length; self.rf_=[]; while(i--){ if(forms[i].getAttribute("action")=="/save") rf_.push(forms[i]); }
  92. self.frm_0=rf_[0];
  93.  
  94. self.frm2=frm_0.cloneNode();
  95. frm2.innerHTML=frm_0.innerHTML;
  96. frm2.target="ifr1";
  97.  
  98. //frm2.querySelectorAll("input[name=capture_outlinks]")[0].checked=!0; //do capture outlinks?
  99. frm2.querySelectorAll("input[name=capture_all]")[0].checked=!1; //don't save error pages
  100.  
  101.  
  102. */
  103.  
Add Comment
Please, Sign In to add comment