Skip to content

Instantly share code, notes, and snippets.

@dpschen
Last active March 1, 2021 13:54
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 dpschen/3690e35ba7853ed040f8f68c813b4f0d to your computer and use it in GitHub Desktop.
Save dpschen/3690e35ba7853ed040f8f68c813b4f0d to your computer and use it in GitHub Desktop.
This is a simple script to find and remove entries from OnTab
function triggerMouseEvent(node, eventType) {
const clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent(eventType, true, true);
node.dispatchEvent(clickEvent);
}
// This is a helper that you can use to remove duplicate entries on a OneTab page.
// Use like this:
// const url = "https://www.zeit.de/index";
// removeDuplicatePages(url)
function removeDuplicatePages(url) {
const pages = document.querySelectorAll(`[href="${url}"]`) || [];
if(!pages.length) {
console.log("Couldn't find any page.")
return
} else if(pages.length === 1) {
console.log("Couldn't find duplicate of page.")
return
}
console.log(`Found ${pages.length} duplicates. Removing ${pages.length - 1}`)
[...pages].forEach((page, index) => {
if (index === 0) return // keep first element
const closeButton = page.parentElement.querySelector('img[src="images/cross.png"]');
triggerMouseEvent(closeButton, 'mousedown');
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment