Last active
March 1, 2021 13:54
-
-
Save dpschen/3690e35ba7853ed040f8f68c813b4f0d to your computer and use it in GitHub Desktop.
This is a simple script to find and remove entries from OnTab
This file contains hidden or 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
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