From 0fc36cfd255659d4e83b6e3b1f20862c57be2363 Mon Sep 17 00:00:00 2001 From: Civati Danilo Date: Sat, 10 Dec 2022 17:33:48 +0100 Subject: [PATCH 1/2] Added "Excluded Channels" settings --- chrome/content.js | 8 ++++++-- chrome/popup/index.html | 31 +++++++++++++++++++++++++++++++ chrome/popup/popupjs.js | 15 ++++++++++++++- chrome/remove_video_ads.js | 17 ++++++++++++----- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/chrome/content.js b/chrome/content.js index f40b0a2..9608ad7 100644 --- a/chrome/content.js +++ b/chrome/content.js @@ -5,13 +5,14 @@ const browser = isFirefox ? window.browser : window.chrome; // Get extension settings function updateSettings() { - browser.storage.local.get(['blockingMessageTTV','forcedQualityTTV','proxyTTV','proxyQualityTTV', 'adTimeTTV']).then(result => { + browser.storage.local.get(['blockingMessageTTV','forcedQualityTTV','proxyTTV','proxyQualityTTV', 'adTimeTTV', 'excludedChannelsTTV']).then(result => { var settings = { BannerVisible: true, ForcedQuality: null, ProxyType: null, ProxyQuality: null, - AdTime: 0 + AdTime: 0, + ExcludedChannels: [] }; if (result.blockingMessageTTV === 'true' || result.blockingMessageTTV === 'false') { settings.BannerVisible = result.blockingMessageTTV === 'true'; @@ -28,6 +29,9 @@ function updateSettings() { if (result.adTimeTTV) { settings.AdTime = result.adTimeTTV; } + if (result.excludedChannelsTTV) { + settings.ExcludedChannels = result.excludedChannelsTTV; + } postMessage({ type: 'SetTwitchAdblockSettings', settings: settings, diff --git a/chrome/popup/index.html b/chrome/popup/index.html index 21980d8..6e21822 100644 --- a/chrome/popup/index.html +++ b/chrome/popup/index.html @@ -31,6 +31,16 @@ padding-bottom: 5px; padding-left: 30px; } + .p3 { + font-family: Arial, sans-serif; + font-size: 12px; + color: rgb(187, 187, 187); + text-align: left; + padding-top: 0px; + padding-right: 30px; + padding-bottom: 2px; + padding-left: 30px; + } .switch { float: right; position: relative; @@ -97,6 +107,21 @@ color: #fff; border: 0px; } + .text-input-large { + position: relative; + display: inline-block; + padding-left: 30px; + width: 300px; + height: 60px; + border-radius: 10px; + background-color: #444; + font-family: Arial, sans-serif; + font-size: 14px; + /*font-weight: bold;*/ + color: #fff; + border: 0px; + resize: none; + } @@ -148,6 +173,12 @@

+

+ Excluded channels +

Type below the channels you want to support through ads. Use ";" to separate the channels.
+ Example: twitchrivals;twitchgaming;twitchpresents

+ +

Whenever you change a setting, you have to reload the Twitch tab(s).

Ads blocked for a total of .

diff --git a/chrome/popup/popupjs.js b/chrome/popup/popupjs.js index e1b247c..400d178 100644 --- a/chrome/popup/popupjs.js +++ b/chrome/popup/popupjs.js @@ -10,8 +10,10 @@ var forcedQuality = document.querySelector('select[name=dropdown_forced_quality] var proxy = document.querySelector('select[name=dropdown_proxy]'); var proxyQuality = document.querySelector('select[name=dropdown_proxy_quality]'); var adTime = document.querySelector('#ad_time'); +var excludedChannels = document.querySelector('textarea[name=excluded_channels]'); -var allSettingsElements = [onOff,blockingMessage,forcedQuality,proxy,proxyQuality]; + +var allSettingsElements = [onOff,blockingMessage,forcedQuality,proxy,proxyQuality,excludedChannels]; for (var i = 0; i < allSettingsElements.length; i++) { if (allSettingsElements[i]) { @@ -27,6 +29,7 @@ function saveOptions() { //chrome.storage.local.set({forcedQualityTTV: forcedQuality.options[forcedQuality.selectedIndex].text}); chrome.storage.local.set({proxyTTV: proxy.options[proxy.selectedIndex].text}); chrome.storage.local.set({proxyQualityTTV: proxyQuality.options[proxyQuality.selectedIndex].text}); + chrome.storage.local.set({excludedChannelsTTV: excludedChannels.value.replace(/\r?\n|\r|\s/g, "").split(";")}); } function restoreOptions() { @@ -36,6 +39,7 @@ function restoreOptions() { restoreDropdown('proxyTTV', proxy); restoreDropdown('proxyQualityTTV', proxyQuality); restoreAdtime('adTimeTTV', adTime); + restoreTextArray('excludedChannelsTTV', excludedChannels, ';'); } function restoreToggle(name, toggle) { @@ -68,4 +72,13 @@ function restoreAdtime(name, container) { }); } +function restoreTextArray(name, textArea, separator) { + chrome.storage.local.get([name], function(result) { + var loadedArray = result[name]; + if (loadedArray.length !== 0) { + textArea.value = loadedArray.join(separator); + } + }); +} + document.addEventListener('DOMContentLoaded', restoreOptions); \ No newline at end of file diff --git a/chrome/remove_video_ads.js b/chrome/remove_video_ads.js index 0309993..b8a8453 100644 --- a/chrome/remove_video_ads.js +++ b/chrome/remove_video_ads.js @@ -81,7 +81,8 @@ var TwitchAdblockSettings = { ForcedQuality: null, ProxyType: null, ProxyQuality: null, - AdTime: 0 + AdTime: 0, + ExcludedChannels: [] }; var twitchMainWorker = null; @@ -312,13 +313,14 @@ function hookWorkerFetch() { var responseText = await response.text(); var weaverText = null; + console.log(TwitchAdblockSettings); - weaverText = await processM3U8(url, responseText, realFetch, PlayerType2); + weaverText = await processM3U8(url, responseText, realFetch, PlayerType2, TwitchAdblockSettings.ExcludedChannels); if (weaverText.includes(AdSignifier)) { - weaverText = await processM3U8(url, responseText, realFetch, PlayerType3); + weaverText = await processM3U8(url, responseText, realFetch, PlayerType3, TwitchAdblockSettings.ExcludedChannels); } if (weaverText.includes(AdSignifier)) { - weaverText = await processM3U8(url, responseText, realFetch, PlayerType4); + weaverText = await processM3U8(url, responseText, realFetch, PlayerType4, TwitchAdblockSettings.ExcludedChannels); } resolve(new Response(weaverText)); @@ -497,7 +499,7 @@ function stripUnusedParams(str, params) { return tempUrl.pathname.substring(1) + tempUrl.search; } -async function processM3U8(url, textStr, realFetch, playerType) { +async function processM3U8(url, textStr, realFetch, playerType, excludedChannels) { //Checks the m3u8 for ads and if it finds one, instead returns an ad-free stream. var streamInfo = StreamInfosByUrl[url]; @@ -510,6 +512,11 @@ async function processM3U8(url, textStr, realFetch, playerType) { if (!textStr) { return textStr; } + + // Channel is excluded by user: ads are visible. + if (excludedChannels.includes(streamInfo.ChannelName)) { + return textStr; + } //Some live streams use mp4. if (!textStr.includes('.ts') && !textStr.includes('.mp4')) { From 5357800593f509d6c4a451a77f2132631b95bfa8 Mon Sep 17 00:00:00 2001 From: Civati Danilo Date: Sat, 10 Dec 2022 17:37:06 +0100 Subject: [PATCH 2/2] Added "Excluded Channels" settings --- chrome/remove_video_ads.js | 1 - 1 file changed, 1 deletion(-) diff --git a/chrome/remove_video_ads.js b/chrome/remove_video_ads.js index b8a8453..15328d3 100644 --- a/chrome/remove_video_ads.js +++ b/chrome/remove_video_ads.js @@ -313,7 +313,6 @@ function hookWorkerFetch() { var responseText = await response.text(); var weaverText = null; - console.log(TwitchAdblockSettings); weaverText = await processM3U8(url, responseText, realFetch, PlayerType2, TwitchAdblockSettings.ExcludedChannels); if (weaverText.includes(AdSignifier)) {