Last active
September 6, 2024 07:14
-
-
Save RubaXa/53bcdb27244a84144fd8f90d2e6a011b to your computer and use it in GitHub Desktop.
JavaScript Snippet for Youtube Subscriptions that automatically adds clips to the Player (сс https://t.me/musicisalreadytaken)
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
(async () => { | |
const $ = (s, e = document) => e.querySelector(s); | |
const $$ = (s, e = document) => e.querySelectorAll(s); | |
const pause = (ms) => new Promise(r => setTimeout(r, ms)); | |
let videos = [...$$('#contents ytd-expanded-shelf-contents-renderer').values()]; | |
if (!videos.length) { | |
videos = [...$$('#contents.ytd-rich-grid-renderer .ytd-rich-grid-renderer').values()]; | |
} | |
console.log('Videos:', videos.length); | |
for (const el of videos) { | |
try { | |
const title = $('#video-title', el).title; | |
const isShorts = !!$('[overlay-style="SHORTS"]', el); | |
const soon = !!$('[aria-label="Скоро"]', el); | |
const progress = parseFloat($('#progress', el)?.style.width || '0'); | |
const menuTrigger = $('[aria-label="Меню действий"]', el); | |
const skipped = isShorts || soon || progress > 80; | |
console.log( | |
`%c%s: %o`, | |
`color: ${skipped ? 'red' : 'green'}`, | |
title, | |
{isShorts, soon, progress}, | |
); | |
if (skipped) { | |
continue; | |
} | |
menuTrigger.click(); | |
await pause(100); | |
const addBtn = $$('ytd-popup-container ytd-menu-service-item-renderer')[0]; | |
addBtn.click(); | |
await pause(100); | |
} catch (err) { | |
console.info('video', el, err); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment