Skip to content

Instantly share code, notes, and snippets.

@kgutwin
Created October 30, 2023 13:40
Show Gist options
  • Save kgutwin/28a6af8343b849364388157950f39555 to your computer and use it in GitHub Desktop.
Save kgutwin/28a6af8343b849364388157950f39555 to your computer and use it in GitHub Desktop.
YouTube automatic "ad skip" bookmarklet
javascript:(function()%7B!function()%7Bvar%20t%2Cn%2Ce%2Cr%3D%5B%22videoAdUiSkipButton%22%2C%22ytp-ad-skip-button%20ytp-button%22%2C%22ytp-ad-overlay-close-button%22%5D%3Bfunction%20o(t)%7Breturn%20null!%3D%3Dt.offsetParent%7Dfunction%20i()%7Bvar%20t%3B(t%3Dr%2Ct.map(t%3D%3EArray.from(document.getElementsByClassName(t))%7C%7C%5B%5D).reduce(function(t%2Cn)%7Breturn%20t.concat(n)%7D%2C%5B%5D)).forEach(t%3D%3E%7Bo(t)%3Fu(t)%3Afunction(t)%7Bif(t!%3D%3Dn)%7Bvar%20r%3Dfunction()%7Bfor(var%20n%3Dt%3Bnull!%3D%3Dn%3B)%7Bif(%22none%22%3D%3D%3Dn.style.display)return%20n%3Bn%3Dn.parentElement%7Dreturn%20null%7D()%3Br%26%26(e%26%26n%26%26(e.disconnect()%2Cu(n))%2Ce%7C%7C(e%3Dnew%20MutationObserver(function()%7Bo(n)%26%26(u(n)%2Cn%3Dvoid%200%2Ce.disconnect())%7D))%2Cn%3Dt%2Ce.observe(r%2C%7Battributes%3A!0%7D))%7D%7D(t)%7D)%7Dfunction%20u(t)%7Bif(%22function%22%3D%3Dtypeof%20t.fireEvent)t.fireEvent(%22onclick%22)%3Belse%20if(%22function%22%3D%3Dtypeof%20t.dispatchEvent)%7Bvar%20n%3Ddocument.createEvent(%22Events%22)%3Bn.initEvent(%22click%22%2C!0%2C!1)%2Ct.dispatchEvent(n)%7D%7D(function()%7Btry%7Breturn%20window.self!%3D%3Dwindow.top%7Dcatch(t)%7Breturn!0%7D%7D)()%7C%7Cfunction%20n()%7BclearTimeout(t)%2Cfunction()%7Bif(!(%22MutationObserver%22in%20window))return!1%3Bvar%20n%3Ddocument.querySelector(%22ytd-player%23ytd-player%22)%3Breturn!!n%26%26(new%20MutationObserver(function()%7Bi()%7D).observe(n%2C%7BchildList%3A!0%2Csubtree%3A!0%7D)%2CclearTimeout(t)%2C!0)%7D()%7C%7C(t%3DsetTimeout(function()%7Bi()%2Cn()%7D%2C2e3))%7D()%7D()%7D)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment