Last active
March 17, 2022 07:40
-
-
Save ncwhale/7e86cdb1eca88598124ba5249224e3b9 to your computer and use it in GitHub Desktop.
This file contains 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
参考来源: https://stackoverflow.com/questions/66940041/is-there-a-javascript-to-remove-duplicate-videos-in-a-youtube-playlist
修订了里面部分逻辑和语言适配喵(X