Last active
January 2, 2024 04:03
-
-
Save bertolo1988/1fa5828d0d6600107073b7be36bc0ec8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deleteFbComments() { | |
let postDeleted = 0; | |
const CLICK_DELAY = 50; | |
function randomIntFromInterval(min, max) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} | |
function sleep(ms = 200) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
function selectThreeDotElements() { | |
return document.getElementsByClassName("cypi58rs"); | |
} | |
function selectDeleteButton() { | |
return document.getElementsByClassName("tiyi1ipj")[0]; | |
} | |
async function selectAndDeleteFacebookComment(comment) { | |
console.log("Selected comment..."); | |
if (!comment || !comment.children || !comment.children[0]) | |
throw new Error("No comment selected!"); | |
await singleClick(comment.children[0]); | |
console.log("Clicked three dots..."); | |
await sleep(); | |
let deleteButton = await selectDeleteButton(); | |
if (!deleteButton) throw new Error("No deleteButton selected!"); | |
await singleClick(deleteButton); | |
console.log("Deleted post!"); | |
} | |
async function singleClick(elem) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
elem.click(); | |
resolve(); | |
}, CLICK_DELAY); | |
}); | |
} | |
async function run() { | |
let comments; | |
do { | |
comments = selectThreeDotElements(); | |
try { | |
selectAndDeleteFacebookComment( | |
comments[randomIntFromInterval(0, comments.length-1)] | |
); | |
postDeleted++; | |
console.log(`Deleted ${postDeleted} posts`); | |
} catch (err) { | |
console.error("Failed while selecting and deleteing post", err); | |
await sleep(8000); | |
} | |
await sleep(); | |
} while (comments && comments.length > 0); | |
} | |
run(); | |
} | |
deleteFbComments() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment