Last active
February 5, 2026 06:25
-
-
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 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
| (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 titleEl = $('#video-title, .yt-lockup-metadata-view-model__heading-reset', el); | |
| if (!titleEl) { | |
| console.info('title not found'); | |
| continue; | |
| } | |
| const title = titleEl.title; | |
| const isShorts = !!$('[overlay-style="SHORTS"]', el); | |
| const soon = !!$('[aria-label="Скоро"], [aria-label="Upcoming"], [aria-label="Soon"]', el); | |
| const progress = parseFloat($('.ytThumbnailOverlayProgressBarHostWatchedProgressBarSegment, #progress', el)?.style.width || '0'); | |
| const menuTrigger = $('[aria-label="Ещё"], [aria-label="More"], [aria-label="Меню действий"], [aria-label="Action menu"]', el); | |
| const skipped = isShorts || soon || progress > 80; | |
| console.log( | |
| `%c%s: %o`, | |
| `color: ${skipped ? 'red' : 'green'}`, | |
| title, | |
| {isShorts, soon, progress}, | |
| ); | |
| if (skipped) { | |
| continue; | |
| } | |
| if (!menuTrigger) { | |
| console.error(`menuTrigger is not found`); | |
| break; | |
| } | |
| menuTrigger.click(); | |
| await pause(100); | |
| const addBtn = $$('.ytContextualSheetLayoutContentContainer .yt-list-item-view-model, ytd-popup-container ytd-menu-service-item-renderer')[0]; | |
| if (!addBtn) { | |
| console.error(`addBtn is not found`); | |
| break; | |
| } | |
| 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