Skip to content

Instantly share code, notes, and snippets.

@trumad
Created November 1, 2022 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trumad/cf454af1e41d138791811ab272a6d030 to your computer and use it in GitHub Desktop.
Save trumad/cf454af1e41d138791811ab272a6d030 to your computer and use it in GitHub Desktop.
JS to delete all files from an archive.org item
function searchText(elementType,text){
var xpath = `//${elementType}[contains(text(),'${text}')]`;
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
return matchingElement;
}
function sleep(ms) { // usage: await sleep(4000)
return new Promise(resolve => setTimeout(resolve, ms));
}
var files = document.querySelectorAll(".x-tree-node-anchor")
async function go(){
for (let item of files){
if (item.textContent.includes('Tree Root')
|| item.textContent.includes('xml')
){continue}
item.click();
await sleep(100);
//document.querySelector("#ext-gen26").click() // file
searchText('button','File').click()
await sleep(700);
//document.querySelector("#ext-gen459").click() // delete
searchText('a','Delete Key').click()
await sleep(300);
//document.querySelector("#ext-gen531").click() // yes
searchText('button','Yes').click()
await sleep(300);
}
}
go();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment