Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function scan(ids,out){
  2.     document.querySelectorAll("[role=button] a[role=link][href^='/'][aria-haspopup=false]").forEach(function(e){
  3.         var userid="", handle="", name="";
  4.  
  5.         a= e.attributes["href"];
  6.         if(a){
  7.             handle=a.value.slice(1);
  8.             if(handle.startsWith("search?")) return;
  9.             if(ids[handle]) return; //duplicate
  10.             ids[handle]=1;
  11.         }
  12.  
  13.         f= e.parentElement.parentElement.querySelector("[data-testid]");
  14.         if(f){
  15.             a= f.attributes["data-testid"];
  16.             if(a){
  17.                 m=a.value.match(/(\d+)/);
  18.                 if(m) userid=m[1];
  19.             }
  20.         }
  21.  
  22.         if(e.firstChild && e.firstChild.firstChild)
  23.             name= e.firstChild.firstChild.innerText.replace(/\s/g," ").trim();
  24.  
  25.         out.push([
  26.             userid,
  27.             handle,
  28.             name,
  29.         ].join("\t"));
  30.     });
  31. }
  32.  
  33. tmp="";
  34. key="\nwindow.__INITIAL_STATE__ = ";
  35. for(i=0;i<document.scripts.length; i++){
  36.     e=document.scripts[i];
  37.     if(e.text.startsWith(key)) tmp=e.text;
  38. }
  39. path=location.pathname.match(/([^/]+)$/)[1];
  40. if(path=="followers") m=tmp.match(/"normal_followers_count":(\d+),/);
  41. else if(path=="following") m=tmp.match(/"friends_count":(\d+),/);
  42.  
  43. if(!m){
  44.     console.error("You need to be on your Followers or Following page!");
  45. }
  46. else{
  47.     total=Number(m[1]);
  48.     ids={};
  49.     out=[];
  50.     timerID=setInterval(function(){  //scroll down until all followers/ees are loaded
  51.         scan(ids,out);
  52.         if(out.length >= total){
  53.             //all loaded
  54.             clearInterval(timerID);
  55.             document.body.innerHTML = "";
  56.             p=document.createElement("pre")
  57.             document.body.append(p)
  58.             p.textContent = out.join("\n");
  59.         }
  60.         //keep scrolling, one page at a time
  61.         window.scrollBy(0,window.innerHeight);
  62.     }, 500);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement