Advertisement
John4711

update_similarsites

Jan 9th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. var u=new Set(),a=['cisco.com','google.com','facebook.com','microsoft.com'];
  2. var s=document.createElement("script");s.async=false;s.defer="defer";s.src="https://unpkg.com/localforage";document.head.appendChild(s);s.onload=function(){
  3. window.store1= localforage.createInstance({name:"sw", storeName:"GlobalRank", driver: localforage.WEBSQL});
  4. window.store= localforage.createInstance({name:"sw", storeName:"SimilarSites", driver: localforage.WEBSQL});
  5. update1();
  6. }
  7. function update1(){let q=a.shift();if (!q) return false;
  8. fetch("https://serving-api.similarsites.com/data",{method: 'POST',credentials: 'include',headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},body:"url="+q})
  9. .then(r=>{return r.status==200?r.json():{"status":r.status}})
  10. .then(d=>{
  11. if (d.status==429) {a.unshift(q);setTimeout(update1,60e3);return false;}
  12. d.SiteName=d.Redirect;d.TotalVisits=parseInt(d.TotalVisits);d.lastModified=new Date().valueOf();
  13. console.log(d);
  14. for (var v of d.SimilarSites){v.TotalVisits=parseInt(v.TotalVisits); if (!u.has(v.Site)){u.add(v.Site);a.push(v.Site);}}
  15. //console.log(d.SimilarSites.map(v=>[v.Site,v.GlobalRank,v.TotalVisits]))
  16.  
  17. store.setItem(d.SiteName,d);
  18. for (var v of d.SimilarSites) store1.setItem(v.Site,{"SiteName":v.Site,"GlobalRank":v.GlobalRank,"TotalVisits":parseInt(v.TotalVisits)});
  19. if (a.length>0) setTimeout(update1,10);
  20. })
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement