Fix muted streams pausing when switching tabs on chrome #336
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -1018,6 +1018,7 @@ twitch-videoad.js text/javascript
|
||||
}
|
||||
});
|
||||
}catch{}
|
||||
let hidden = document.__lookupGetter__('hidden');
|
||||
try {
|
||||
Object.defineProperty(document, 'hidden', {
|
||||
get() {
|
||||
@@ -1030,9 +1031,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)) {
|
||||
|
||||
Reference in New Issue
Block a user