|
(async function () { |
|
//Config |
|
const UNFOLLOW_LIMIT = 4; |
|
const REMOVE_LIST = []; |
|
const REMOVED_LIST = []; |
|
const CLASS_LIST = 'x1dm5mii x16mil14 xiojian x1yutycm x1lliihq x193iq5w xh8yej3'; |
|
const $followers = document.querySelectorAll('.' + CLASS_LIST.replace(/ /g, '.')); |
|
const delay = (ms) => new Promise(_ => setTimeout(_, ms)); |
|
const findButtonRemoveButton = (parent, selector = '*') => [...parent.querySelectorAll(selector).entries()].map(([pos, btn]) => btn).filter(btn => btn.textContent.trim() === 'Remove')[0]; |
|
const randomBetween30And60s = () => Math.floor(Math.random() * 30) + 30; |
|
const findNodeWithText = (rootNode, searchText) => { |
|
if (!rootNode) { |
|
return null; |
|
} |
|
|
|
if (rootNode.nodeType === Node.TEXT_NODE && rootNode.nodeValue?.includes(searchText)) { |
|
return rootNode; |
|
} |
|
|
|
for (let i = 0; i < rootNode.childNodes.length; i++) { |
|
const foundNode = findNodeWithText(rootNode.childNodes[i], searchText); |
|
if (foundNode) { |
|
return foundNode; |
|
} |
|
} |
|
|
|
return null; |
|
} |
|
|
|
const findFollowerNode = (username) => { |
|
for (let i = 0; i < $followers.length; i++) { |
|
const $follower = $followers[i]; |
|
|
|
const $username = findNodeWithText($follower, username); |
|
if ($username) { |
|
console.log("Found", username) |
|
return $follower; |
|
} |
|
} |
|
} |
|
|
|
const clickConfirmModal = () => { |
|
const dialogs = document.querySelectorAll('div[role=dialog]'); |
|
|
|
if (dialogs.length === 0) { |
|
console.warn('Could not find modal'); |
|
return; |
|
} |
|
|
|
const lastDialog = dialogs[dialogs.length - 1]; |
|
const $removeButton = findButtonRemoveButton(lastDialog, 'button'); |
|
|
|
if ($removeButton) { |
|
$removeButton.click(); |
|
} |
|
} |
|
|
|
console.log("Start") |
|
|
|
if (!$followers.length) { |
|
console.log("No followers found") |
|
return |
|
} |
|
|
|
console.log("Found followers") |
|
for (let i = 0; i < REMOVE_LIST.length && i < UNFOLLOW_LIMIT; i++) { |
|
console.log("Searching", REMOVE_LIST[i]); |
|
let $followerNode = findFollowerNode(REMOVE_LIST[i], $followers); |
|
|
|
if ($followerNode) { |
|
const $confirm = findButtonRemoveButton($followerNode); |
|
if ($confirm) { |
|
$confirm.click(); |
|
REMOVED_LIST.push(REMOVE_LIST[i]); |
|
console.log(`Removed ${REMOVE_LIST[i]}`); |
|
await delay(1000); // Wait for confirmation modal |
|
clickConfirmModal(); |
|
await delay(randomBetween30And60s()); |
|
} |
|
} else { |
|
console.log(`Could not find ${REMOVE_LIST[i]}`); |
|
} |
|
} |
|
|
|
console.log("The end"); |
|
console.log('We removed these followers:', REMOVED_LIST); |
|
})(); |