Twitch - Mute ads and optionally hide them

Automatically mutes the Twitch player when an advertisement started and unmute it once finished. You can also hide ads by setting disableDisplay to true.

Forfatter
Harest
Daglige installasjoner
11
Totale installasjoner
7 072
Vurderinger
11 0 0
Versjon
1.1612
Lagd
14.08.2018
Oppdatert
09.01.2024
Lisens
MIT
Gjelder

Automatically mutes the Twitch player when an advertisement started and unmute it once finished. You can also hide ads by setting the property disableDisplay to true. There's several variables you can edit as you want.
Since v1.146, you can still hear the stream during ads, thanks to the small player (top-right) Twitch displays.

Changelog:

  • v1.1612: Very minor fix to avoid pre-roll ad anticipation to trigger on the player when you visit the channel pages.
  • v1.1611: Moved a single line of code to allow ads detection on offline channel pages, when there's another stream embedded.
  • v1.161: Very small improvements. When i wanted to optimize a bit the main loop, i forgot Twitch redraw the DOM elements where we add the ads options button when you want to check stream info for instance. So i added back a check, but with a longer delay as it's not too important to have this button.
  • v1.16: Added a pre-roll ad anticipation option (anticipatePreroll, disabled by default) it will mute and/or hide the player for a set period of time on initial stream loading. Removed squad stream specific code, Twitch removed it for Stream Together instead. Prepared the script for Picture in Picture support. Small additional improvements (refactoring, better buttons style & highlighting of editable settings). Ad check rate now switched from 1s to 0.5s by default.
  • v1.15: Cleaned up the code a bit, as the period with co-existing players is long gone. Also copied the volume currently set over the small stream player displayed top right during ads.
  • v1.146: Enabled stream audio during ads, when Twitch allow you to see the stream top right (and you don't have it muted before the ad(s)).
  • v1.145: Updated with the new changes with ads on Twitch (others updates may follow, seems to be some massive changes, with new "audio ads" and such). Also minor fix for squad streams. Switching to squad stream mode previously during an ad would not keep the ad detection.
  • Since v1.1441, added yet another potential fallback in case of a new class name change. So that old versions of the script may still work.
  • v1.14: Updated with latest Twitch changes. They keep obfuscating class names.
  • v1.13: Updated due to current offensive of Twitch towards adblockers. It's unbearable. Note: Squad might not work atm, i don't know if they did class changes since. Will update if needed.
  • v1.11 & 1.12: Highwind or old player is automatically detected.
  • v1.10: Updated for the new "Highwind player".
  • v1.09: Updated the display of Ads Options buttons in the new Twitch design.
  • v1.08: Added Squad page support.
  • v1.07: Added a minimum ads duration since Twitch sometimes removed the ad notice before the end. Default to 15s, editable.
  • Since v1.06, it displays an "Ads Options" button next to the viewer count to allow you to switch temporarily from your default display setting for the player during an ad (show/hide), or to unlock the player in case the ad notice wasn't properly removed at the end of the ad(s) by Twitch and you don't want to wait the auto unlock (set to be triggered after 2m30 elapsed with ad(s) in progress).

Old notices:

2023-12-19 Notice: Release of v1.16. Picture in Picture support still not in Firefox 121, but the script should be ready for it.
2023-12-17 Notice: Currently testing pre-roll ad anticipation, it'll be off by default. I'll remove squad stream stuff in a near future as it's going away. Waiting Firefox v121 (in 2 days normally) to add Picture in Picture support so it's also hidden during an ad if you set disableDisplay to true.
2020-11-01 Notice: uBlock Origin once in a while doesn't work properly to block the ads. Temporary fix likes this one makes things worse. I decided to quickly update my script and use it again in the meantime. Previously noted problem below doesn't seem to be existing anymore.
2019-11-24 Notice: Use uBlock Origin. Twitch wants you to see their ads too much. They hindered this script again by delaying the display of the ad notice (used to know if an ad is in progress), and by pausing the ad despite the player is in a playing state.