Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "Excluded Channel" feature #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions chrome/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions chrome/popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -148,6 +173,12 @@
<option>160p</option>
</select>
</p>
<p class="p2" style="padding-bottom: 0px;">
Excluded channels
<p class="p3">Type below the channels you want to support through ads. Use ";" to separate the channels.<br/>
Example: <i>twitchrivals;twitchgaming;twitchpresents</i></p>
<textarea class="text-input-large" type="text" name="excluded_channels"></textarea>
</p>
<p class="p2">Whenever you change a setting, you have to reload the Twitch tab(s).</p>
<p class="p2">Ads blocked for a total of <label id="ad_time">0h</label>.</p>
<p class="p2" style="text-align: center;">
Expand Down
15 changes: 14 additions & 1 deletion chrome/popup/popupjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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() {
Expand All @@ -36,6 +39,7 @@ function restoreOptions() {
restoreDropdown('proxyTTV', proxy);
restoreDropdown('proxyQualityTTV', proxyQuality);
restoreAdtime('adTimeTTV', adTime);
restoreTextArray('excludedChannelsTTV', excludedChannels, ';');
}

function restoreToggle(name, toggle) {
Expand Down Expand Up @@ -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);
16 changes: 11 additions & 5 deletions chrome/remove_video_ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ var TwitchAdblockSettings = {
ForcedQuality: null,
ProxyType: null,
ProxyQuality: null,
AdTime: 0
AdTime: 0,
ExcludedChannels: []
};

var twitchMainWorker = null;
Expand Down Expand Up @@ -313,12 +314,12 @@ function hookWorkerFetch() {
var responseText = await response.text();
var weaverText = null;

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));
Expand Down Expand Up @@ -497,7 +498,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];
Expand All @@ -510,6 +511,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')) {
Expand Down