1
0
mirror of https://github.com/pixeltris/TwitchAdSolutions.git synced 2024-11-22 10:22:51 +01:00

Fix ad blocking for logged in users (video-swap-new / vaft)

This commit is contained in:
pixeltris 2023-06-01 10:33:30 +01:00
parent b986914732
commit ccfcc71a12
4 changed files with 100 additions and 62 deletions

View File

@ -59,8 +59,8 @@ twitch-videoad.js text/javascript
scope.ClientSession = 'null'; scope.ClientSession = 'null';
//scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself //scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself
scope.PlayerType2 = 'autoplay'; //360p scope.PlayerType2 = 'autoplay'; //360p
scope.PlayerType3 = 'proxy'; //Source scope.PlayerType3 = 'embed'; //Source
scope.PlayerType4 = 'embed'; //Source //scope.PlayerType4 = 'embed'; //Source
scope.CurrentChannelName = null; scope.CurrentChannelName = null;
scope.UsherParams = null; scope.UsherParams = null;
scope.WasShowingAd = false; scope.WasShowingAd = false;
@ -73,7 +73,8 @@ twitch-videoad.js text/javascript
scope.DefaultProxyType = null; scope.DefaultProxyType = null;
scope.DefaultForcedQuality = null; scope.DefaultForcedQuality = null;
scope.DefaultProxyQuality = null; scope.DefaultProxyQuality = null;
scope.ClientIntegrity = null; scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
} }
declareOptions(window); declareOptions(window);
var TwitchAdblockSettings = { var TwitchAdblockSettings = {
@ -123,8 +124,10 @@ twitch-videoad.js text/javascript
ClientID = e.data.value; ClientID = e.data.value;
} else if (e.data.key == 'UpdateDeviceId') { } else if (e.data.key == 'UpdateDeviceId') {
GQLDeviceID = e.data.value; GQLDeviceID = e.data.value;
} else if (e.data.key == 'UpdateClientIntegrity') { } else if (e.data.key == 'UpdateClientIntegrityHeader') {
ClientIntegrity = e.data.value; ClientIntegrityHeader = e.data.value;
} else if (e.data.key == 'UpdateAuthorizationHeader') {
AuthorizationHeader = e.data.value;
} }
}); });
hookWorkerFetch(); hookWorkerFetch();
@ -140,7 +143,7 @@ twitch-videoad.js text/javascript
if (adBlockDiv == null) { if (adBlockDiv == null) {
adBlockDiv = getAdBlockDiv(); adBlockDiv = getAdBlockDiv();
} }
adBlockDiv.P.textContent = 'Blocking ads...'; adBlockDiv.P.textContent = 'Blocking ads';
adBlockDiv.style.display = 'block'; adBlockDiv.style.display = 'block';
} else if (e.data.key == 'HideAdBlockBanner') { } else if (e.data.key == 'HideAdBlockBanner') {
if (adBlockDiv == null) { if (adBlockDiv == null) {
@ -281,9 +284,9 @@ twitch-videoad.js text/javascript
if (weaverText.includes(AdSignifier)) { if (weaverText.includes(AdSignifier)) {
weaverText = await processM3U8(url, responseText, realFetch, PlayerType3); weaverText = await processM3U8(url, responseText, realFetch, PlayerType3);
} }
if (weaverText.includes(AdSignifier)) { //if (weaverText.includes(AdSignifier)) {
weaverText = await processM3U8(url, responseText, realFetch, PlayerType4); // weaverText = await processM3U8(url, responseText, realFetch, PlayerType4);
} //}
resolve(new Response(weaverText)); resolve(new Response(weaverText));
}; };
var send = function() { var send = function() {
@ -659,9 +662,9 @@ twitch-videoad.js text/javascript
return gqlRequest(body, realFetch); return gqlRequest(body, realFetch);
} }
function gqlRequest(body, realFetch) { function gqlRequest(body, realFetch) {
if (ClientIntegrity == null) { if (ClientIntegrityHeader == null) {
console.error('ClientIntegrity is null'); console.error('ClientIntegrityHeader is null');
throw 'ClientIntegrity is null'; throw 'ClientIntegrityHeader is null';
} }
var fetchFunc = realFetch ? realFetch : fetch; var fetchFunc = realFetch ? realFetch : fetch;
if (!GQLDeviceID) { if (!GQLDeviceID) {
@ -676,11 +679,12 @@ twitch-videoad.js text/javascript
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { headers: {
'Client-ID': ClientID, 'Client-ID': ClientID,
'Client-Integrity': ClientIntegrity, 'Client-Integrity': ClientIntegrityHeader,
'Device-ID': GQLDeviceID, 'Device-ID': GQLDeviceID,
'X-Device-Id': GQLDeviceID, 'X-Device-Id': GQLDeviceID,
'Client-Version': ClientVersion, 'Client-Version': ClientVersion,
'Client-Session-Id': ClientSession 'Client-Session-Id': ClientSession,
'Authorization': AuthorizationHeader
} }
}); });
} }
@ -855,14 +859,18 @@ twitch-videoad.js text/javascript
value: ClientID value: ClientID
}); });
} }
} //Client integrity header
//Client integrity ClientIntegrityHeader = init.headers['Client-Integrity'];
if (url.includes('gql') && init && typeof init.headers['Client-Integrity'] === 'string') {
ClientIntegrity = init.headers['Client-Integrity'];
twitchMainWorker.postMessage({ twitchMainWorker.postMessage({
key: 'UpdateClientIntegrity', key: 'UpdateClientIntegrityHeader',
value: init.headers['Client-Integrity'] value: init.headers['Client-Integrity']
}); });
//Authorization header
AuthorizationHeader = init.headers['Authorization'];
twitchMainWorker.postMessage({
key: 'UpdateAuthorizationHeader',
value: init.headers['Authorization']
});
} }
//To prevent pause/resume loop for mid-rolls. //To prevent pause/resume loop for mid-rolls.
if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && init.body.includes('picture-by-picture')) { if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && init.body.includes('picture-by-picture')) {

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions (vaft) // @name TwitchAdSolutions (vaft)
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 5.8.1 // @version 5.8.2
// @description Multiple solutions for blocking Twitch ads (vaft) // @description Multiple solutions for blocking Twitch ads (vaft)
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/vaft/vaft.user.js
@ -70,8 +70,8 @@
scope.ClientSession = 'null'; scope.ClientSession = 'null';
//scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself //scope.PlayerType1 = 'site'; //Source - NOTE: This is unused as it's implicitly used by the website iself
scope.PlayerType2 = 'autoplay'; //360p scope.PlayerType2 = 'autoplay'; //360p
scope.PlayerType3 = 'proxy'; //Source scope.PlayerType3 = 'embed'; //Source
scope.PlayerType4 = 'embed'; //Source //scope.PlayerType4 = 'embed'; //Source
scope.CurrentChannelName = null; scope.CurrentChannelName = null;
scope.UsherParams = null; scope.UsherParams = null;
scope.WasShowingAd = false; scope.WasShowingAd = false;
@ -84,7 +84,8 @@
scope.DefaultProxyType = null; scope.DefaultProxyType = null;
scope.DefaultForcedQuality = null; scope.DefaultForcedQuality = null;
scope.DefaultProxyQuality = null; scope.DefaultProxyQuality = null;
scope.ClientIntegrity = null; scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
} }
declareOptions(window); declareOptions(window);
var TwitchAdblockSettings = { var TwitchAdblockSettings = {
@ -134,8 +135,10 @@
ClientID = e.data.value; ClientID = e.data.value;
} else if (e.data.key == 'UpdateDeviceId') { } else if (e.data.key == 'UpdateDeviceId') {
GQLDeviceID = e.data.value; GQLDeviceID = e.data.value;
} else if (e.data.key == 'UpdateClientIntegrity') { } else if (e.data.key == 'UpdateClientIntegrityHeader') {
ClientIntegrity = e.data.value; ClientIntegrityHeader = e.data.value;
} else if (e.data.key == 'UpdateAuthorizationHeader') {
AuthorizationHeader = e.data.value;
} }
}); });
hookWorkerFetch(); hookWorkerFetch();
@ -151,7 +154,7 @@
if (adBlockDiv == null) { if (adBlockDiv == null) {
adBlockDiv = getAdBlockDiv(); adBlockDiv = getAdBlockDiv();
} }
adBlockDiv.P.textContent = 'Blocking ads...'; adBlockDiv.P.textContent = 'Blocking ads';
adBlockDiv.style.display = 'block'; adBlockDiv.style.display = 'block';
} else if (e.data.key == 'HideAdBlockBanner') { } else if (e.data.key == 'HideAdBlockBanner') {
if (adBlockDiv == null) { if (adBlockDiv == null) {
@ -292,9 +295,9 @@
if (weaverText.includes(AdSignifier)) { if (weaverText.includes(AdSignifier)) {
weaverText = await processM3U8(url, responseText, realFetch, PlayerType3); weaverText = await processM3U8(url, responseText, realFetch, PlayerType3);
} }
if (weaverText.includes(AdSignifier)) { //if (weaverText.includes(AdSignifier)) {
weaverText = await processM3U8(url, responseText, realFetch, PlayerType4); // weaverText = await processM3U8(url, responseText, realFetch, PlayerType4);
} //}
resolve(new Response(weaverText)); resolve(new Response(weaverText));
}; };
var send = function() { var send = function() {
@ -670,9 +673,9 @@
return gqlRequest(body, realFetch); return gqlRequest(body, realFetch);
} }
function gqlRequest(body, realFetch) { function gqlRequest(body, realFetch) {
if (ClientIntegrity == null) { if (ClientIntegrityHeader == null) {
console.error('ClientIntegrity is null'); console.error('ClientIntegrityHeader is null');
throw 'ClientIntegrity is null'; throw 'ClientIntegrityHeader is null';
} }
var fetchFunc = realFetch ? realFetch : fetch; var fetchFunc = realFetch ? realFetch : fetch;
if (!GQLDeviceID) { if (!GQLDeviceID) {
@ -687,11 +690,12 @@
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { headers: {
'Client-ID': ClientID, 'Client-ID': ClientID,
'Client-Integrity': ClientIntegrity, 'Client-Integrity': ClientIntegrityHeader,
'Device-ID': GQLDeviceID, 'Device-ID': GQLDeviceID,
'X-Device-Id': GQLDeviceID, 'X-Device-Id': GQLDeviceID,
'Client-Version': ClientVersion, 'Client-Version': ClientVersion,
'Client-Session-Id': ClientSession 'Client-Session-Id': ClientSession,
'Authorization': AuthorizationHeader
} }
}); });
} }
@ -866,14 +870,18 @@
value: ClientID value: ClientID
}); });
} }
} //Client integrity header
//Client integrity ClientIntegrityHeader = init.headers['Client-Integrity'];
if (url.includes('gql') && init && typeof init.headers['Client-Integrity'] === 'string') {
ClientIntegrity = init.headers['Client-Integrity'];
twitchMainWorker.postMessage({ twitchMainWorker.postMessage({
key: 'UpdateClientIntegrity', key: 'UpdateClientIntegrityHeader',
value: init.headers['Client-Integrity'] value: init.headers['Client-Integrity']
}); });
//Authorization header
AuthorizationHeader = init.headers['Authorization'];
twitchMainWorker.postMessage({
key: 'UpdateAuthorizationHeader',
value: init.headers['Authorization']
});
} }
//To prevent pause/resume loop for mid-rolls. //To prevent pause/resume loop for mid-rolls.
if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && init.body.includes('picture-by-picture')) { if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken') && init.body.includes('picture-by-picture')) {

View File

@ -30,7 +30,8 @@ twitch-videoad.js text/javascript
scope.gql_device_id_rolling += charTable[(bs.charCodeAt(i) ^ di) % charTable.length]; scope.gql_device_id_rolling += charTable[(bs.charCodeAt(i) ^ di) % charTable.length];
} }
scope.gql_device_id_rolling = '1';//temporary scope.gql_device_id_rolling = '1';//temporary
scope.ClientIntegrity = null; scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
} }
declareOptions(window); declareOptions(window);
var twitchMainWorker = null; var twitchMainWorker = null;
@ -60,8 +61,10 @@ twitch-videoad.js text/javascript
self.addEventListener('message', function(e) { self.addEventListener('message', function(e) {
if (e.data.key == 'UboUpdateDeviceId') { if (e.data.key == 'UboUpdateDeviceId') {
gql_device_id = e.data.value; gql_device_id = e.data.value;
} else if (e.data.key == 'UpdateClientIntegrity') { } else if (e.data.key == 'UpdateClientIntegrityHeader') {
ClientIntegrity = e.data.value; ClientIntegrityHeader = e.data.value;
} else if (e.data.key == 'UpdateAuthorizationHeader') {
AuthorizationHeader = e.data.value;
} }
}); });
hookWorkerFetch(); hookWorkerFetch();
@ -74,7 +77,7 @@ twitch-videoad.js text/javascript
if (e.data.key == 'UboShowAdBanner') { if (e.data.key == 'UboShowAdBanner') {
var adDiv = getAdDiv(); var adDiv = getAdDiv();
if (adDiv != null) { if (adDiv != null) {
adDiv.P.textContent = 'Blocking' + (e.data.isMidroll ? ' midroll' : '') + ' ads...'; adDiv.P.textContent = 'Blocking' + (e.data.isMidroll ? ' midroll' : '') + ' ads';
if (OPT_SHOW_AD_BANNER) { if (OPT_SHOW_AD_BANNER) {
adDiv.style.display = 'block'; adDiv.style.display = 'block';
} }
@ -310,9 +313,9 @@ twitch-videoad.js text/javascript
return gqlRequest(body, realFetch); return gqlRequest(body, realFetch);
} }
function gqlRequest(body, realFetch) { function gqlRequest(body, realFetch) {
if (ClientIntegrity == null) { if (ClientIntegrityHeader == null) {
console.error('ClientIntegrity is null'); console.error('ClientIntegrityHeader is null');
throw 'ClientIntegrity is null'; throw 'ClientIntegrityHeader is null';
} }
var fetchFunc = realFetch ? realFetch : fetch; var fetchFunc = realFetch ? realFetch : fetch;
return fetchFunc('https://gql.twitch.tv/gql', { return fetchFunc('https://gql.twitch.tv/gql', {
@ -320,8 +323,9 @@ twitch-videoad.js text/javascript
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { headers: {
'Client-Id': CLIENT_ID, 'Client-Id': CLIENT_ID,
'Client-Integrity': ClientIntegrity, 'Client-Integrity': ClientIntegrityHeader,
'X-Device-Id': OPT_ROLLING_DEVICE_ID ? gql_device_id_rolling : gql_device_id 'X-Device-Id': OPT_ROLLING_DEVICE_ID ? gql_device_id_rolling : gql_device_id,
'Authorization': AuthorizationHeader
} }
}); });
} }
@ -435,12 +439,19 @@ twitch-videoad.js text/javascript
} }
} }
if (typeof init.headers['Client-Integrity'] === 'string') { if (typeof init.headers['Client-Integrity'] === 'string') {
ClientIntegrity = init.headers['Client-Integrity']; ClientIntegrityHeader = init.headers['Client-Integrity'];
twitchMainWorker.postMessage({ twitchMainWorker.postMessage({
key: 'UpdateClientIntegrity', key: 'UpdateClientIntegrityHeader',
value: init.headers['Client-Integrity'] value: init.headers['Client-Integrity']
}); });
} }
if (typeof init.headers['Authorization'] === 'string') {
AuthorizationHeader = init.headers['Authorization'];
twitchMainWorker.postMessage({
key: 'UpdateAuthorizationHeader',
value: init.headers['Authorization']
});
}
} }
} }
} }

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions (video-swap-new) // @name TwitchAdSolutions (video-swap-new)
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.18 // @version 1.19
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/video-swap-new/video-swap-new.user.js // @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 // @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) // @description Multiple solutions for blocking Twitch ads (video-swap-new)
@ -41,7 +41,8 @@
scope.gql_device_id_rolling += charTable[(bs.charCodeAt(i) ^ di) % charTable.length]; scope.gql_device_id_rolling += charTable[(bs.charCodeAt(i) ^ di) % charTable.length];
} }
scope.gql_device_id_rolling = '1';//temporary scope.gql_device_id_rolling = '1';//temporary
scope.ClientIntegrity = null; scope.ClientIntegrityHeader = null;
scope.AuthorizationHeader = null;
} }
declareOptions(window); declareOptions(window);
var twitchMainWorker = null; var twitchMainWorker = null;
@ -71,8 +72,10 @@
self.addEventListener('message', function(e) { self.addEventListener('message', function(e) {
if (e.data.key == 'UboUpdateDeviceId') { if (e.data.key == 'UboUpdateDeviceId') {
gql_device_id = e.data.value; gql_device_id = e.data.value;
} else if (e.data.key == 'UpdateClientIntegrity') { } else if (e.data.key == 'UpdateClientIntegrityHeader') {
ClientIntegrity = e.data.value; ClientIntegrityHeader = e.data.value;
} else if (e.data.key == 'UpdateAuthorizationHeader') {
AuthorizationHeader = e.data.value;
} }
}); });
hookWorkerFetch(); hookWorkerFetch();
@ -85,7 +88,7 @@
if (e.data.key == 'UboShowAdBanner') { if (e.data.key == 'UboShowAdBanner') {
var adDiv = getAdDiv(); var adDiv = getAdDiv();
if (adDiv != null) { if (adDiv != null) {
adDiv.P.textContent = 'Blocking' + (e.data.isMidroll ? ' midroll' : '') + ' ads...'; adDiv.P.textContent = 'Blocking' + (e.data.isMidroll ? ' midroll' : '') + ' ads';
if (OPT_SHOW_AD_BANNER) { if (OPT_SHOW_AD_BANNER) {
adDiv.style.display = 'block'; adDiv.style.display = 'block';
} }
@ -321,9 +324,9 @@
return gqlRequest(body, realFetch); return gqlRequest(body, realFetch);
} }
function gqlRequest(body, realFetch) { function gqlRequest(body, realFetch) {
if (ClientIntegrity == null) { if (ClientIntegrityHeader == null) {
console.error('ClientIntegrity is null'); console.error('ClientIntegrityHeader is null');
throw 'ClientIntegrity is null'; throw 'ClientIntegrityHeader is null';
} }
var fetchFunc = realFetch ? realFetch : fetch; var fetchFunc = realFetch ? realFetch : fetch;
return fetchFunc('https://gql.twitch.tv/gql', { return fetchFunc('https://gql.twitch.tv/gql', {
@ -331,8 +334,9 @@
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { headers: {
'Client-Id': CLIENT_ID, 'Client-Id': CLIENT_ID,
'Client-Integrity': ClientIntegrity, 'Client-Integrity': ClientIntegrityHeader,
'X-Device-Id': OPT_ROLLING_DEVICE_ID ? gql_device_id_rolling : gql_device_id 'X-Device-Id': OPT_ROLLING_DEVICE_ID ? gql_device_id_rolling : gql_device_id,
'Authorization': AuthorizationHeader
} }
}); });
} }
@ -446,12 +450,19 @@
} }
} }
if (typeof init.headers['Client-Integrity'] === 'string') { if (typeof init.headers['Client-Integrity'] === 'string') {
ClientIntegrity = init.headers['Client-Integrity']; ClientIntegrityHeader = init.headers['Client-Integrity'];
twitchMainWorker.postMessage({ twitchMainWorker.postMessage({
key: 'UpdateClientIntegrity', key: 'UpdateClientIntegrityHeader',
value: init.headers['Client-Integrity'] value: init.headers['Client-Integrity']
}); });
} }
if (typeof init.headers['Authorization'] === 'string') {
AuthorizationHeader = init.headers['Authorization'];
twitchMainWorker.postMessage({
key: 'UpdateAuthorizationHeader',
value: init.headers['Authorization']
});
}
} }
} }
} }