Skip to content

Instantly share code, notes, and snippets.

@abhijithvijayan
Created October 8, 2025 16:49
Show Gist options
  • Save abhijithvijayan/602bdaa2cc00320728ea0593b71b218e to your computer and use it in GitHub Desktop.
Save abhijithvijayan/602bdaa2cc00320728ea0593b71b218e to your computer and use it in GitHub Desktop.

Revisions

  1. abhijithvijayan renamed this gist Oct 8, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. abhijithvijayan created this gist Oct 8, 2025.
    59 changes: 59 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    // Unlike all the liked tweets in bulk

    const run = async () => {
    const xpath = "//div[contains(text(),' Likes')]";
    const likesCountElmt = document.evaluate(
    xpath,
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null
    ).singleNodeValue;

    if (!(likesCountElmt instanceof HTMLElement)) {
    console.log("Likes count element not found");
    return;
    }

    const count = +likesCountElmt.innerText.replace(",", "").match(/\d+/g)?.[0] || 0;
    console.log(`Detected ${count} total likes`);

    if (count === 0) {
    console.log("No liked tweets found. Reloading page...");
    window.location.reload();
    return;
    }

    const MAX_SCROLL_RETRIES = 5;
    let scrollRetries = 0;

    while (true) {
    const elements = [...document.querySelectorAll(`[data-testid="unlike"]`)];
    if (elements.length > 0) {
    console.log(`Unliking ${elements.length} tweets...`);
    for (const btn of elements) {
    btn.click();
    console.log("Unliked one tweet");
    await new Promise((resolve) => setTimeout(resolve, 150));
    }

    scrollRetries = 0;
    } else {
    console.log("No unlike buttons found. Scrolling...");
    window.scrollTo(0, 0);
    await new Promise((resolve) => setTimeout(resolve, 200));
    window.scrollTo(0, document.body.scrollHeight);
    await new Promise((resolve) => setTimeout(resolve, 2000));

    scrollRetries += 1;
    if (scrollRetries > MAX_SCROLL_RETRIES) {
    console.log("Reached max scroll retries — stopping.");
    break;
    }
    }
    }

    console.log("Finished unliking all visible tweets!");
    };

    run();