"use strict";const INSTAGRAM_HOSTNAME="www.instagram.com";let nonFollowersList=[],userIdsToUnfollow=[],isActiveProcess=!1;function sleep(e){return new Promise((n=>{setTimeout(n,e)}))}function getCookie(e){const n=`; ${document.cookie}`.split(`; ${e}=`);if(2===n.length)return n.pop().split(";").shift()}function afterUrlGenerator(e){return`https://www.instagram.com/graphql/query/?query_hash=3dec7e2c57367ef3da3d987d89f9dbc8&variables={"id":"${getCookie("ds_user_id")}","include_reel":"true","fetch_mutual":"false","first":"24","after":"${e}"}`}function unfollowUserUrlGenerator(e){return`https://www.instagram.com/web/friendships/${e}/unfollow/`}function getElementByClass(e){const n=document.querySelector(e);if(null===n)throw new Error(`Unable to find element by class: ${e}`);return n}function getUserById(e){const n=nonFollowersList.find((n=>n.id.toString()===e.toString()));return void 0===n&&console.error(`Unable to find user by id: ${e}`),n}function copyListToClipboard(){const e=[...nonFollowersList].sort(((e,n)=>e.username>n.username?1:-1));let n="";e.forEach((e=>{n+=e.username+"\n"})),copyToClipboard(n)}async function copyToClipboard(e){await navigator.clipboard.writeText(e),alert("List copied to clipboard!")}function onToggleUser(){getElementByClass(".selected-user-count").innerHTML=`[${userIdsToUnfollow.length}]`}function toggleUser(e){userIdsToUnfollow=-1===userIdsToUnfollow.indexOf(e)?[...userIdsToUnfollow,e]:userIdsToUnfollow.filter((n=>n!==e)),onToggleUser()}function toggleAllUsers(e=!1){document.querySelectorAll(".account-checkbox").forEach((n=>n.checked=e)),userIdsToUnfollow=e?nonFollowersList.map((e=>e.id)):[],onToggleUser()}function renderResults(e){const n=[...e].sort(((e,n)=>e.username>n.username?1:-1));getElementByClass(".toggle-all-checkbox").disabled=!1;const t=getElementByClass(".results-container");t.innerHTML="";let o="";n.forEach((e=>{const n=-1!==userIdsToUnfollow.indexOf(parseInt(e.id,10)),r=e.username.substring(0,1).toUpperCase();o!==r&&(o=r,t.innerHTML+=`
${o}
`),t.innerHTML+=``}))}async function run(e){getElementByClass(".run-scan").remove(),getElementByClass(".include-verified-checkbox").disabled=!0,nonFollowersList=await getNonFollowersList(e),getElementByClass(".copy-list").disabled=!1}function renderOverlay(){let e=!0;document.body.innerHTML=`\n \n
\n \n
InstagramUnfollowers
\n \n \n \n \n \n\n \n \n\n \n
\n `,getElementByClass(".run-scan").addEventListener("click",(()=>run(e))),getElementByClass(".include-verified-checkbox").addEventListener("change",(()=>e=!e))}async function getNonFollowersList(e=!0){if(isActiveProcess)return;let n=[],t=!0,o=0,r=0,s=-1;isActiveProcess=!0;let l=`https://www.instagram.com/graphql/query/?query_hash=3dec7e2c57367ef3da3d987d89f9dbc8&variables={"id":"${getCookie("ds_user_id")}","include_reel":"true","fetch_mutual":"false","first":"24"}`;const i=getElementByClass(".progressbar-bar"),a=getElementByClass(".progressbar-text"),c=getElementByClass(".nonfollower-count"),d=getElementByClass(".sleeping-text");for(;t;){let u;try{u=await fetch(l).then((e=>e.json()))}catch(e){console.error(e);continue}-1===s&&(s=u.data.user.edge_follow.count),t=u.data.user.edge_follow.page_info.has_next_page,l=afterUrlGenerator(u.data.user.edge_follow.page_info.end_cursor),r+=u.data.user.edge_follow.edges.length,u.data.user.edge_follow.edges.forEach((t=>{!e&&t.node.is_verified||t.node.follows_viewer||n.push(t.node)}));const f=`${Math.ceil(r/s*100)}%`;a.innerHTML=f,i.style.width=f,c.innerHTML=n.length.toString(),renderResults(n),await sleep(Math.floor(400*Math.random())+1e3),o++,o>6&&(o=0,d.style.display="block",d.innerHTML="Sleeping 10 secs to prevent getting temp blocked...",await sleep(1e4)),d.style.display="none"}return i.style.backgroundColor="#59A942",a.innerHTML="DONE",isActiveProcess=!1,n}async function unfollow(){if(isActiveProcess)return;if(0===userIdsToUnfollow.length)return void alert("Must select at least a single user to unfollow");if(!confirm("Are you sure?"))return;let e=getCookie("csrftoken");if(void 0===e)throw new Error("csrftoken cookie is undefined");const n=getElementByClass(".sleeping-text"),t=getElementByClass(".progressbar-bar"),o=getElementByClass(".progressbar-text");getElementByClass(".toggle-all-checkbox").disabled=!0;const r=getElementByClass(".results-container");r.innerHTML="";const s=()=>window.scrollTo(0,r.scrollHeight);o.innerHTML="0%",t.style.width="0%",isActiveProcess=!0;let l=0;for(const i of userIdsToUnfollow){const a=getUserById(i);try{await fetch(unfollowUserUrlGenerator(i),{headers:{"content-type":"application/x-www-form-urlencoded","x-csrftoken":e},method:"POST",mode:"cors",credentials:"include"}),r.innerHTML+=`