Advertisement
John4711

update_globalrank2 (localforage)

Jan 9th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var s=document.createElement("script");s.async=false;s.defer="defer";s.src="https://unpkg.com/localforage";document.head.appendChild(s);s.onload=function(){setTimeout(update1,300)}
  2. async function update1(){
  3. //window.store= localforage.createInstance({name:"sw", storeName:"GlobalRank"});
  4. window.store= localforage.createInstance({name:"lru1"});
  5. window.store1= localforage.createInstance({name:"sw", storeName:"list"});
  6.  
  7. var i=0;
  8. console.log(await store.getItem('cisco.com'));
  9. var vv=await store.keys();vv=vv.sort((a, b) => 0.5 - Math.random());
  10. for (let v of vv) {
  11.    let o=await store.getItem(v);
  12.    if (!o.EstimatedMonthlyVisits["2021-12-01"]) {
  13.       console.log(i++,o.SiteName);
  14.       let r=await fetch("https://data.similarweb.com/api/v1/data/?domain="+o.SiteName,{credentials: 'include'});
  15.       if (r.status==200) {
  16.          let d = await r.json();
  17.          d.EstimatedMonthlyVisits= Object.assign( o.EstimatedMonthlyVisits,d.EstimatedMonthlyVisits);
  18.          d.lastModified=new Date().valueOf();
  19.          await store.setItem(d.SiteName,d);
  20.          document.title=d.SiteName+" [ " +d.GlobalRank.Rank + " ] "+i+""
  21.          document.body.innerHTML="<pre>"+JSON.stringify(d,null,2)+"</pre>";
  22.          }
  23.      if (r.status==403) {location.assign("https://data.similarweb.com/api/v1/data/?domain="+v); break;}
  24.       }
  25.  
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement