Skip to content

Instantly share code, notes, and snippets.

@ZettZet
Created September 27, 2024 19:09
Show Gist options
  • Select an option

  • Save ZettZet/cf325eee1f511b7ad5bf391d3305f698 to your computer and use it in GitHub Desktop.

Select an option

Save ZettZet/cf325eee1f511b7ad5bf391d3305f698 to your computer and use it in GitHub Desktop.
Deleting files from OneDrive is difficult, especially if you want to delete thousands at once. The settings delete button does not work, and you can delete only 50 files at once.
setInterval(() => {
Array.from(document.querySelectorAll('[aria-labelledby]'))
.slice(0, 50)
.forEach((item) => {
const id = item.getAttribute('aria-labelledby')
document.getElementById(id).click()
})
document.querySelector('button[data-automationid="deleteCommand"]').click()
waitForElm('button[data-automationid="confirmbutton"]').then((element) => element.click())
}, 100)
function waitForElm(selector) {
return new Promise((resolve) => {
const element = document.querySelector(selector)
if (element) {
return resolve(element)
}
const observer = new MutationObserver(() => {
const element = document.querySelector(selector)
if (element) {
observer.disconnect()
resolve(element)
}
})
observer.observe(document.body, {
childList: true,
subtree: true,
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment