Possibly fix midroll pause/play issue

This commit is contained in:
pixeltris 2021-06-30 13:01:44 +01:00
parent ac04e98d61
commit e476b5d661
5 changed files with 28 additions and 23 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions // @name TwitchAdSolutions
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.9 // @version 1.10
// @description Multiple solutions for blocking Twitch ads // @description Multiple solutions for blocking Twitch ads
// @author pixeltris // @author pixeltris
// @match *://*.twitch.tv/* // @match *://*.twitch.tv/*
@ -148,7 +148,7 @@
break; break;
} }
} }
streamInfo.HadAds = true; streamInfo.HadAds[url] = true;
streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"'); streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"');
postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll}); postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll});
// Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early. // Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early.
@ -272,9 +272,9 @@
streamInfo.BackupUrl = null; streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds[url]) {
postMessage({key:'UboPauseResumePlayer'}); postMessage({key:'UboPauseResumePlayer'});
streamInfo.HadAds = false; streamInfo.HadAds[url] = false;
} }
postMessage({key:'UboHideAdBanner'}); postMessage({key:'UboHideAdBanner'});
return textStr; return textStr;
@ -340,7 +340,7 @@
streamInfo.BackupRegUrl = null; streamInfo.BackupRegUrl = null;
streamInfo.BackupRegRes = null; streamInfo.BackupRegRes = null;
streamInfo.IsMidroll = false; streamInfo.IsMidroll = false;
streamInfo.HadAds = false; streamInfo.HadAds = [];// xxx.m3u8 -> bool (had ads on prev request)
var lines = encodingsM3u8.replace('\r', '').split('\n'); var lines = encodingsM3u8.replace('\r', '').split('\n');
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) { if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) {
@ -351,6 +351,7 @@
streamInfo.Urls[lines[i]] = res; streamInfo.Urls[lines[i]] = res;
} }
} }
streamInfo.HadAds[lines[i]] = false;
StreamInfosByUrl[lines[i]] = streamInfo; StreamInfosByUrl[lines[i]] = streamInfo;
} }
} }

View File

@ -139,7 +139,7 @@ twitch-videoad.js application/javascript
break; break;
} }
} }
streamInfo.HadAds = true; streamInfo.HadAds[url] = true;
streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"'); streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"');
postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll}); postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll});
// Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early. // Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early.
@ -263,9 +263,9 @@ twitch-videoad.js application/javascript
streamInfo.BackupUrl = null; streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds[url]) {
postMessage({key:'UboPauseResumePlayer'}); postMessage({key:'UboPauseResumePlayer'});
streamInfo.HadAds = false; streamInfo.HadAds[url] = false;
} }
postMessage({key:'UboHideAdBanner'}); postMessage({key:'UboHideAdBanner'});
return textStr; return textStr;
@ -331,7 +331,7 @@ twitch-videoad.js application/javascript
streamInfo.BackupRegUrl = null; streamInfo.BackupRegUrl = null;
streamInfo.BackupRegRes = null; streamInfo.BackupRegRes = null;
streamInfo.IsMidroll = false; streamInfo.IsMidroll = false;
streamInfo.HadAds = false; streamInfo.HadAds = [];// xxx.m3u8 -> bool (had ads on prev request)
var lines = encodingsM3u8.replace('\r', '').split('\n'); var lines = encodingsM3u8.replace('\r', '').split('\n');
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) { if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) {
@ -342,6 +342,7 @@ twitch-videoad.js application/javascript
streamInfo.Urls[lines[i]] = res; streamInfo.Urls[lines[i]] = res;
} }
} }
streamInfo.HadAds[lines[i]] = false;
StreamInfosByUrl[lines[i]] = streamInfo; StreamInfosByUrl[lines[i]] = streamInfo;
} }
} }

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions (notify-reload) // @name TwitchAdSolutions (notify-reload)
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.9 // @version 1.10
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-reload/notify-reload.user.js
// @description Multiple solutions for blocking Twitch ads (notify-reload) // @description Multiple solutions for blocking Twitch ads (notify-reload)
@ -150,7 +150,7 @@
break; break;
} }
} }
streamInfo.HadAds = true; streamInfo.HadAds[url] = true;
streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"'); streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"');
postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll}); postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll});
// Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early. // Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early.
@ -274,9 +274,9 @@
streamInfo.BackupUrl = null; streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds[url]) {
postMessage({key:'UboPauseResumePlayer'}); postMessage({key:'UboPauseResumePlayer'});
streamInfo.HadAds = false; streamInfo.HadAds[url] = false;
} }
postMessage({key:'UboHideAdBanner'}); postMessage({key:'UboHideAdBanner'});
return textStr; return textStr;
@ -342,7 +342,7 @@
streamInfo.BackupRegUrl = null; streamInfo.BackupRegUrl = null;
streamInfo.BackupRegRes = null; streamInfo.BackupRegRes = null;
streamInfo.IsMidroll = false; streamInfo.IsMidroll = false;
streamInfo.HadAds = false; streamInfo.HadAds = [];// xxx.m3u8 -> bool (had ads on prev request)
var lines = encodingsM3u8.replace('\r', '').split('\n'); var lines = encodingsM3u8.replace('\r', '').split('\n');
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) { if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) {
@ -353,6 +353,7 @@
streamInfo.Urls[lines[i]] = res; streamInfo.Urls[lines[i]] = res;
} }
} }
streamInfo.HadAds[lines[i]] = false;
StreamInfosByUrl[lines[i]] = streamInfo; StreamInfosByUrl[lines[i]] = streamInfo;
} }
} }

View File

@ -139,7 +139,7 @@ twitch-videoad.js application/javascript
break; break;
} }
} }
streamInfo.HadAds = true; streamInfo.HadAds[url] = true;
streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"'); streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"');
postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll}); postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll});
// Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early. // Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early.
@ -263,9 +263,9 @@ twitch-videoad.js application/javascript
streamInfo.BackupUrl = null; streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds[url]) {
postMessage({key:'UboPauseResumePlayer'}); postMessage({key:'UboPauseResumePlayer'});
streamInfo.HadAds = false; streamInfo.HadAds[url] = false;
} }
postMessage({key:'UboHideAdBanner'}); postMessage({key:'UboHideAdBanner'});
return textStr; return textStr;
@ -331,7 +331,7 @@ twitch-videoad.js application/javascript
streamInfo.BackupRegUrl = null; streamInfo.BackupRegUrl = null;
streamInfo.BackupRegRes = null; streamInfo.BackupRegRes = null;
streamInfo.IsMidroll = false; streamInfo.IsMidroll = false;
streamInfo.HadAds = false; streamInfo.HadAds = [];// xxx.m3u8 -> bool (had ads on prev request)
var lines = encodingsM3u8.replace('\r', '').split('\n'); var lines = encodingsM3u8.replace('\r', '').split('\n');
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) { if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) {
@ -342,6 +342,7 @@ twitch-videoad.js application/javascript
streamInfo.Urls[lines[i]] = res; streamInfo.Urls[lines[i]] = res;
} }
} }
streamInfo.HadAds[lines[i]] = false;
StreamInfosByUrl[lines[i]] = streamInfo; StreamInfosByUrl[lines[i]] = streamInfo;
} }
} }

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name TwitchAdSolutions (notify-strip) // @name TwitchAdSolutions (notify-strip)
// @namespace https://github.com/pixeltris/TwitchAdSolutions // @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.9 // @version 1.10
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js // @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js // @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js
// @description Multiple solutions for blocking Twitch ads (notify-strip) // @description Multiple solutions for blocking Twitch ads (notify-strip)
@ -150,7 +150,7 @@
break; break;
} }
} }
streamInfo.HadAds = true; streamInfo.HadAds[url] = true;
streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"'); streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"');
postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll}); postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll});
// Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early. // Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early.
@ -274,9 +274,9 @@
streamInfo.BackupUrl = null; streamInfo.BackupUrl = null;
return ''; return '';
} }
if (streamInfo.HadAds) { if (streamInfo.HadAds[url]) {
postMessage({key:'UboPauseResumePlayer'}); postMessage({key:'UboPauseResumePlayer'});
streamInfo.HadAds = false; streamInfo.HadAds[url] = false;
} }
postMessage({key:'UboHideAdBanner'}); postMessage({key:'UboHideAdBanner'});
return textStr; return textStr;
@ -342,7 +342,7 @@
streamInfo.BackupRegUrl = null; streamInfo.BackupRegUrl = null;
streamInfo.BackupRegRes = null; streamInfo.BackupRegRes = null;
streamInfo.IsMidroll = false; streamInfo.IsMidroll = false;
streamInfo.HadAds = false; streamInfo.HadAds = [];// xxx.m3u8 -> bool (had ads on prev request)
var lines = encodingsM3u8.replace('\r', '').split('\n'); var lines = encodingsM3u8.replace('\r', '').split('\n');
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) { if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) {
@ -353,6 +353,7 @@
streamInfo.Urls[lines[i]] = res; streamInfo.Urls[lines[i]] = res;
} }
} }
streamInfo.HadAds[lines[i]] = false;
StreamInfosByUrl[lines[i]] = streamInfo; StreamInfosByUrl[lines[i]] = streamInfo;
} }
} }