Fix muted streams pausing when switching tabs on chrome #336

This commit is contained in:
pixeltris
2025-07-20 21:02:57 +01:00
parent 69a2e17a5b
commit 6eefa4d2fa
4 changed files with 78 additions and 18 deletions
+19 -4
View File
@@ -1,7 +1,7 @@
twitch-videoad.js text/javascript
(function() {
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
var ourTwitchAdSolutionsVersion = 7;// Only bump this when there's a breaking change to Twitch, the script, or there's a conflict with an unmaintained extension which uses this script
var ourTwitchAdSolutionsVersion = 8;// Used to prevent conflicts with outdated versions of the scripts
if (typeof unsafeWindow === 'undefined') {
unsafeWindow = window;
}
@@ -789,6 +789,7 @@ twitch-videoad.js text/javascript
}
});
}catch{}
let hidden = document.__lookupGetter__('hidden');
try {
Object.defineProperty(document, 'hidden', {
get() {
@@ -801,9 +802,23 @@ twitch-videoad.js text/javascript
e.stopPropagation();
e.stopImmediatePropagation();
};
document.addEventListener('visibilitychange', block, true);
document.addEventListener('webkitvisibilitychange', block, true);
document.addEventListener('mozvisibilitychange', block, true);
let wasVideoPlaying = true;
var visibilityChange = e => {
if (typeof chrome !== 'undefined') {
const videos = document.getElementsByTagName('video');
if (videos.length > 0) {
if (hidden.apply(document) === true) {
wasVideoPlaying = !videos[0].paused && !videos[0].ended;
} else if (wasVideoPlaying && !videos[0].ended) {
videos[0].play();
}
}
}
block(e);
};
document.addEventListener('visibilitychange', visibilityChange, true);
document.addEventListener('webkitvisibilitychange', visibilityChange, true);
document.addEventListener('mozvisibilitychange', visibilityChange, true);
document.addEventListener('hasFocus', block, true);
try {
if (/Firefox/.test(navigator.userAgent)) {
+20 -5
View File
@@ -1,7 +1,7 @@
// ==UserScript==
// @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.40
// @version 1.41
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js
// @description Multiple solutions for blocking Twitch ads (video-swap-new)
@@ -14,7 +14,7 @@
// ==/UserScript==
(function() {
'use strict';
var ourTwitchAdSolutionsVersion = 7;// Only bump this when there's a breaking change to Twitch, the script, or there's a conflict with an unmaintained extension which uses this script
var ourTwitchAdSolutionsVersion = 8;// Used to prevent conflicts with outdated versions of the scripts
if (typeof unsafeWindow === 'undefined') {
unsafeWindow = window;
}
@@ -802,6 +802,7 @@
}
});
}catch{}
let hidden = document.__lookupGetter__('hidden');
try {
Object.defineProperty(document, 'hidden', {
get() {
@@ -814,9 +815,23 @@
e.stopPropagation();
e.stopImmediatePropagation();
};
document.addEventListener('visibilitychange', block, true);
document.addEventListener('webkitvisibilitychange', block, true);
document.addEventListener('mozvisibilitychange', block, true);
let wasVideoPlaying = true;
var visibilityChange = e => {
if (typeof chrome !== 'undefined') {
const videos = document.getElementsByTagName('video');
if (videos.length > 0) {
if (hidden.apply(document) === true) {
wasVideoPlaying = !videos[0].paused && !videos[0].ended;
} else if (wasVideoPlaying && !videos[0].ended) {
videos[0].play();
}
}
}
block(e);
};
document.addEventListener('visibilitychange', visibilityChange, true);
document.addEventListener('webkitvisibilitychange', visibilityChange, true);
document.addEventListener('mozvisibilitychange', visibilityChange, true);
document.addEventListener('hasFocus', block, true);
try {
if (/Firefox/.test(navigator.userAgent)) {