Last active
March 17, 2022 07:40
-
-
Save ncwhale/7e86cdb1eca88598124ba5249224e3b9 to your computer and use it in GitHub Desktop.
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 sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function removeduplicates() { | |
let titles = document.querySelectorAll('#primary #video-title') | |
let href_pattern = RegExp('https?://www\\.youtube\\.com/watch\\?v=[^&]*&list=[^&]*&index=') | |
titles = Array.from(titles).filter(t => href_pattern.test(t.href)) | |
let exists = {} | |
for (let i = 0; i < titles.length; i++) { | |
let id = titles[i].href.match(/\\?v=([^&]+)/)[1] | |
if(exists[id]) { | |
titles[i].focus() | |
titles[i].parentElement.parentElement.parentElement.parentElement.parentElement.querySelector('button[aria-label="操作菜单"]').click() | |
await sleep(100) | |
var things = document.evaluate( | |
'//span[contains(text(),"中移除")]', | |
document, | |
null, | |
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, | |
null | |
); | |
await sleep(300) | |
for (var j = 0; j < things.snapshotLength; j++) { | |
things.snapshotItem(j).click(); | |
} | |
console.log(titles[i].innerText) | |
} | |
exists[id] = true | |
} | |
} | |
removeduplicates() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
适用于简体中文界面的 YouTube 列表 Deduplicate 脚本,直接在 F12 窗口或者油猴一类地方执行喵~