Skip to content

Instantly share code, notes, and snippets.

@JuanRetard
Created February 7, 2026 09:39
Show Gist options
  • Select an option

  • Save JuanRetard/3edd02d3cb793fc16d02fe9fb734a8a5 to your computer and use it in GitHub Desktop.

Select an option

Save JuanRetard/3edd02d3cb793fc16d02fe9fb734a8a5 to your computer and use it in GitHub Desktop.
i didnt made this i found it and it worked rn atleast
; (async function () {
// Constants
/** @const {number} - The number of comments to delete in each batch. */
const DELETION_BATCH_SIZE = 10
/** @const {number} - The delay between actions in milliseconds. */
const DELAY_BETWEEN_ACTIONS_MS = 1000
/** @const {number} - The delay between clicking the checkboxes in milliseconds. */
const DELAY_BETWEEN_CHECKBOX_CLICKS_MS = 300
/** @const {number} - The maximum number of retries for waiting operations */
const MAX_RETRIES = 60
/** @const {string} - The XPath selector for the "Select" button */
const XPATH_SELECT_BUTTON = "//span[text()='Select']/.."
/** @const {string} - The XPath selector for the "Delete" button */
const XPATH_DELETE_BUTTON = '//span[text()="Delete"]/../../..'
/** @const {string} - The XPath selector for the "Delete" button in the confirm dialog */
const XPATH_CONFIRM_DELETE_BUTTON = '//button[div[text()="Delete"]]'
/**
* Utility function that delays execution for a given amount of time.
* @param {number} ms - The milliseconds to delay.
* @returns {Promise<void>} A promise that resolves after the specified delay.
*/
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
/**
* Utility function that waits for an element to appear in the DOM before resolving.
* @param {string} selector - The XPath of the element to wait for.
* @param {number} [timeout=30000] - The maximum time to wait in milliseconds.
* @returns {Promise<Element>} A promise that resolves with the found element.
* @throws {Error} If the element is not found within the timeout period.
*/
const waitForElementByXpath = async (xpath, timeout = 30000) => {
const startTime = Date.now()
while (Date.now() - startTime < timeout) {
const element = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null)?.iterateNext()
if (element) return element
await delay(100)
}
throw new Error(`Element with selector "${selector}" not found within ${timeout}ms`)
}
/**
* Utility function that clicks on a given element.
* @param {Element} element - The element to click.
* @throws {Error} If the element is not found.
*/
const clickElement = async (element) => {
if (!element) throw new Error('Element not found')
element.click()
}
/**
* Waits for the "Select" button to reappear after the page loads more comments
* following the deletion of a batch of comments when the "Select" button
* is hidden while a spinner indicates that more comments are loading.
* @returns {Promise<void>} A promise that resolves when the select button reappears.
* @throws {Error} If the select button is not found after maximum retries.
*/
const waitForSelectButton = async () => {
for (let i = 0; i < MAX_RETRIES; i++) {
console.log("Trying to find Select Button")
const foundSelect = document.evaluate(XPATH_SELECT_BUTTON, document, null, XPathResult.ANY_TYPE, null)?.iterateNext();
if (foundSelect) return
await delay(1000)
}
throw new Error('Select button not found after maximum retries')
}
/**
* Deletes the currently selected comments.
* @returns {Promise<void>} A promise that resolves when the comments are deleted.
*/
const deleteSelectedComments = async () => {
try {
const deleteButton = await waitForElementByXpath(XPATH_DELETE_BUTTON)
await clickElement(deleteButton)
await delay(DELAY_BETWEEN_ACTIONS_MS)
const confirmButton = await waitForElementByXpath(XPATH_CONFIRM_DELETE_BUTTON)
await clickElement(confirmButton)
} catch (error) {
console.error('Error during comment deletion:', error.message)
}
}
/**
* Deletes all user comments by selecting comments in batches.
* @returns {Promise<void>} A promise that resolves when all comments are deleted.
*/
const deleteActivity = async () => {
try {
while (true) {
// Find all spans that say "Select"
const allSpans = Array.from(document.querySelectorAll('span'));
const selectButton = allSpans.find(span => span.textContent === 'Select')?.parentElement;
if (!selectButton) throw new Error('Select button not found')
await clickElement(selectButton)
await delay(DELAY_BETWEEN_ACTIONS_MS)
const checkboxes = document.querySelectorAll('[aria-label="Toggle checkbox"]')
if (checkboxes.length === 0) {
console.log('No more comments to delete')
break
}
for (let i = 0; i < Math.min(DELETION_BATCH_SIZE, checkboxes.length); i++) {
await clickElement(checkboxes[i])
await delay(DELAY_BETWEEN_CHECKBOX_CLICKS_MS)
}
await delay(DELAY_BETWEEN_ACTIONS_MS)
await deleteSelectedComments()
await delay(DELAY_BETWEEN_ACTIONS_MS)
await waitForSelectButton()
await delay(DELAY_BETWEEN_ACTIONS_MS)
}
} catch (error) {
console.error('Error in deleteActivity:', error.message)
}
}
// Start the deletion process
try {
await deleteActivity()
console.log('Activity deletion completed')
} catch (error) {
console.error('Fatal error:', error.message)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment