Created
November 12, 2022 12:08
-
-
Save phuochau/d36fa48fe1f36a99ec50fa54dbb401ef to your computer and use it in GitHub Desktop.
Delete all photos of Facebook Page
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 getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
const ID = document.body.children[0].id | |
let hasDeletion = true | |
async function start() { | |
const container = getElementByXpath(`//*[@id=\"${ID}\"]/div[1]/div[1]/div/div[3]/div/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div/div/div/div/div/div[3]/div[1]`) | |
if (container && container.children && container.children.length > 0 && hasDeletion) { | |
hasDeletion = false | |
for (let i = 0; i < container.children.length; i++) { | |
const item = container.children[i] | |
try { | |
const editButton = item.children[0].children[0].children[0].children[2].children[0] | |
if (editButton) { | |
editButton.click() | |
await sleep(500) | |
const deleteMenu = getElementByXpath(`//*[@id="${ID}"]/div[1]/div[1]/div/div[3]/div/div/div/div[2]/div/div/div[1]/div[1]/div/div/div/div/div/div/div[1]/div/div[3]`) | |
if (deleteMenu) { | |
deleteMenu.click() | |
await sleep(500) | |
const deleteConfirm = getElementByXpath(`//*[@id="${ID}"]/div[1]/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[4]/div/div[2]/div[1]`) | |
if (deleteConfirm) { | |
deleteConfirm.click() | |
console.log('Deleted Photo') | |
hasDeletion = true | |
await sleep(6000) | |
} | |
} | |
} | |
} catch { | |
console.log('Error at index:', i, item) | |
} | |
} | |
console.log('DONE') | |
start() | |
} | |
} | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment