Skip to content

Instantly share code, notes, and snippets.

@JoseCage
Forked from JamieMason/unfollow.js.md
Created December 12, 2019 13:40
Show Gist options
  • Select an option

  • Save JoseCage/5897b6037623dd95ae22ad177c58f3a5 to your computer and use it in GitHub Desktop.

Select an option

Save JoseCage/5897b6037623dd95ae22ad177c58f3a5 to your computer and use it in GitHub Desktop.

Revisions

  1. @JamieMason JamieMason revised this gist Aug 22, 2019. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions unfollow.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    // ====================
    // UPDATED 13 AUG 2019
    // ====================
    // Unfollow everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left)
    // https://gist.github.com/JamieMason/7580315
    //
    // 1. Go to https://twitter.com/YOUR_USER_NAME/following
    // 2. Open the Developer Console. (COMMAND+ALT+I on Mac)
    @@ -16,6 +14,9 @@
    });

    const nextBatch = async () => {
    window.scrollTo(0, document.body.scrollHeight);
    await sleep({ seconds: 1 });

    const followButtons = Array.from(document.querySelectorAll(followButtonQuery));
    const followButtonCount = followButtons.length;

  2. @JamieMason JamieMason revised this gist Aug 13, 2019. 1 changed file with 26 additions and 19 deletions.
    45 changes: 26 additions & 19 deletions unfollow.js
    Original file line number Diff line number Diff line change
    @@ -7,31 +7,38 @@
    // 2. Open the Developer Console. (COMMAND+ALT+I on Mac)
    // 3. Paste this into the Developer Console and run it
    (() => {
    const sleep = ({ seconds }) => new Promise(proceed => setTimeout(proceed, seconds * 1000));
    const followButtonQuery = '[data-testid$="-unfollow"]';
    const confirmButtonQuery = '[data-testid="confirmationSheetConfirm"]';
    const sleep = ({ seconds }) =>
    new Promise(proceed => {
    console.log(`WAITING FOR ${seconds} SECONDS...`);
    setTimeout(proceed, seconds * 1000);
    });

    const nextBatch = async () => {
    const followButtonQuery = '[data-testid$="-unfollow"]';
    const confirmButtonQuery = '[data-testid="confirmationSheetConfirm"]';
    const followButtons = Array.from(document.querySelectorAll(followButtonQuery));
    const followButtonCount = followButtons.length;

    if (followButtonCount > 0) {
    console.log(`UNFOLLOWING ${followButtonCount} USERS...`);
    await Promise.all(
    followButtons.map(async followButton => {
    followButton.click();
    await sleep({ seconds: 1 });
    const confirmBtn = document.querySelector(confirmButtonQuery);
    confirmBtn.click();
    })
    );

    console.log(`WAITING FOR 2 SECONDS...`);
    await sleep({ seconds: 2 });
    nextBatch();
    } else {
    console.log(`I THINK WE'RE DONE, RE-RUN THE SCRIPT IF ANY WERE MISSED`);
    if (followButtonCount === 0) {
    console.log(`NO ACCOUNTS FOUND, SO I THINK WE'RE DONE`);
    console.log(`RELOAD PAGE AND RE-RUN SCRIPT IF ANY WERE MISSED`);
    return;
    }

    console.log(`UNFOLLOWING ${followButtonCount} USERS...`);

    await Promise.all(
    followButtons.map(async followButton => {
    followButton.click();
    await sleep({ seconds: 1 });
    const confirmButton = document.querySelector(confirmButtonQuery);
    confirmButton.click();
    })
    );

    await sleep({ seconds: 2 });
    nextBatch();
    };

    nextBatch();
    })();
  3. @JamieMason JamieMason revised this gist Aug 13, 2019. 1 changed file with 23 additions and 10 deletions.
    33 changes: 23 additions & 10 deletions unfollow.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,34 @@
    // ====================
    // UPDATED 23 JULY 2019
    // UPDATED 13 AUG 2019
    // ====================
    // Unfollow everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left)
    //
    // 1. Go to https://twitter.com/YOUR_USER_NAME/following
    // 2. Open the Developer Console. (COMMAND+ALT+I on Mac)
    // 3. Paste this into the Developer Console and run it
    (() => {
    const nextBatch = () => {
    const waitFor = 2;
    const nextBatch = Array.from(document.querySelectorAll('[data-testid$="-unfollow"]'));
    const batchSize = nextBatch.length;
    if (batchSize > 0) {
    console.log(`UNFOLLOWING ${batchSize} USERS...`);
    nextBatch.forEach((button) => button.click());
    console.log(`WAITING FOR ${waitFor} SECONDS...`);
    setTimeout(nextBatch, waitFor * 1000);
    const sleep = ({ seconds }) => new Promise(proceed => setTimeout(proceed, seconds * 1000));

    const nextBatch = async () => {
    const followButtonQuery = '[data-testid$="-unfollow"]';
    const confirmButtonQuery = '[data-testid="confirmationSheetConfirm"]';
    const followButtons = Array.from(document.querySelectorAll(followButtonQuery));
    const followButtonCount = followButtons.length;

    if (followButtonCount > 0) {
    console.log(`UNFOLLOWING ${followButtonCount} USERS...`);
    await Promise.all(
    followButtons.map(async followButton => {
    followButton.click();
    await sleep({ seconds: 1 });
    const confirmBtn = document.querySelector(confirmButtonQuery);
    confirmBtn.click();
    })
    );

    console.log(`WAITING FOR 2 SECONDS...`);
    await sleep({ seconds: 2 });
    nextBatch();
    } else {
    console.log(`I THINK WE'RE DONE, RE-RUN THE SCRIPT IF ANY WERE MISSED`);
    }
  4. @JamieMason JamieMason revised this gist Jul 23, 2019. 1 changed file with 23 additions and 10 deletions.
    33 changes: 23 additions & 10 deletions unfollow.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,24 @@
    // ====================
    // UPDATED 23 JULY 2019
    // ====================
    // Unfollow everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left)

    // 1. Go to https://twitter.com/following.
    // 2. Keep scrolling to the bottom repeatedly until all your followers are loaded.
    // 3. Run this in your console.
    [].slice.call(document.querySelectorAll('.unfollow-text')).forEach(function(button) {
    button.click();
    });

    // If your browser is freezing because you follow *loads* of people, then try the version
    // in this comment: https://gist.github.com/JamieMason/7580315#gistcomment-2316858
    //
    // 1. Go to https://twitter.com/YOUR_USER_NAME/following
    // 2. Open the Developer Console. (COMMAND+ALT+I on Mac)
    // 3. Paste this into the Developer Console and run it
    (() => {
    const nextBatch = () => {
    const waitFor = 2;
    const nextBatch = Array.from(document.querySelectorAll('[data-testid$="-unfollow"]'));
    const batchSize = nextBatch.length;
    if (batchSize > 0) {
    console.log(`UNFOLLOWING ${batchSize} USERS...`);
    nextBatch.forEach((button) => button.click());
    console.log(`WAITING FOR ${waitFor} SECONDS...`);
    setTimeout(nextBatch, waitFor * 1000);
    } else {
    console.log(`I THINK WE'RE DONE, RE-RUN THE SCRIPT IF ANY WERE MISSED`);
    }
    };
    nextBatch();
    })();
  5. @JamieMason JamieMason revised this gist Jan 10, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions unfollow.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // Unfollow everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left)

    // 1. Go to https://twitter.com/following.
    // 2. Keep scrolling to the bottom repeatedly until all your followers are loaded.
    // 3. Run this in your console.
  6. @JamieMason JamieMason revised this gist Jan 10, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions unfollow.js
    Original file line number Diff line number Diff line change
    @@ -4,3 +4,6 @@
    [].slice.call(document.querySelectorAll('.unfollow-text')).forEach(function(button) {
    button.click();
    });

    // If your browser is freezing because you follow *loads* of people, then try the version
    // in this comment: https://gist.github.com/JamieMason/7580315#gistcomment-2316858
  7. @JamieMason JamieMason revised this gist Jul 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion unfollow.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // 1. Go to https://twitter.com/following.
    // 2. Keep scrolling to the bottom repeatedly until all your followers are loaded.
    // 3. Run this in your console.
    [].slice.call(document.querySelectorAll('stream-container .unfollow-text')).forEach(function(button) {
    [].slice.call(document.querySelectorAll('.unfollow-text')).forEach(function(button) {
    button.click();
    });
  8. @JamieMason JamieMason created this gist Nov 21, 2013.
    6 changes: 6 additions & 0 deletions unfollow.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    // 1. Go to https://twitter.com/following.
    // 2. Keep scrolling to the bottom repeatedly until all your followers are loaded.
    // 3. Run this in your console.
    [].slice.call(document.querySelectorAll('stream-container .unfollow-text')).forEach(function(button) {
    button.click();
    });