Last active
May 7, 2025 17:26
-
-
Save jazeee/d8e8d0a67263fd46cafabffb62551d50 to your computer and use it in GitHub Desktop.
Deal with a website that forces you to watch videos without leaving focus or plays them very slowly
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
| ** | |
| * When you encounter a website that forces you to watch videos without | |
| * leaving focus or plays them very slowly, this set of code may help. | |
| * Your mileage may vary, so play around. | |
| * | |
| * First, set the right browser context in your console. | |
| * Easiest is to right click on an element in the UI, and inspect. | |
| * Alternatively, find it in the context dropdown under the `top` context. | |
| * Example, `contentRelay` | |
| */ | |
| selectAllElements = $$; | |
| async function goNextOrPlayRelevantVideoOrAudio() { | |
| const nextAction = selectAllElements('[title="Play"],[title="Next"],[aria-label="Next"],.kTAWOq'); | |
| if (nextAction.length > 0) { | |
| nextAction.at(-1)?.click(); | |
| return; | |
| } | |
| const audioElements = selectAllElements('audio'); | |
| const videoElements = selectAllElements('video'); | |
| if (videoElements.length > 0) { | |
| videoElements.at(-1)?.play(); | |
| } else { | |
| audioElements.forEach((audioElement) => { | |
| audioElement.play(); | |
| }); | |
| } | |
| } | |
| async function speedUpPlaybackAndWait() { | |
| const audioElements = selectAllElements('audio'); | |
| const videoElements = selectAllElements('video'); | |
| audioElements.forEach((audioElement) => { | |
| audioElement.playbackRate = 2; | |
| }) | |
| videoElements.forEach((videoElement) => { | |
| videoElement.playbackRate = 2; | |
| }) | |
| return new Promise((resolve) => setTimeout(resolve, 500)); | |
| } | |
| for (let i = 0; i < 10000; i += 1) { | |
| await speedUpPlaybackAndWait(); | |
| if (i % 100 === 0) { | |
| console.log(i); | |
| } | |
| } | |
| goNextOrPlayRelevantVideoOrAudio(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment