Fix backup player types #471
Also fixed video-swap-new not working correctly in Firefox on embeded pages
This commit is contained in:
@@ -2,7 +2,7 @@ twitch-videoad.js text/javascript
|
||||
(function() {
|
||||
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
|
||||
'use strict';
|
||||
var ourTwitchAdSolutionsVersion = 15;// Used to prevent conflicts with outdated versions of the scripts
|
||||
var ourTwitchAdSolutionsVersion = 16;// Used to prevent conflicts with outdated versions of the scripts
|
||||
if (typeof window.twitchAdSolutionsVersion !== 'undefined' && window.twitchAdSolutionsVersion >= ourTwitchAdSolutionsVersion) {
|
||||
console.log("skipping vaft as there's another script active. ourVersion:" + ourTwitchAdSolutionsVersion + " activeVersion:" + window.twitchAdSolutionsVersion);
|
||||
window.twitchAdSolutionsVersion = ourTwitchAdSolutionsVersion;
|
||||
@@ -22,6 +22,7 @@ twitch-videoad.js text/javascript
|
||||
scope.SkipPlayerReloadOnHevc = false;// If true this will skip player reload on streams which have 2k/4k quality (if you enable this and you use the 2k/4k quality setting you'll get error #4000 / #3000 / spinning wheel on chrome based browsers)
|
||||
scope.AlwaysReloadPlayerOnAd = false;
|
||||
scope.PlayerReloadLowResTime = 1500;
|
||||
scope.DisableMatureConentPopup = false;// If true this avoids having to log in to watch age gated content
|
||||
scope.StreamInfos = [];
|
||||
scope.StreamInfosByUrl = [];
|
||||
scope.GQLDeviceID = null;
|
||||
@@ -532,7 +533,7 @@ twitch-videoad.js text/javascript
|
||||
if (playerType == FallbackPlayerType) {
|
||||
fallbackM3u8 = m3u8Text;
|
||||
}
|
||||
if (!m3u8Text.includes(AdSignifier) && (SimulatedAdsDepth == 0 || playerTypeIndex >= SimulatedAdsDepth - 1)) {
|
||||
if ((!m3u8Text.includes(AdSignifier) && (SimulatedAdsDepth == 0 || playerTypeIndex >= SimulatedAdsDepth - 1)) || (!fallbackM3u8 && playerTypeIndex >= BackupPlayerTypes.length - 1)) {
|
||||
backupPlayerType = playerType;
|
||||
backupM3u8 = m3u8Text;
|
||||
break;
|
||||
@@ -601,9 +602,9 @@ twitch-videoad.js text/javascript
|
||||
'playerType': playerType
|
||||
}
|
||||
};
|
||||
return gqlRequest(body);
|
||||
return gqlRequest(body, playerType);
|
||||
}
|
||||
function gqlRequest(body) {
|
||||
function gqlRequest(body, playerType) {
|
||||
if (!GQLDeviceID) {
|
||||
var dcharacters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var dcharactersLength = dcharacters.length;
|
||||
@@ -620,6 +621,12 @@ twitch-videoad.js text/javascript
|
||||
...(ClientVersion && {'Client-Version': ClientVersion}),
|
||||
...(ClientSession && {'Client-Session-Id': ClientSession})
|
||||
};
|
||||
if (playerType != 'site') {
|
||||
headers = {
|
||||
'Client-Id': ClientID,
|
||||
'X-Device-Id': GQLDeviceID
|
||||
};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestId = Math.random().toString(36).substring(2, 15);
|
||||
const fetchRequest = {
|
||||
@@ -698,9 +705,13 @@ twitch-videoad.js text/javascript
|
||||
const lsKeyQuality = 'video-quality';
|
||||
const lsKeyMuted = 'video-muted';
|
||||
const lsKeyVolume = 'volume';
|
||||
var currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
var currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
var currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
var currentQualityLS = null;
|
||||
var currentMutedLS = null;
|
||||
var currentVolumeLS = null;
|
||||
try {
|
||||
currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
if (localStorageHookFailed && player?.core?.state) {
|
||||
localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted}));
|
||||
localStorage.setItem(lsKeyVolume, player.core.state.volume);
|
||||
@@ -708,13 +719,22 @@ twitch-videoad.js text/javascript
|
||||
if (localStorageHookFailed && player?.core?.state?.quality?.group) {
|
||||
localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group}));
|
||||
}
|
||||
} catch {}
|
||||
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });
|
||||
player.play();
|
||||
if (localStorageHookFailed) {
|
||||
if (localStorageHookFailed && (currentQualityLS || currentMutedLS || currentVolumeLS)) {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentQualityLS) {
|
||||
localStorage.setItem(lsKeyQuality, currentQualityLS);
|
||||
}
|
||||
if (currentMutedLS) {
|
||||
localStorage.setItem(lsKeyMuted, currentMutedLS);
|
||||
}
|
||||
if (currentVolumeLS) {
|
||||
localStorage.setItem(lsKeyVolume, currentVolumeLS);
|
||||
}
|
||||
} catch {}
|
||||
}, 3000);
|
||||
}
|
||||
return;
|
||||
@@ -772,7 +792,7 @@ twitch-videoad.js text/javascript
|
||||
if (typeof init.headers['Authorization'] === 'string' && init.headers['Authorization'] !== AuthorizationHeader) {
|
||||
postTwitchWorkerMessage('UpdateAuthorizationHeader', AuthorizationHeader = init.headers['Authorization']);
|
||||
}
|
||||
if (ForceAccessTokenPlayerType && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture')) {
|
||||
if (ForceAccessTokenPlayerType && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture') && !init.body.includes('frontpage')) {
|
||||
let replacedPlayerType = '';
|
||||
const newBody = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody)) {
|
||||
@@ -793,6 +813,22 @@ twitch-videoad.js text/javascript
|
||||
init.body = JSON.stringify(newBody);
|
||||
}
|
||||
}
|
||||
if (DisableMatureConentPopup) {
|
||||
const newBody2 = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody2)) {
|
||||
var hasRemovedClassification = false;
|
||||
for (let i = 0; i < newBody2.length; i++) {
|
||||
if (newBody2[i]?.operationName == 'ContentClassificationContext') {
|
||||
hasRemovedClassification = true;
|
||||
// Doesn't seem like it if we remove this element from the array so instead we duplicate another entry into this index. TODO: Find out why
|
||||
newBody2[i] = newBody2[i == 0 && newBody2.length > 1 ? 1 : 0];
|
||||
}
|
||||
}
|
||||
if (hasRemovedClassification) {
|
||||
init.body = JSON.stringify(newBody2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return realFetch.apply(this, arguments);
|
||||
@@ -856,6 +892,7 @@ twitch-videoad.js text/javascript
|
||||
}
|
||||
}catch{}
|
||||
// Hooks for preserving volume / resolution
|
||||
try {
|
||||
var keysToCache = [
|
||||
'video-quality',
|
||||
'video-muted',
|
||||
@@ -886,6 +923,10 @@ twitch-videoad.js text/javascript
|
||||
// Firefox doesn't allow hooking of localStorage functions but chrome does
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('localStorageHooks failed ' + err)
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
}
|
||||
declareOptions(window);
|
||||
hookWindowWorker();
|
||||
|
||||
+51
-10
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name TwitchAdSolutions (vaft)
|
||||
// @namespace https://github.com/pixeltris/TwitchAdSolutions
|
||||
// @version 28.0.0
|
||||
// @version 29.0.0
|
||||
// @description Multiple solutions for blocking Twitch ads (vaft)
|
||||
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
|
||||
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
|
||||
@@ -13,7 +13,7 @@
|
||||
// ==/UserScript==
|
||||
(function() {
|
||||
'use strict';
|
||||
var ourTwitchAdSolutionsVersion = 15;// Used to prevent conflicts with outdated versions of the scripts
|
||||
var ourTwitchAdSolutionsVersion = 16;// Used to prevent conflicts with outdated versions of the scripts
|
||||
if (typeof window.twitchAdSolutionsVersion !== 'undefined' && window.twitchAdSolutionsVersion >= ourTwitchAdSolutionsVersion) {
|
||||
console.log("skipping vaft as there's another script active. ourVersion:" + ourTwitchAdSolutionsVersion + " activeVersion:" + window.twitchAdSolutionsVersion);
|
||||
window.twitchAdSolutionsVersion = ourTwitchAdSolutionsVersion;
|
||||
@@ -33,6 +33,7 @@
|
||||
scope.SkipPlayerReloadOnHevc = false;// If true this will skip player reload on streams which have 2k/4k quality (if you enable this and you use the 2k/4k quality setting you'll get error #4000 / #3000 / spinning wheel on chrome based browsers)
|
||||
scope.AlwaysReloadPlayerOnAd = false;
|
||||
scope.PlayerReloadLowResTime = 1500;
|
||||
scope.DisableMatureConentPopup = false;// If true this avoids having to log in to watch age gated content
|
||||
scope.StreamInfos = [];
|
||||
scope.StreamInfosByUrl = [];
|
||||
scope.GQLDeviceID = null;
|
||||
@@ -543,7 +544,7 @@
|
||||
if (playerType == FallbackPlayerType) {
|
||||
fallbackM3u8 = m3u8Text;
|
||||
}
|
||||
if (!m3u8Text.includes(AdSignifier) && (SimulatedAdsDepth == 0 || playerTypeIndex >= SimulatedAdsDepth - 1)) {
|
||||
if ((!m3u8Text.includes(AdSignifier) && (SimulatedAdsDepth == 0 || playerTypeIndex >= SimulatedAdsDepth - 1)) || (!fallbackM3u8 && playerTypeIndex >= BackupPlayerTypes.length - 1)) {
|
||||
backupPlayerType = playerType;
|
||||
backupM3u8 = m3u8Text;
|
||||
break;
|
||||
@@ -612,9 +613,9 @@
|
||||
'playerType': playerType
|
||||
}
|
||||
};
|
||||
return gqlRequest(body);
|
||||
return gqlRequest(body, playerType);
|
||||
}
|
||||
function gqlRequest(body) {
|
||||
function gqlRequest(body, playerType) {
|
||||
if (!GQLDeviceID) {
|
||||
var dcharacters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var dcharactersLength = dcharacters.length;
|
||||
@@ -631,6 +632,12 @@
|
||||
...(ClientVersion && {'Client-Version': ClientVersion}),
|
||||
...(ClientSession && {'Client-Session-Id': ClientSession})
|
||||
};
|
||||
if (playerType != 'site') {
|
||||
headers = {
|
||||
'Client-Id': ClientID,
|
||||
'X-Device-Id': GQLDeviceID
|
||||
};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestId = Math.random().toString(36).substring(2, 15);
|
||||
const fetchRequest = {
|
||||
@@ -709,9 +716,13 @@
|
||||
const lsKeyQuality = 'video-quality';
|
||||
const lsKeyMuted = 'video-muted';
|
||||
const lsKeyVolume = 'volume';
|
||||
var currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
var currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
var currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
var currentQualityLS = null;
|
||||
var currentMutedLS = null;
|
||||
var currentVolumeLS = null;
|
||||
try {
|
||||
currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
if (localStorageHookFailed && player?.core?.state) {
|
||||
localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted}));
|
||||
localStorage.setItem(lsKeyVolume, player.core.state.volume);
|
||||
@@ -719,13 +730,22 @@
|
||||
if (localStorageHookFailed && player?.core?.state?.quality?.group) {
|
||||
localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group}));
|
||||
}
|
||||
} catch {}
|
||||
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });
|
||||
player.play();
|
||||
if (localStorageHookFailed) {
|
||||
if (localStorageHookFailed && (currentQualityLS || currentMutedLS || currentVolumeLS)) {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentQualityLS) {
|
||||
localStorage.setItem(lsKeyQuality, currentQualityLS);
|
||||
}
|
||||
if (currentMutedLS) {
|
||||
localStorage.setItem(lsKeyMuted, currentMutedLS);
|
||||
}
|
||||
if (currentVolumeLS) {
|
||||
localStorage.setItem(lsKeyVolume, currentVolumeLS);
|
||||
}
|
||||
} catch {}
|
||||
}, 3000);
|
||||
}
|
||||
return;
|
||||
@@ -783,7 +803,7 @@
|
||||
if (typeof init.headers['Authorization'] === 'string' && init.headers['Authorization'] !== AuthorizationHeader) {
|
||||
postTwitchWorkerMessage('UpdateAuthorizationHeader', AuthorizationHeader = init.headers['Authorization']);
|
||||
}
|
||||
if (ForceAccessTokenPlayerType && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture')) {
|
||||
if (ForceAccessTokenPlayerType && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture') && !init.body.includes('frontpage')) {
|
||||
let replacedPlayerType = '';
|
||||
const newBody = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody)) {
|
||||
@@ -804,6 +824,22 @@
|
||||
init.body = JSON.stringify(newBody);
|
||||
}
|
||||
}
|
||||
if (DisableMatureConentPopup) {
|
||||
const newBody2 = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody2)) {
|
||||
var hasRemovedClassification = false;
|
||||
for (let i = 0; i < newBody2.length; i++) {
|
||||
if (newBody2[i]?.operationName == 'ContentClassificationContext') {
|
||||
hasRemovedClassification = true;
|
||||
// Doesn't seem like it if we remove this element from the array so instead we duplicate another entry into this index. TODO: Find out why
|
||||
newBody2[i] = newBody2[i == 0 && newBody2.length > 1 ? 1 : 0];
|
||||
}
|
||||
}
|
||||
if (hasRemovedClassification) {
|
||||
init.body = JSON.stringify(newBody2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return realFetch.apply(this, arguments);
|
||||
@@ -867,6 +903,7 @@
|
||||
}
|
||||
}catch{}
|
||||
// Hooks for preserving volume / resolution
|
||||
try {
|
||||
var keysToCache = [
|
||||
'video-quality',
|
||||
'video-muted',
|
||||
@@ -897,6 +934,10 @@
|
||||
// Firefox doesn't allow hooking of localStorage functions but chrome does
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('localStorageHooks failed ' + err)
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
}
|
||||
declareOptions(window);
|
||||
hookWindowWorker();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
twitch-videoad.js text/javascript
|
||||
(function() {
|
||||
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
|
||||
var ourTwitchAdSolutionsVersion = 15;// Used to prevent conflicts with outdated versions of the scripts
|
||||
var ourTwitchAdSolutionsVersion = 16;// Used to prevent conflicts with outdated versions of the scripts
|
||||
if (typeof window.twitchAdSolutionsVersion !== 'undefined' && window.twitchAdSolutionsVersion >= ourTwitchAdSolutionsVersion) {
|
||||
console.log("skipping video-swap-new as there's another script active. ourVersion:" + ourTwitchAdSolutionsVersion + " activeVersion:" + window.twitchAdSolutionsVersion);
|
||||
window.twitchAdSolutionsVersion = ourTwitchAdSolutionsVersion;
|
||||
@@ -13,6 +13,7 @@ twitch-videoad.js text/javascript
|
||||
scope.OPT_BACKUP_PLAYER_TYPES = [ 'autoplay', 'picture-by-picture', 'embed' ];
|
||||
scope.OPT_BACKUP_PLATFORM = 'android';
|
||||
scope.OPT_FORCE_ACCESS_TOKEN_PLAYER_TYPE = 'site';
|
||||
scope.OPT_DISABLE_MATURE_CONTENT_POPUP = false;// If true this avoids having to log in to watch age gated content
|
||||
scope.AD_SIGNIFIER = 'stitched-ad';
|
||||
scope.LIVE_SIGNIFIER = ',live';
|
||||
scope.CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
|
||||
@@ -275,12 +276,12 @@ twitch-videoad.js text/javascript
|
||||
var streamM3u8Response = await realFetch(streamM3u8Url);
|
||||
if (streamM3u8Response.status === 200) {
|
||||
var backTextStr = await streamM3u8Response.text();
|
||||
if ((!backTextStr.includes(AD_SIGNIFIER) && (SimulatedAdsDepth == 0 || i >= SimulatedAdsDepth - 1)) || streamInfo.BackupEncodingsStatus.size >= playerTypes.length - 1) {
|
||||
if ((!backTextStr.includes(AD_SIGNIFIER) && (SimulatedAdsDepth == 0 || i >= SimulatedAdsDepth - 1)) || i >= playerTypes.length - 1) {
|
||||
result = backTextStr;
|
||||
backupPlayerTypeInfo = ' (' + playerType + ')';
|
||||
streamInfo.BackupEncodingsStatus.set(playerType, 1);
|
||||
streamInfo.BackupEncodingsPlayerTypeIndex = i;
|
||||
if (playerType !== 'embed' && streamInfo.Encodings != null) {
|
||||
if (streamInfo.Encodings != null) {
|
||||
// Low resolution streams will reduce the number of resolutions in the UI. To fix this we merge the low res URLs into the main m3u8
|
||||
var normalEncodingsM3u8 = streamInfo.Encodings;
|
||||
var normalLines = normalEncodingsM3u8.replace('\r', '').split('\n');
|
||||
@@ -544,9 +545,9 @@ twitch-videoad.js text/javascript
|
||||
'playerType': playerType
|
||||
}
|
||||
};
|
||||
return gqlRequest(body);
|
||||
return gqlRequest(body, playerType);
|
||||
}
|
||||
function gqlRequest(body) {
|
||||
function gqlRequest(body, playerType) {
|
||||
if (!gql_device_id) {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (let i = 0; i < 32; i += 1) {
|
||||
@@ -560,6 +561,12 @@ twitch-videoad.js text/javascript
|
||||
'Authorization': AuthorizationHeader,
|
||||
...(ClientIntegrityHeader && {'Client-Integrity': ClientIntegrityHeader})
|
||||
};
|
||||
if (playerType != 'site') {
|
||||
headers = {
|
||||
'Client-Id': CLIENT_ID,
|
||||
'X-Device-Id': gql_device_id
|
||||
};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestId = Math.random().toString(36).substring(2, 15);
|
||||
const fetchRequest = {
|
||||
@@ -637,7 +644,7 @@ twitch-videoad.js text/javascript
|
||||
if (typeof init.headers['Authorization'] === 'string' && init.headers['Authorization'] !== AuthorizationHeader) {
|
||||
postTwitchWorkerMessage('UpdateAuthorizationHeader', AuthorizationHeader = init.headers['Authorization']);
|
||||
}
|
||||
if (OPT_FORCE_ACCESS_TOKEN_PLAYER_TYPE && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture')) {
|
||||
if (OPT_FORCE_ACCESS_TOKEN_PLAYER_TYPE && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture') && !init.body.includes('frontpage')) {
|
||||
let replacedPlayerType = '';
|
||||
const newBody = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody)) {
|
||||
@@ -658,6 +665,22 @@ twitch-videoad.js text/javascript
|
||||
init.body = JSON.stringify(newBody);
|
||||
}
|
||||
}
|
||||
if (OPT_DISABLE_MATURE_CONTENT_POPUP) {
|
||||
const newBody2 = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody2)) {
|
||||
var hasRemovedClassification = false;
|
||||
for (let i = 0; i < newBody2.length; i++) {
|
||||
if (newBody2[i]?.operationName == 'ContentClassificationContext') {
|
||||
hasRemovedClassification = true;
|
||||
// Doesn't seem like it if we remove this element from the array so instead we duplicate another entry into this index. TODO: Find out why
|
||||
newBody2[i] = newBody2[i == 0 && newBody2.length > 1 ? 1 : 0];
|
||||
}
|
||||
}
|
||||
if (hasRemovedClassification) {
|
||||
init.body = JSON.stringify(newBody2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return realFetch.apply(this, arguments);
|
||||
@@ -729,9 +752,13 @@ twitch-videoad.js text/javascript
|
||||
const lsKeyQuality = 'video-quality';
|
||||
const lsKeyMuted = 'video-muted';
|
||||
const lsKeyVolume = 'volume';
|
||||
var currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
var currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
var currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
var currentQualityLS = null;
|
||||
var currentMutedLS = null;
|
||||
var currentVolumeLS = null;
|
||||
try {
|
||||
currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
if (localStorageHookFailed && player?.core?.state) {
|
||||
localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted}));
|
||||
localStorage.setItem(lsKeyVolume, player.core.state.volume);
|
||||
@@ -739,13 +766,22 @@ twitch-videoad.js text/javascript
|
||||
if (localStorageHookFailed && player?.core?.state?.quality?.group) {
|
||||
localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group}));
|
||||
}
|
||||
} catch {}
|
||||
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });
|
||||
player.play();
|
||||
if (localStorageHookFailed) {
|
||||
if (localStorageHookFailed && (currentQualityLS || currentMutedLS || currentVolumeLS)) {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentQualityLS) {
|
||||
localStorage.setItem(lsKeyQuality, currentQualityLS);
|
||||
}
|
||||
if (currentMutedLS) {
|
||||
localStorage.setItem(lsKeyMuted, currentMutedLS);
|
||||
}
|
||||
if (currentVolumeLS) {
|
||||
localStorage.setItem(lsKeyVolume, currentVolumeLS);
|
||||
}
|
||||
} catch {}
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
@@ -807,6 +843,7 @@ twitch-videoad.js text/javascript
|
||||
}
|
||||
}catch{}
|
||||
// Hooks for preserving volume / resolution
|
||||
try {
|
||||
var keysToCache = [
|
||||
'video-quality',
|
||||
'video-muted',
|
||||
@@ -837,6 +874,10 @@ twitch-videoad.js text/javascript
|
||||
// Firefox doesn't allow hooking of localStorage functions but chrome does
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('localStorageHooks failed ' + err)
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
}
|
||||
window.reloadTwitchPlayer = reloadTwitchPlayer;
|
||||
declareOptions(window);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name TwitchAdSolutions (video-swap-new)
|
||||
// @namespace https://github.com/pixeltris/TwitchAdSolutions
|
||||
// @version 1.47
|
||||
// @version 1.48
|
||||
// @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)
|
||||
@@ -13,7 +13,7 @@
|
||||
// ==/UserScript==
|
||||
(function() {
|
||||
'use strict';
|
||||
var ourTwitchAdSolutionsVersion = 15;// Used to prevent conflicts with outdated versions of the scripts
|
||||
var ourTwitchAdSolutionsVersion = 16;// Used to prevent conflicts with outdated versions of the scripts
|
||||
if (typeof window.twitchAdSolutionsVersion !== 'undefined' && window.twitchAdSolutionsVersion >= ourTwitchAdSolutionsVersion) {
|
||||
console.log("skipping video-swap-new as there's another script active. ourVersion:" + ourTwitchAdSolutionsVersion + " activeVersion:" + window.twitchAdSolutionsVersion);
|
||||
window.twitchAdSolutionsVersion = ourTwitchAdSolutionsVersion;
|
||||
@@ -25,6 +25,7 @@
|
||||
scope.OPT_BACKUP_PLAYER_TYPES = [ 'autoplay', 'picture-by-picture', 'embed' ];
|
||||
scope.OPT_BACKUP_PLATFORM = 'android';
|
||||
scope.OPT_FORCE_ACCESS_TOKEN_PLAYER_TYPE = 'site';
|
||||
scope.OPT_DISABLE_MATURE_CONTENT_POPUP = false;// If true this avoids having to log in to watch age gated content
|
||||
scope.AD_SIGNIFIER = 'stitched-ad';
|
||||
scope.LIVE_SIGNIFIER = ',live';
|
||||
scope.CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
|
||||
@@ -287,12 +288,12 @@
|
||||
var streamM3u8Response = await realFetch(streamM3u8Url);
|
||||
if (streamM3u8Response.status === 200) {
|
||||
var backTextStr = await streamM3u8Response.text();
|
||||
if ((!backTextStr.includes(AD_SIGNIFIER) && (SimulatedAdsDepth == 0 || i >= SimulatedAdsDepth - 1)) || streamInfo.BackupEncodingsStatus.size >= playerTypes.length - 1) {
|
||||
if ((!backTextStr.includes(AD_SIGNIFIER) && (SimulatedAdsDepth == 0 || i >= SimulatedAdsDepth - 1)) || i >= playerTypes.length - 1) {
|
||||
result = backTextStr;
|
||||
backupPlayerTypeInfo = ' (' + playerType + ')';
|
||||
streamInfo.BackupEncodingsStatus.set(playerType, 1);
|
||||
streamInfo.BackupEncodingsPlayerTypeIndex = i;
|
||||
if (playerType !== 'embed' && streamInfo.Encodings != null) {
|
||||
if (streamInfo.Encodings != null) {
|
||||
// Low resolution streams will reduce the number of resolutions in the UI. To fix this we merge the low res URLs into the main m3u8
|
||||
var normalEncodingsM3u8 = streamInfo.Encodings;
|
||||
var normalLines = normalEncodingsM3u8.replace('\r', '').split('\n');
|
||||
@@ -556,9 +557,9 @@
|
||||
'playerType': playerType
|
||||
}
|
||||
};
|
||||
return gqlRequest(body);
|
||||
return gqlRequest(body, playerType);
|
||||
}
|
||||
function gqlRequest(body) {
|
||||
function gqlRequest(body, playerType) {
|
||||
if (!gql_device_id) {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (let i = 0; i < 32; i += 1) {
|
||||
@@ -572,6 +573,12 @@
|
||||
'Authorization': AuthorizationHeader,
|
||||
...(ClientIntegrityHeader && {'Client-Integrity': ClientIntegrityHeader})
|
||||
};
|
||||
if (playerType != 'site') {
|
||||
headers = {
|
||||
'Client-Id': CLIENT_ID,
|
||||
'X-Device-Id': gql_device_id
|
||||
};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestId = Math.random().toString(36).substring(2, 15);
|
||||
const fetchRequest = {
|
||||
@@ -649,7 +656,7 @@
|
||||
if (typeof init.headers['Authorization'] === 'string' && init.headers['Authorization'] !== AuthorizationHeader) {
|
||||
postTwitchWorkerMessage('UpdateAuthorizationHeader', AuthorizationHeader = init.headers['Authorization']);
|
||||
}
|
||||
if (OPT_FORCE_ACCESS_TOKEN_PLAYER_TYPE && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture')) {
|
||||
if (OPT_FORCE_ACCESS_TOKEN_PLAYER_TYPE && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && !init.body.includes('picture-by-picture') && !init.body.includes('frontpage')) {
|
||||
let replacedPlayerType = '';
|
||||
const newBody = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody)) {
|
||||
@@ -670,6 +677,22 @@
|
||||
init.body = JSON.stringify(newBody);
|
||||
}
|
||||
}
|
||||
if (OPT_DISABLE_MATURE_CONTENT_POPUP) {
|
||||
const newBody2 = JSON.parse(init.body);
|
||||
if (Array.isArray(newBody2)) {
|
||||
var hasRemovedClassification = false;
|
||||
for (let i = 0; i < newBody2.length; i++) {
|
||||
if (newBody2[i]?.operationName == 'ContentClassificationContext') {
|
||||
hasRemovedClassification = true;
|
||||
// Doesn't seem like it if we remove this element from the array so instead we duplicate another entry into this index. TODO: Find out why
|
||||
newBody2[i] = newBody2[i == 0 && newBody2.length > 1 ? 1 : 0];
|
||||
}
|
||||
}
|
||||
if (hasRemovedClassification) {
|
||||
init.body = JSON.stringify(newBody2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return realFetch.apply(this, arguments);
|
||||
@@ -741,9 +764,13 @@
|
||||
const lsKeyQuality = 'video-quality';
|
||||
const lsKeyMuted = 'video-muted';
|
||||
const lsKeyVolume = 'volume';
|
||||
var currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
var currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
var currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
var currentQualityLS = null;
|
||||
var currentMutedLS = null;
|
||||
var currentVolumeLS = null;
|
||||
try {
|
||||
currentQualityLS = localStorage.getItem(lsKeyQuality);
|
||||
currentMutedLS = localStorage.getItem(lsKeyMuted);
|
||||
currentVolumeLS = localStorage.getItem(lsKeyVolume);
|
||||
if (localStorageHookFailed && player?.core?.state) {
|
||||
localStorage.setItem(lsKeyMuted, JSON.stringify({default:player.core.state.muted}));
|
||||
localStorage.setItem(lsKeyVolume, player.core.state.volume);
|
||||
@@ -751,13 +778,22 @@
|
||||
if (localStorageHookFailed && player?.core?.state?.quality?.group) {
|
||||
localStorage.setItem(lsKeyQuality, JSON.stringify({default:player.core.state.quality.group}));
|
||||
}
|
||||
} catch {}
|
||||
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });
|
||||
player.play();
|
||||
if (localStorageHookFailed) {
|
||||
if (localStorageHookFailed && (currentQualityLS || currentMutedLS || currentVolumeLS)) {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
if (currentQualityLS) {
|
||||
localStorage.setItem(lsKeyQuality, currentQualityLS);
|
||||
}
|
||||
if (currentMutedLS) {
|
||||
localStorage.setItem(lsKeyMuted, currentMutedLS);
|
||||
}
|
||||
if (currentVolumeLS) {
|
||||
localStorage.setItem(lsKeyVolume, currentVolumeLS);
|
||||
}
|
||||
} catch {}
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
@@ -819,6 +855,7 @@
|
||||
}
|
||||
}catch{}
|
||||
// Hooks for preserving volume / resolution
|
||||
try {
|
||||
var keysToCache = [
|
||||
'video-quality',
|
||||
'video-muted',
|
||||
@@ -849,6 +886,10 @@
|
||||
// Firefox doesn't allow hooking of localStorage functions but chrome does
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('localStorageHooks failed ' + err)
|
||||
localStorageHookFailed = true;
|
||||
}
|
||||
}
|
||||
window.reloadTwitchPlayer = reloadTwitchPlayer;
|
||||
declareOptions(window);
|
||||
|
||||
Reference in New Issue
Block a user