Created
February 21, 2018 21:25
-
-
Save vibol/70b7545db3d4c76b55da0dbea266e1aa to your computer and use it in GitHub Desktop.
Google Docs: A Google App script for deleting all bookmarks from a Google Doc
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
// 1. Tools > Script editor... | |
// 2. Paste the below code | |
// 3. Run | |
// 4. Approve permissions | |
// 5. Go to the document from which Script editor was launched and allow the script to run | |
function deleteAllBookmarks() { | |
var ui = DocumentApp.getUi(); | |
var response = ui.alert('This will delete ALL bookmarks in this document. Are you sure you want to continue?', ui.ButtonSet.YES_NO); | |
if (response == ui.Button.YES) { | |
var doc = DocumentApp.getActiveDocument(); | |
var bookmarks = doc.getBookmarks(); | |
for (var i = 0; i < bookmarks.length - 1; i++) { | |
bookmarks[i].remove(); | |
} | |
} | |
} |
This script also works in the console; however, you may need to scroll through multiple pages to ensure they're all removed.
document.querySelectorAll('.kix-bookmarkicon-icon-outer').forEach(el => {
try {
let ev = getEventListeners(el)
ev.mousedown[0].listener(el)
ev.mousedown[1].listener(el)
document.querySelectorAll('.kix-bookmark-bubble-button[data-tooltip="Remove"]').forEach(_ => _.click())
} catch (error) {
console.log("error on el: ", el) // likely means scrolling, can i automate this?
}
})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The .remove() method is definitely the correct method according to the api docs, however, it no longer seems to work. I filed an issue here https://issuetracker.google.com/issues/276617142