Slightly improve ad detection speed for mute-black / dyn-video-swap

This commit is contained in:
pixeltris 2020-12-22 20:13:01 +00:00
parent f5bbf0b893
commit 26c88c15f5
2 changed files with 104 additions and 90 deletions

View File

@ -2,31 +2,17 @@
twitch-videoad.js application/javascript
(function() {
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
window.addEventListener("DOMContentLoaded", function() {
//current state of if video is disabled
var tempVideo = null;
var disabledVideo = null;
var originalVolume = 0;
//repeatedly check for ad
function checkForAd() {
//check ad by looking for text banner
var adBanner = document.querySelectorAll("span.tw-c-text-overlay");
var foundAd = false;
for (var i = 0; i < adBanner.length; i++) {
if (adBanner[i].attributes["data-test-selector"]) {
foundAd = true;
break;
var originalAppendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function() {
originalAppendChild.apply(this, arguments);
if (arguments[0] && arguments[0].innerHTML && arguments[0].innerHTML.includes('tw-c-text-overlay') && arguments[0].innerHTML.includes('ad-banner')) {
onFoundAd();
}
}
if (tempVideo && disabledVideo && tempVideo.paused != disabledVideo.paused) {
if (disabledVideo.paused) {
tempVideo.pause();
} else {
tempVideo.play();
}
}
if (foundAd && typeof Hls !== 'undefined') {
//if found ad and video is visible, black out video and mute
};
function onFoundAd() {
if (!disabledVideo) {
//get livestream video element
var liveVid = document.getElementsByTagName("video");
@ -89,6 +75,27 @@ twitch-videoad.js application/javascript
createTempStream();
}
}
}
window.addEventListener("DOMContentLoaded", function() {
function checkForAd() {
//check ad by looking for text banner
var adBanner = document.querySelectorAll("span.tw-c-text-overlay");
var foundAd = false;
for (var i = 0; i < adBanner.length; i++) {
if (adBanner[i].attributes["data-test-selector"]) {
foundAd = true;
break;
}
}
if (tempVideo && disabledVideo && tempVideo.paused != disabledVideo.paused) {
if (disabledVideo.paused) {
tempVideo.pause();
} else {
tempVideo.play();
}
}
if (foundAd && typeof Hls !== 'undefined') {
onFoundAd();
} else {
//if no ad and video blacked out, unmute and disable black out
if (disabledVideo) {

View File

@ -2,23 +2,16 @@
twitch-videoad.js application/javascript
(function() {
if ( /(^|\.)twitch\.tv$/.test(document.location.hostname) === false ) { return; }
window.addEventListener("DOMContentLoaded", function() {
//current state of if video is disabled
var disabledVideo = null;
var originalVolume = 0;
//repeatedly check for ad
function checkForAd() {
//check ad by looking for text banner
var adBanner = document.querySelectorAll("span.tw-c-text-overlay");
var foundAd = false;
for (var i = 0; i < adBanner.length; i++) {
if (adBanner[i].attributes["data-test-selector"]) {
foundAd = true;
break;
var originalAppendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function() {
originalAppendChild.apply(this, arguments);
if (arguments[0] && arguments[0].innerHTML && arguments[0].innerHTML.includes('tw-c-text-overlay') && arguments[0].innerHTML.includes('ad-banner')) {
onFoundAd();
}
}
if (foundAd) {
//if found ad and video is visible, black out video and mute
};
function onFoundAd() {
if (!disabledVideo) {
//get livestream video element
var liveVid = document.getElementsByTagName("video");
@ -36,6 +29,20 @@ twitch-videoad.js application/javascript
}
}
}
}
window.addEventListener("DOMContentLoaded", function() {
function checkForAd() {
//check ad by looking for text banner
var adBanner = document.querySelectorAll("span.tw-c-text-overlay");
var foundAd = false;
for (var i = 0; i < adBanner.length; i++) {
if (adBanner[i].attributes["data-test-selector"]) {
foundAd = true;
break;
}
}
if (foundAd) {
onFoundAd();
} else {
//if no ad and video blacked out, unmute and disable black out
if (disabledVideo) {