Skip to content

Instantly share code, notes, and snippets.

@mhcifci
Created March 21, 2022 13:13
Show Gist options
  • Save mhcifci/bf9c0efe72c94c29a3748d914672ee6b to your computer and use it in GitHub Desktop.
Save mhcifci/bf9c0efe72c94c29a3748d914672ee6b to your computer and use it in GitHub Desktop.
Twitter Takipten Çıkma Kodu 2022 | Unfollow.JS
(() => {
const $followButtons = '[data-testid$="-unfollow"]';
const $confirmButton = '[data-testid="confirmationSheetConfirm"]';
const retry = {
count: 0,
limit: 3,
};
const scrollToTheBottom = () => window.scrollTo(0, document.body.scrollHeight);
const retryLimitReached = () => retry.count === retry.limit;
const addNewRetry = () => retry.count++;
const sleep = ({ seconds }) =>
new Promise((proceed) => {
console.log(`İŞLEM İÇİN ${seconds} SANİYE BEKLENİYOR...`);
setTimeout(proceed, seconds * 1000);
});
const unfollowAll = async (followButtons) => {
console.log(`${followButtons.length} KİŞİ TAKİPTEN ÇIKILIYOR.`);
await Promise.all(
followButtons.map(async (followButton) => {
followButton && followButton.click();
await sleep({ seconds: 1 });
const confirmButton = document.querySelector($confirmButton);
confirmButton && confirmButton.click();
})
);
};
const nextBatch = async () => {
scrollToTheBottom();
await sleep({ seconds: 1 });
const followButtons = Array.from(document.querySelectorAll($followButtons));
const followButtonsWereFound = followButtons.length > 0;
if (followButtonsWereFound) {
await unfollowAll(followButtons);
await sleep({ seconds: 2 });
return nextBatch();
} else {
addNewRetry();
}
if (retryLimitReached()) {
console.log(`HESAP BULUNAMADI, YA TAMAMLANDI YA DA SAYFAYI YENİLEYİP KODU TEKRAR BAŞLATMAN GEREK`);
console.log(`KAÇIRDIĞIMIZ BİR ŞEY VARSA SAYFAYI YENİLE`);
} else {
await sleep({ seconds: 2 });
return nextBatch();
}
};
nextBatch();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment