Skip to content

Instantly share code, notes, and snippets.

@lihuanshuai
Last active January 24, 2019 03:07
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 lihuanshuai/8ad7a7689924aeac6d00a8327152a615 to your computer and use it in GitHub Desktop.
Save lihuanshuai/8ad7a7689924aeac6d00a8327152a615 to your computer and use it in GitHub Desktop.
remove duplicate onetab items
function get_close_nodes_for_duplicate_onetab_items() {
let closeNodes = [];
let cache = {};
let selector = '#contentAreaDiv > div > div:nth-child(2) > div > div:nth-child(2)';
let nodes = Array.from(document.querySelectorAll(selector));
for (let node of nodes) {
let linkNode = node.querySelector('a.clickable');
let closeNode = node.querySelector('img:nth-child(3)');
let url = linkNode.getAttribute('href');
if(cache[url]) {
closeNodes.push(closeNode);
continue;
}
cache[url] = 1;
}
return closeNodes;
}
function get_close_nodes_for_spec_url_onetab_items(prefix) {
let closeNodes = [];
let selector = '#contentAreaDiv > div > div:nth-child(2) > div > div:nth-child(2)';
let nodes = Array.from(document.querySelectorAll(selector));
for (let node of nodes) {
let linkNode = node.querySelector('a.clickable');
let closeNode = node.querySelector('img:nth-child(3)');
let url = linkNode.getAttribute('href');
if(url.startsWith(prefix)) {
closeNodes.push(closeNode);
}
}
return closeNodes;
}
function remove_onetab_items(closeNodes) {
for (let i = 0; i < closeNodes.length; i++) {
console.log(closeNodes[i]);
closeNodes[i].visibility = 'visible';
closeNodes[i].click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment