Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scan(ids,out){
- document.querySelectorAll("[role=button] a[role=link][href^='/'][aria-haspopup=false]").forEach(function(e){
- var userid="", handle="", name="";
- a= e.attributes["href"];
- if(a){
- handle=a.value.slice(1);
- if(handle.startsWith("search?")) return;
- if(ids[handle]) return; //duplicate
- ids[handle]=1;
- }
- f= e.parentElement.parentElement.querySelector("[data-testid]");
- if(f){
- a= f.attributes["data-testid"];
- if(a){
- m=a.value.match(/(\d+)/);
- if(m) userid=m[1];
- }
- }
- if(e.firstChild && e.firstChild.firstChild)
- name= e.firstChild.firstChild.innerText.replace(/\s/g," ").trim();
- out.push([
- userid,
- handle,
- name,
- ].join("\t"));
- });
- }
- tmp="";
- key="\nwindow.__INITIAL_STATE__ = ";
- for(i=0;i<document.scripts.length; i++){
- e=document.scripts[i];
- if(e.text.startsWith(key)) tmp=e.text;
- }
- path=location.pathname.match(/([^/]+)$/)[1];
- if(path=="followers") m=tmp.match(/"normal_followers_count":(\d+),/);
- else if(path=="following") m=tmp.match(/"friends_count":(\d+),/);
- if(!m){
- console.error("You need to be on your Followers or Following page!");
- }
- else{
- total=Number(m[1]);
- ids={};
- out=[];
- timerID=setInterval(function(){ //scroll down until all followers/ees are loaded
- scan(ids,out);
- if(out.length >= total){
- //all loaded
- clearInterval(timerID);
- document.body.innerHTML = "";
- p=document.createElement("pre")
- document.body.append(p)
- p.textContent = out.join("\n");
- }
- //keep scrolling, one page at a time
- window.scrollBy(0,window.innerHeight);
- }, 500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement