Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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