-
-
Save KebabLord/0cd4b0391fba147869fbdac10fc31621 to your computer and use it in GitHub Desktop.
| // ==UserScript== | |
| // @name YouTube Ads Accelerator | |
| // @namespace https://youtube.com/ | |
| // @version 1.1 | |
| // @author Kebablord | |
| // @description Speed up YouTube ads by 200x when they appear | |
| // @match https://www.youtube.com/* | |
| // @grant none | |
| // @run-at document-end | |
| // @updateURL https://gist.githubusercontent.com/KebabLord/0cd4b0391fba147869fbdac10fc31621/raw/youtube-ad-accelerator.user.js | |
| // @downloadURL https://gist.githubusercontent.com/KebabLord/0cd4b0391fba147869fbdac10fc31621/raw/youtube-ad-accelerator.user.js | |
| // ==/UserScript== | |
| // Firefox supports unlimited video playback speed while Chromium based browsers support maximum 16 | |
| const isFirefox = /firefox/i.test(navigator.userAgent); | |
| const maxRate = isFirefox ? 200 : 16; | |
| (function() { | |
| 'use strict'; | |
| async function accelerateAdPlayback() { | |
| const isAdVisible = () => { | |
| const el = document.querySelector('div.ytp-ad-player-overlay-layout__ad-info-container'); | |
| return el && el.offsetParent !== null; | |
| }; | |
| const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
| const trySpeedUpAd = async () => { | |
| if (!isAdVisible()) return; | |
| const ad = document.querySelectorAll('video.video-stream.html5-main-video')[0]; | |
| if (!ad || ad.paused) return; | |
| ad.playbackRate = maxRate; | |
| while (!ad.paused) { | |
| await wait(100); | |
| } | |
| }; | |
| setInterval(() => { | |
| trySpeedUpAd(); | |
| }, 500); | |
| } | |
| accelerateAdPlayback(); | |
| })(); |
@LuisTorresGonzalez sorry for responding this late, did you try this on your browser does it work? Because when i tried a similar workaround when i initially created this user script, it wasn't working because youtube js checks if the click event is event.isTrusted so it never worked. A workaround i came up with for this was disable isTrusted from youtube's js on page load but this is a bit complicated.
Hi, worked for some days, but then I got stuck into the "You need to see ads or we will disable the player" banner, havent found a way to actually bypass the isTrusted thingy, so i deleted it from my script.
But there is another thing I wanted to share with you
for some reason yt kind of monitors the time you have seen ads when the ads comes from yt (at least in my country), so I implemented something like this
const adOrigin = document.querySelector('span.ytp-visit-advertiser-link__text');
const isYTAdd = adOrigin.textContent.includes('youtube');
ad.playbackRate = isYTAdd ? 1 : maxRate;
this way I dont actually skip those ones, otherwise it shows me the banner blocking my video,
i dont know if any others ads partners are "monitored" as well and even yt ads are not always "monitored", so take it if you ever see something like that
And also wanted to say thanks for giving something that has been usefull for me!
Hi, Id like to propose a change to autoclick the skip ad button
near line 37 we can do something like