;(async function () {
const BATCH_SIZE = 10
const PAUSE_DURATION = 20000
const DELAY = (ms) => new Promise(r => setTimeout(r, ms))
const reactClick = (el) => {
el.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }))
el.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }))
el.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }))
el.dispatchEvent(new MouseEvent('click', { bubbles: true }))
}
const waitFor = async (fn, maxWait = 6000) => {
const start = Date.now()
while (Date.now() - start < maxWait) {
const el = fn()
if (el) return el
await DELAY(300)
}
return null
}
// Background dialog dismisser
const dialogDismisser = setInterval(() => {
const okBtn = [...document.querySelectorAll('button, div[role="button"]')]
.find(b => b.innerText.trim() === 'OK')
if (okBtn) {
console.log('⚠️ Auto-dismissed error dialog')
reactClick(okBtn)
}
}, 1000)
let totalDeleted = 0
while (true) {
// ✅ Re-enter Select mode every batch
const selectBtn = await waitFor(() =>
[...document.querySelectorAll('div._ap3a._aaco._aacw._aad0._aad6')]
.find(el => el.innerText.trim() === 'Select')
)
if (!selectBtn) {
console.log('✅ No more Select button — all done! Total deleted:', totalDeleted)
break
}
reactClick(selectBtn)
await DELAY(1500)
const comments = [...document.querySelectorAll('[aria-label="Image with button"]')]
if (comments.length === 0) {
console.log('✅ No comments found — all done! Total deleted:', totalDeleted)
break
}
const batchSize = Math.min(BATCH_SIZE, comments.length)
console.log(`🗑️ Selecting ${batchSize} comments...`)
for (let i = 0; i < batchSize; i++) {
reactClick(comments[i])
await DELAY(400)
}
await DELAY(1500)
const deleteBtn = await waitFor(() =>
[...document.querySelectorAll('[aria-label="Delete"]')]
.find(el => el.style.pointerEvents === 'auto')
)
if (!deleteBtn) { console.error('❌ Delete button not found'); break }
reactClick(deleteBtn)
await DELAY(1000)
const confirmBtn = await waitFor(() =>
[...document.querySelectorAll('button._a9--')]
.find(b => b.innerText.trim() === 'Delete')
)
if (!confirmBtn) { console.error('❌ Confirm button not found'); break }
reactClick(confirmBtn)
await DELAY(2500)
totalDeleted += batchSize
console.log(`✔️ ${totalDeleted} deleted — waiting 20 seconds...`)
await DELAY(PAUSE_DURATION)
console.log('▶️ Resuming...')
}
clearInterval(dialogDismisser)
})()