Skip to content

Instantly share code, notes, and snippets.

@palaueb
Created January 1, 2025 19:42
Show Gist options
  • Select an option

  • Save palaueb/cdbc6202b0e84887c4d883186dc2bcc6 to your computer and use it in GitHub Desktop.

Select an option

Save palaueb/cdbc6202b0e84887c4d883186dc2bcc6 to your computer and use it in GitHub Desktop.

Revisions

  1. palaueb created this gist Jan 1, 2025.
    40 changes: 40 additions & 0 deletions unfollow_all.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    function startProcess() {
    console.log('inici');
    // Primer element: click al botó de "unfollow"
    const unfollowButton = document.querySelector('button[data-testid$="unfollow"]');
    console.log(unfollowButton);
    if (unfollowButton) {
    unfollowButton.click();

    // Espera un temps aleatori entre 800 ms i 1200 ms i clicka al segon element
    const randomDelay = Math.floor(Math.random() * (120 - 80 + 1)) + 80;
    console.log('waiting:', randomDelay);
    setTimeout(() => {
    const confirmButton = document.querySelector('[data-testid="confirmationSheetConfirm"]');
    console.log(confirmButton);
    if (confirmButton) {
    confirmButton.click();
    let element=unfollowButton;
    while (element && element.getAttribute("data-testid") !== "cellInnerDiv") {
    element = element.parentElement;
    }

    // `element` serà el node que conté l'atribut o `null` si no es troba cap.
    if (element) {
    element.remove();
    } else {
    console.log("No s'ha trobat cap element amb data-testid='cellInnerDiv'.");
    }
    } else {
    console.error("No s'ha trobat el botó de confirmació.");
    }
    }, randomDelay);
    } else {
    console.error("No s'ha trobat el botó de 'unfollow'.");
    }
    }

    // Inicia el procés amb un interval aleatori
    setInterval(() => {
    startProcess();
    }, Math.floor(Math.random() * (1200 - 800 + 1)) + 800);