id="anonymous-mode-checkbox"
/>
- Browse Twitch as if you were logged out.
+
+ Watch streams as if you were logged out. This option removes
+ authentication headers from requests to Twitch.
+
No proxies have been added to the extension. Add proxies in the
options page.
+
+
You are using a limited proxy!
+ The proxy you are using has a limited number of simultaneous connections.
+ This means that you may experience buffering issues. Consider donating to
+ get access to unlimited proxies.
+
diff --git a/src/popup/popup.ts b/src/popup/popup.ts
index 4930262a..4119324c 100644
--- a/src/popup/popup.ts
+++ b/src/popup/popup.ts
@@ -5,13 +5,21 @@ import {
anonymizeIpAddress,
anonymizeIpAddresses,
} from "../common/ts/anonymizeIpAddress";
+import getProxyInfoFromUrl from "../common/ts/getProxyInfoFromUrl";
import isChromium from "../common/ts/isChromium";
import { twitchChannelNameRegex } from "../common/ts/regexes";
import store from "../store";
import type { StreamStatus } from "../types";
+type WarningBannerType = "noProxies" | "limitedProxy";
+
//#region HTML Elements
-const warningBannerElement = $("#warning-banner") as HTMLDivElement;
+const warningBannerNoProxiesElement = $(
+ "#warning-banner-no-proxies"
+) as HTMLDivElement;
+const warningBannerLimitedProxyElement = $(
+ "#warning-banner-limited-proxy"
+) as HTMLDivElement;
const streamStatusElement = $("#stream-status") as HTMLDivElement;
const proxiedElement = $("#proxied") as HTMLDivElement;
const channelNameElement = $("#channel-name") as HTMLHeadingElement;
@@ -31,20 +39,21 @@ if (store.readyState === "complete") main();
else store.addEventListener("load", main);
async function main() {
- if (isChromium && store.state.normalProxies.length === 0) {
- warningBannerElement.style.display = "block";
- } else if (
- !isChromium &&
- store.state.optimizedProxiesEnabled &&
- store.state.optimizedProxies.length === 0
- ) {
- warningBannerElement.style.display = "block";
- } else if (
- !isChromium &&
- !store.state.optimizedProxiesEnabled &&
- store.state.normalProxies.length === 0
- ) {
- warningBannerElement.style.display = "block";
+ let proxies: string[];
+ if (isChromium) {
+ proxies = store.state.normalProxies;
+ } else {
+ proxies = store.state.optimizedProxiesEnabled
+ ? store.state.optimizedProxies
+ : store.state.normalProxies;
+ }
+ const isLimitedProxy =
+ proxies.length > 0 &&
+ getProxyInfoFromUrl(proxies[0]).host === "chrome.api.cdn-perfprod.com";
+ if (proxies.length === 0) {
+ setWarningBanner("noProxies");
+ } else if (isLimitedProxy) {
+ setWarningBanner("limitedProxy");
}
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
@@ -60,6 +69,16 @@ async function main() {
store.addEventListener("change", () => setStreamStatusElement(channelName));
}
+function setWarningBanner(type: WarningBannerType) {
+ if (type === "noProxies") {
+ warningBannerNoProxiesElement.style.display = "block";
+ warningBannerLimitedProxyElement.style.display = "none";
+ } else if (type === "limitedProxy") {
+ warningBannerNoProxiesElement.style.display = "none";
+ warningBannerLimitedProxyElement.style.display = "block";
+ }
+}
+
function setStreamStatusElement(channelName: string) {
const channelNameLower = channelName.toLowerCase();
const status = store.state.streamStatuses[channelNameLower];
diff --git a/src/popup/style.css b/src/popup/style.css
index a1db56f0..a77e90c4 100644
--- a/src/popup/style.css
+++ b/src/popup/style.css
@@ -48,7 +48,7 @@ main > * {
/* Warning banner */
-#warning-banner {
+.warning-banner {
display: none;
margin: 3px 3px 0 3px;
padding: 15px;
@@ -59,20 +59,20 @@ main > * {
font-size: 9pt;
}
-#warning-banner .warning-banner-title {
+.warning-banner .warning-banner-title {
margin: 0 0 2px 0;
font-weight: bold;
font-size: 11pt;
}
-#warning-banner .warning-banner-link,
-#warning-banner .warning-banner-link:visited {
+.warning-banner .warning-banner-link,
+.warning-banner .warning-banner-link:visited {
color: currentColor;
transition: opacity 100ms ease-in-out;
}
-#warning-banner .warning-banner-link:hover,
-#warning-banner .warning-banner-link:hover:visited {
+.warning-banner .warning-banner-link:hover,
+.warning-banner .warning-banner-link:hover:visited {
color: currentColor;
opacity: 0.8;
}
From b4f65bba5ccbba529b6c00cf748f6b9b6104b011 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Tue, 3 Oct 2023 00:35:21 +0200
Subject: [PATCH 13/42] =?UTF-8?q?=E2=9C=A8=20Add=20#257?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/handlers/onBeforeVideoWeaverRequest.ts | 11 +++++++++--
src/background/handlers/onProxyRequest.ts | 7 ++++++-
src/background/handlers/onResponseStarted.ts | 7 ++++++-
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/background/handlers/onBeforeVideoWeaverRequest.ts b/src/background/handlers/onBeforeVideoWeaverRequest.ts
index 9768f893..6782ecd1 100644
--- a/src/background/handlers/onBeforeVideoWeaverRequest.ts
+++ b/src/background/handlers/onBeforeVideoWeaverRequest.ts
@@ -2,7 +2,10 @@ import { WebRequest } from "webextension-polyfill";
import filterResponseDataWrapper from "../../common/ts/filterResponseDataWrapper";
import findChannelFromVideoWeaverUrl from "../../common/ts/findChannelFromVideoWeaverUrl";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
-import { videoWeaverHostRegex } from "../../common/ts/regexes";
+import {
+ twitchChannelNameRegex,
+ videoWeaverHostRegex,
+} from "../../common/ts/regexes";
import store from "../../store";
import { AdType, ProxyInfo } from "../../types";
@@ -26,7 +29,11 @@ export default function onBeforeVideoWeaverRequest(
if (isAd || isMidroll) {
const adType: AdType = isMidroll ? AdType.MIDROLL : AdType.PREROLL;
- const channel = findChannelFromVideoWeaverUrl(details.url);
+ let channel = findChannelFromVideoWeaverUrl(details.url);
+ if (!channel && details.documentUrl) {
+ const match = twitchChannelNameRegex.exec(details.documentUrl);
+ if (match) channel = match[1];
+ }
const isPurpleScreen = textLower.includes(
"https://help.twitch.tv/s/article/ad-experience-on-twitch"
);
diff --git a/src/background/handlers/onProxyRequest.ts b/src/background/handlers/onProxyRequest.ts
index a73bf9f2..fb6cbbc1 100644
--- a/src/background/handlers/onProxyRequest.ts
+++ b/src/background/handlers/onProxyRequest.ts
@@ -7,6 +7,7 @@ import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isFlaggedRequest from "../../common/ts/isFlaggedRequest";
import {
passportHostRegex,
+ twitchChannelNameRegex,
twitchGqlHostRegex,
twitchTvHostRegex,
usherHostRegex,
@@ -90,7 +91,11 @@ export default async function onProxyRequest(
// Video Weaver requests.
if (videoWeaverHostRegex.test(host) && isFlagged) {
// Don't proxy whitelisted channels.
- const channelName = findChannelFromVideoWeaverUrl(details.url);
+ let channelName = findChannelFromVideoWeaverUrl(details.url);
+ if (!channelName && details.documentUrl) {
+ const match = twitchChannelNameRegex.exec(details.documentUrl);
+ if (match) channelName = match[1];
+ }
if (isChannelWhitelisted(channelName)) {
console.log(`β Channel '${channelName}' is whitelisted.`);
return { type: "direct" };
diff --git a/src/background/handlers/onResponseStarted.ts b/src/background/handlers/onResponseStarted.ts
index df121a76..94fbab4e 100644
--- a/src/background/handlers/onResponseStarted.ts
+++ b/src/background/handlers/onResponseStarted.ts
@@ -5,6 +5,7 @@ import getProxyInfoFromUrl from "../../common/ts/getProxyInfoFromUrl";
import isChromium from "../../common/ts/isChromium";
import {
passportHostRegex,
+ twitchChannelNameRegex,
twitchGqlHostRegex,
twitchTvHostRegex,
usherHostRegex,
@@ -48,7 +49,11 @@ export default function onResponseStarted(
// Video-weaver requests.
if (videoWeaverHostRegex.test(host)) {
- const channelName = findChannelFromVideoWeaverUrl(details.url);
+ let channelName = findChannelFromVideoWeaverUrl(details.url);
+ if (!channelName && details.documentUrl) {
+ const match = twitchChannelNameRegex.exec(details.documentUrl);
+ if (match) channelName = match[1];
+ }
const streamStatus = getStreamStatus(channelName);
const stats = streamStatus?.stats ?? { proxied: 0, notProxied: 0 };
if (!proxy) {
From 2c9ad866f28c66451062e4fcad825395d7548866 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Tue, 3 Oct 2023 00:37:34 +0200
Subject: [PATCH 14/42] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Upgrade=20dependenci?=
=?UTF-8?q?es?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package-lock.json | 156 +++++++++++++++++++++++-----------------------
package.json | 6 +-
2 files changed, 81 insertions(+), 81 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 02dd6f27..82f3d994 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15,12 +15,12 @@
"devDependencies": {
"@parcel/config-webextension": "^2.9.3",
"@types/chrome": "^0.0.246",
- "@types/ip": "^1.1.0",
- "@types/webextension-polyfill": "^0.10.3",
+ "@types/ip": "^1.1.1",
+ "@types/webextension-polyfill": "^0.10.4",
"buffer": "^6.0.3",
"os-browserify": "^0.3.0",
"parcel": "^2.9.3",
- "postcss": "^8.4.30",
+ "postcss": "^8.4.31",
"prettier": "2.8.8",
"prettier-plugin-css-order": "^1.3.1",
"prettier-plugin-organize-imports": "^3.2.3",
@@ -1940,9 +1940,9 @@
}
},
"node_modules/@swc/core": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.88.tgz",
- "integrity": "sha512-kaJ5t6Fg/DmJPNeI+jdtCEt7NVKxhUYToq7PF2fMRPFPLKSJzJCZajcp6/gZNcEUCVWaK6pWi/XL79Tzz1FqzQ==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.91.tgz",
+ "integrity": "sha512-r950d0fdlZ8qbSDyvApn3HyCojiZE8xpgJzQvypeMi32dalYwugdJKWyLB55JIGMRGJ8+lmVvY4MPGkSR3kXgA==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
@@ -1957,16 +1957,16 @@
"url": "https://opencollective.com/swc"
},
"optionalDependencies": {
- "@swc/core-darwin-arm64": "1.3.88",
- "@swc/core-darwin-x64": "1.3.88",
- "@swc/core-linux-arm-gnueabihf": "1.3.88",
- "@swc/core-linux-arm64-gnu": "1.3.88",
- "@swc/core-linux-arm64-musl": "1.3.88",
- "@swc/core-linux-x64-gnu": "1.3.88",
- "@swc/core-linux-x64-musl": "1.3.88",
- "@swc/core-win32-arm64-msvc": "1.3.88",
- "@swc/core-win32-ia32-msvc": "1.3.88",
- "@swc/core-win32-x64-msvc": "1.3.88"
+ "@swc/core-darwin-arm64": "1.3.91",
+ "@swc/core-darwin-x64": "1.3.91",
+ "@swc/core-linux-arm-gnueabihf": "1.3.91",
+ "@swc/core-linux-arm64-gnu": "1.3.91",
+ "@swc/core-linux-arm64-musl": "1.3.91",
+ "@swc/core-linux-x64-gnu": "1.3.91",
+ "@swc/core-linux-x64-musl": "1.3.91",
+ "@swc/core-win32-arm64-msvc": "1.3.91",
+ "@swc/core-win32-ia32-msvc": "1.3.91",
+ "@swc/core-win32-x64-msvc": "1.3.91"
},
"peerDependencies": {
"@swc/helpers": "^0.5.0"
@@ -1978,9 +1978,9 @@
}
},
"node_modules/@swc/core-darwin-arm64": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.88.tgz",
- "integrity": "sha512-Nb7kKydSQK3FE90pw/GPRFmAkquDQcTixLijNcki2xFBXh/DcGdFUPE/GShQjk8gtQelj2vqZrsGs/GZPGA1mA==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.91.tgz",
+ "integrity": "sha512-7kHGiQ1he5khcEeJuHDmLZPM3rRL/ith5OTmV6bOPsoHi46kLeixORW+ts1opC3tC9vu6xbk16xgX0QAJchc1w==",
"cpu": [
"arm64"
],
@@ -1994,9 +1994,9 @@
}
},
"node_modules/@swc/core-darwin-x64": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.88.tgz",
- "integrity": "sha512-RcCrnjkmLXL1izSHPYLaJKVaxwd64LYiYLqjX2jXG4U50D6LOlmuLeqTJ8aAnENZP19gNpsY9ggY9jD5UQqHAw==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.91.tgz",
+ "integrity": "sha512-8SpU18FbFpZDVzsHsAwdI1thF/picQGxq9UFxa8W+T9SDnbsqwFJv/6RqKJeJoDV6qFdl2OLjuO0OL7xrp0qnQ==",
"cpu": [
"x64"
],
@@ -2010,9 +2010,9 @@
}
},
"node_modules/@swc/core-linux-arm-gnueabihf": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.88.tgz",
- "integrity": "sha512-/H7QhpgbWX4xe6jbkgPrhjY543oCCmbPRvBMvZ3iuLb81bEtOFiEp9LYe/95ZW/BTz2z9a6fQtQMqkhAjcrV5w==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.91.tgz",
+ "integrity": "sha512-fOq4Cy8UbwX1yf0WB0d8hWZaIKCnPtPGguRqdXGLfwvhjZ9SIErT6PnmGTGRbQCNCIkOZWHKyTU0r8t2dN3haQ==",
"cpu": [
"arm"
],
@@ -2026,9 +2026,9 @@
}
},
"node_modules/@swc/core-linux-arm64-gnu": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.88.tgz",
- "integrity": "sha512-ar/oQJxisjn/Su9rsg+XcBqA54Ylh1SyrZiLslv37OnGr785Xw+C//rw+JGoFmCZSjhGAU5hriOiHJd2S8mtqA==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.91.tgz",
+ "integrity": "sha512-fki4ioRP/Esy4vdp8T34RCV+V9dqkRmOt763pf74pdiyFV2dPLXa5lnw/XvR1RTfPGknrYgjEQLCfZlReTryRw==",
"cpu": [
"arm64"
],
@@ -2042,9 +2042,9 @@
}
},
"node_modules/@swc/core-linux-arm64-musl": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.88.tgz",
- "integrity": "sha512-ZyUtCk1Y4GpOajbHcnm2JwkFm/m8M/wP3I8iaAm/0yAPIYwQInVdD0Hn++eig2Y+nLJ7gT0QI82fFUDPEIP6Jw==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.91.tgz",
+ "integrity": "sha512-XrG+DUUqNtfVLcJ20imby7fpBwQNG5VsEQBzQndSonPyUOa2YkTbBb60YDondfQGDABopuHH8gHN8o2H2/VCnQ==",
"cpu": [
"arm64"
],
@@ -2058,9 +2058,9 @@
}
},
"node_modules/@swc/core-linux-x64-gnu": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.88.tgz",
- "integrity": "sha512-VrwGCzKLwimL0Js1yWRQNpcJCLGYkETku9mEI9sM4yF6kzT/jwfOe94udBe9O4GGUv24QkzHXRk+EnGR2LFSOQ==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.91.tgz",
+ "integrity": "sha512-d11bYhX+YPBr/Frcjc6eVn3C0LuS/9U1Li9EmQ+6s9EpYtYRl2ygSlC8eueLbaiazBnCVYFnc8bU4o0kc5B9sw==",
"cpu": [
"x64"
],
@@ -2074,9 +2074,9 @@
}
},
"node_modules/@swc/core-linux-x64-musl": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.88.tgz",
- "integrity": "sha512-cur5h0JmNfF4ZHb+FBPLePX86lu3FUjxltObWUhqO4QiXzHxWfde6g+pgdqfUAer0cd9VEEjEKGA5OQncXqyCQ==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.91.tgz",
+ "integrity": "sha512-2SRp5Dke2P4jCQePkDx9trkkTstnRpZJVw5r3jvYdk0zeO6iC4+ZPvvoWXJLigqQv/fZnIiSUfJ6ssOoaEqTzQ==",
"cpu": [
"x64"
],
@@ -2090,9 +2090,9 @@
}
},
"node_modules/@swc/core-win32-arm64-msvc": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.88.tgz",
- "integrity": "sha512-f9OVuWrey7X0gjCZlVD4d5/9/d0yyxu8KFUOEjyjJ2Kd+pvzRys1U3E0FE1PiiDOng3qrfdOt4HQxyAy2jts9Q==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.91.tgz",
+ "integrity": "sha512-l9qKXikOxj42UIjbeZpz9xtBmr736jOMqInNP8mVF2/U+ws5sI8zJjcOFFtfis4ru7vWCXhB1wtltdlJYO2vGA==",
"cpu": [
"arm64"
],
@@ -2106,9 +2106,9 @@
}
},
"node_modules/@swc/core-win32-ia32-msvc": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.88.tgz",
- "integrity": "sha512-7KCeTVe8wWRbuiuAwXoHKBkr9nugCAHQe/JGxoevHXxn2h+WwBuWHog1AbS6PvRWSKK8dVhKAAPDNWwdEltA5A==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.91.tgz",
+ "integrity": "sha512-+s+52O0QVPmzOgjEe/rcb0AK6q/J7EHKwAyJCu/FaYO9df5ovE0HJjSKP6HAF0dGPO5hkENrXuNGujofUH9vtQ==",
"cpu": [
"ia32"
],
@@ -2122,9 +2122,9 @@
}
},
"node_modules/@swc/core-win32-x64-msvc": {
- "version": "1.3.88",
- "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.88.tgz",
- "integrity": "sha512-x0wr9kCS2Hmpx7H6gvJHA17G0DnvwToqWDSO1VmePt5hQZZfLzxiHHDHKFv4YYsVPbAU283q4Wa39QSPZeJbTA==",
+ "version": "1.3.91",
+ "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.91.tgz",
+ "integrity": "sha512-7u9HDQhjUC3Gv43EFW84dZtduWCSa4MgltK+Sp9zEGti6WXqDPu/ESjvDsQEVYTBEMEvZs/xVAXPgLVHorV5nQ==",
"cpu": [
"x64"
],
@@ -2138,9 +2138,9 @@
}
},
"node_modules/@swc/counter": {
- "version": "0.1.1",
- "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.1.tgz",
- "integrity": "sha512-xVRaR4u9hcYjFvcSg71Lz5Bo4//CyjAAfMxa7UsaDSYxAshflUkVJWiyVWrfxC59z2kP1IzI4/1BEpnhI9o3Mw==",
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.2.tgz",
+ "integrity": "sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==",
"dev": true
},
"node_modules/@swc/helpers": {
@@ -2199,24 +2199,24 @@
"dev": true
},
"node_modules/@types/ip": {
- "version": "1.1.0",
- "resolved": "https://registry.npmjs.org/@types/ip/-/ip-1.1.0.tgz",
- "integrity": "sha512-dwNe8gOoF70VdL6WJBwVHtQmAX4RMd62M+mAB9HQFjG1/qiCLM/meRy95Pd14FYBbEDwCq7jgJs89cHpLBu4HQ==",
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@types/ip/-/ip-1.1.1.tgz",
+ "integrity": "sha512-/v+XZuKNBQHJi3dKeFt9LySLzWNkgmaYRtnFfg27Ag0MO9tQLzHUuAA8zOhPtbDvDGkcnZGr4pVZQPGNft/WYA==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/node": {
- "version": "20.6.4",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.4.tgz",
- "integrity": "sha512-nU6d9MPY0NBUMiE/nXd2IIoC4OLvsLpwAjheoAeuzgvDZA1Cb10QYg+91AF6zQiKWRN5i1m07x6sMe0niBznoQ==",
+ "version": "20.8.2",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz",
+ "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==",
"dev": true
},
"node_modules/@types/webextension-polyfill": {
- "version": "0.10.3",
- "resolved": "https://registry.npmjs.org/@types/webextension-polyfill/-/webextension-polyfill-0.10.3.tgz",
- "integrity": "sha512-7RqGPhr+Ib7IKrOIeXRTB2TVojq/bMRieoYVfgHoicQ+VvI6OOzBNF0fZXA+5JVJIEtfE/o426S+bMgg/XhvXg==",
+ "version": "0.10.4",
+ "resolved": "https://registry.npmjs.org/@types/webextension-polyfill/-/webextension-polyfill-0.10.4.tgz",
+ "integrity": "sha512-pvEIqAZEbJRzaqTaWq3xlUoMWa3+euZHHz+VZHCzHWW+jOf8qLOq9wXy38U+WiPG3108SJC/wNc1X6vPC5TcjQ==",
"dev": true
},
"node_modules/abortcontroller-polyfill": {
@@ -2315,9 +2315,9 @@
}
},
"node_modules/browserslist": {
- "version": "4.21.11",
- "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.11.tgz",
- "integrity": "sha512-xn1UXOKUz7DjdGlg9RrUr0GGiWzI97UQJnugHtH0OLDfJB7jMgoIkYvRIEO1l9EeEERVqeqLYOcFBW9ldjypbQ==",
+ "version": "4.22.1",
+ "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.1.tgz",
+ "integrity": "sha512-FEVc202+2iuClEhZhrWy6ZiAcRLvNMyYcxZ8raemul1DYVOVdFsbqckWLdsixQZCpJlwe77Z3UTalE7jsjnKfQ==",
"dev": true,
"funding": [
{
@@ -2334,8 +2334,8 @@
}
],
"dependencies": {
- "caniuse-lite": "^1.0.30001538",
- "electron-to-chromium": "^1.4.526",
+ "caniuse-lite": "^1.0.30001541",
+ "electron-to-chromium": "^1.4.535",
"node-releases": "^2.0.13",
"update-browserslist-db": "^1.0.13"
},
@@ -2380,9 +2380,9 @@
}
},
"node_modules/caniuse-lite": {
- "version": "1.0.30001538",
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001538.tgz",
- "integrity": "sha512-HWJnhnID+0YMtGlzcp3T9drmBJUVDchPJ08tpUGFLs9CYlwWPH2uLgpHn8fND5pCgXVtnGS3H4QR9XLMHVNkHw==",
+ "version": "1.0.30001542",
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001542.tgz",
+ "integrity": "sha512-UrtAXVcj1mvPBFQ4sKd38daP8dEcXXr5sQe6QNNinaPd0iA/cxg9/l3VrSdL73jgw5sKyuQ6jNgiKO12W3SsVA==",
"dev": true,
"funding": [
{
@@ -2502,9 +2502,9 @@
}
},
"node_modules/css-declaration-sorter": {
- "version": "7.1.0",
- "resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-7.1.0.tgz",
- "integrity": "sha512-suZ/qn6r4iXWLGOlD34EfYCCZxq18KXC/OYIyPHUnV3MHl3JO9LmcaVFHpgbHwfg+SayGOpXURJIs3aJpxcjyA==",
+ "version": "7.1.1",
+ "resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-7.1.1.tgz",
+ "integrity": "sha512-dZ3bVTEEc1vxr3Bek9vGwfB5Z6ESPULhcRvO472mfjVnj8jRcTnKO8/JTczlvxM10Myb+wBM++1MtdO76eWcaQ==",
"dev": true,
"engines": {
"node": "^14 || ^16 || >=18"
@@ -2752,9 +2752,9 @@
"dev": true
},
"node_modules/electron-to-chromium": {
- "version": "1.4.528",
- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.528.tgz",
- "integrity": "sha512-UdREXMXzLkREF4jA8t89FQjA8WHI6ssP38PMY4/4KhXFQbtImnghh4GkCgrtiZwLKUKVD2iTVXvDVQjfomEQuA==",
+ "version": "1.4.539",
+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.539.tgz",
+ "integrity": "sha512-wRmWJ8F7rgmINuI32S6r2SLrw/h/bJQsDSvBiq9GBfvc2Lh73qTOwn73r3Cf67mjVgFGJYcYtmERzySa5jIWlg==",
"dev": true
},
"node_modules/entities": {
@@ -3642,9 +3642,9 @@
}
},
"node_modules/postcss": {
- "version": "8.4.30",
- "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.30.tgz",
- "integrity": "sha512-7ZEao1g4kd68l97aWG/etQKPKq07us0ieSZ2TnFDk11i0ZfDW2AwKHYU8qv4MZKqN2fdBfg+7q0ES06UA73C1g==",
+ "version": "8.4.31",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
+ "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==",
"dev": true,
"funding": [
{
@@ -3682,9 +3682,9 @@
}
},
"node_modules/postcss-scss": {
- "version": "4.0.8",
- "resolved": "https://registry.npmjs.org/postcss-scss/-/postcss-scss-4.0.8.tgz",
- "integrity": "sha512-Cr0X8Eu7xMhE96PJck6ses/uVVXDtE5ghUTKNUYgm8ozgP2TkgV3LWs3WgLV1xaSSLq8ZFiXaUrj0LVgG1fGEA==",
+ "version": "4.0.9",
+ "resolved": "https://registry.npmjs.org/postcss-scss/-/postcss-scss-4.0.9.tgz",
+ "integrity": "sha512-AjKOeiwAitL/MXxQW2DliT28EKukvvbEWx3LBmJIRN8KfBGZbRTxNYW0kSqi1COiTZ57nZ9NW06S6ux//N1c9A==",
"dev": true,
"funding": [
{
diff --git a/package.json b/package.json
index 2d64a8f8..db0806bb 100644
--- a/package.json
+++ b/package.json
@@ -48,12 +48,12 @@
"devDependencies": {
"@parcel/config-webextension": "^2.9.3",
"@types/chrome": "^0.0.246",
- "@types/ip": "^1.1.0",
- "@types/webextension-polyfill": "^0.10.3",
+ "@types/ip": "^1.1.1",
+ "@types/webextension-polyfill": "^0.10.4",
"buffer": "^6.0.3",
"os-browserify": "^0.3.0",
"parcel": "^2.9.3",
- "postcss": "^8.4.30",
+ "postcss": "^8.4.31",
"prettier": "2.8.8",
"prettier-plugin-css-order": "^1.3.1",
"prettier-plugin-organize-imports": "^3.2.3",
From 08148c99052ec574bfe06af0b5333b6bbb35f421 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Tue, 3 Oct 2023 17:25:15 +0200
Subject: [PATCH 15/42] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../handlers/onBeforeVideoWeaverRequest.ts | 14 +++++---------
src/background/handlers/onProxyRequest.ts | 19 +++++++++++++------
src/background/handlers/onResponseStarted.ts | 10 ++++------
src/common/ts/findChannelFromTwitchTvUrl.ts | 17 +++++++++++++++++
src/content/content.ts | 12 +++++-------
src/popup/popup.ts | 6 ++----
6 files changed, 46 insertions(+), 32 deletions(-)
create mode 100644 src/common/ts/findChannelFromTwitchTvUrl.ts
diff --git a/src/background/handlers/onBeforeVideoWeaverRequest.ts b/src/background/handlers/onBeforeVideoWeaverRequest.ts
index 6782ecd1..122bf3b5 100644
--- a/src/background/handlers/onBeforeVideoWeaverRequest.ts
+++ b/src/background/handlers/onBeforeVideoWeaverRequest.ts
@@ -1,11 +1,9 @@
import { WebRequest } from "webextension-polyfill";
import filterResponseDataWrapper from "../../common/ts/filterResponseDataWrapper";
+import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
import findChannelFromVideoWeaverUrl from "../../common/ts/findChannelFromVideoWeaverUrl";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
-import {
- twitchChannelNameRegex,
- videoWeaverHostRegex,
-} from "../../common/ts/regexes";
+import { videoWeaverHostRegex } from "../../common/ts/regexes";
import store from "../../store";
import { AdType, ProxyInfo } from "../../types";
@@ -29,11 +27,9 @@ export default function onBeforeVideoWeaverRequest(
if (isAd || isMidroll) {
const adType: AdType = isMidroll ? AdType.MIDROLL : AdType.PREROLL;
- let channel = findChannelFromVideoWeaverUrl(details.url);
- if (!channel && details.documentUrl) {
- const match = twitchChannelNameRegex.exec(details.documentUrl);
- if (match) channel = match[1];
- }
+ const channel =
+ findChannelFromVideoWeaverUrl(details.url) ??
+ findChannelFromTwitchTvUrl(details.documentUrl);
const isPurpleScreen = textLower.includes(
"https://help.twitch.tv/s/article/ad-experience-on-twitch"
);
diff --git a/src/background/handlers/onProxyRequest.ts b/src/background/handlers/onProxyRequest.ts
index fb6cbbc1..dd51ac32 100644
--- a/src/background/handlers/onProxyRequest.ts
+++ b/src/background/handlers/onProxyRequest.ts
@@ -1,4 +1,5 @@
import { Proxy } from "webextension-polyfill";
+import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
import findChannelFromUsherUrl from "../../common/ts/findChannelFromUsherUrl";
import findChannelFromVideoWeaverUrl from "../../common/ts/findChannelFromVideoWeaverUrl";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
@@ -7,7 +8,6 @@ import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isFlaggedRequest from "../../common/ts/isFlaggedRequest";
import {
passportHostRegex,
- twitchChannelNameRegex,
twitchGqlHostRegex,
twitchTvHostRegex,
usherHostRegex,
@@ -72,6 +72,15 @@ export default async function onProxyRequest(
return proxyInfoArray;
}
+ const documentHost = details.documentUrl
+ ? getHostFromUrl(details.documentUrl)
+ : null;
+ if (documentHost && !twitchTvHostRegex.test(documentHost)) {
+ // Don't proxy Usher and Video Weaver requests from non-supported websites.
+ console.log(`β '${documentHost}' is not supported.`);
+ return { type: "direct" };
+ }
+
// Usher requests.
if (store.state.proxyUsherRequests && usherHostRegex.test(host)) {
// Don't proxy whitelisted channels.
@@ -91,11 +100,9 @@ export default async function onProxyRequest(
// Video Weaver requests.
if (videoWeaverHostRegex.test(host) && isFlagged) {
// Don't proxy whitelisted channels.
- let channelName = findChannelFromVideoWeaverUrl(details.url);
- if (!channelName && details.documentUrl) {
- const match = twitchChannelNameRegex.exec(details.documentUrl);
- if (match) channelName = match[1];
- }
+ const channelName =
+ findChannelFromVideoWeaverUrl(details.url) ??
+ findChannelFromTwitchTvUrl(details.documentUrl);
if (isChannelWhitelisted(channelName)) {
console.log(`β Channel '${channelName}' is whitelisted.`);
return { type: "direct" };
diff --git a/src/background/handlers/onResponseStarted.ts b/src/background/handlers/onResponseStarted.ts
index 94fbab4e..f70a2c51 100644
--- a/src/background/handlers/onResponseStarted.ts
+++ b/src/background/handlers/onResponseStarted.ts
@@ -1,11 +1,11 @@
import { WebRequest } from "webextension-polyfill";
+import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
import findChannelFromVideoWeaverUrl from "../../common/ts/findChannelFromVideoWeaverUrl";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
import getProxyInfoFromUrl from "../../common/ts/getProxyInfoFromUrl";
import isChromium from "../../common/ts/isChromium";
import {
passportHostRegex,
- twitchChannelNameRegex,
twitchGqlHostRegex,
twitchTvHostRegex,
usherHostRegex,
@@ -49,11 +49,9 @@ export default function onResponseStarted(
// Video-weaver requests.
if (videoWeaverHostRegex.test(host)) {
- let channelName = findChannelFromVideoWeaverUrl(details.url);
- if (!channelName && details.documentUrl) {
- const match = twitchChannelNameRegex.exec(details.documentUrl);
- if (match) channelName = match[1];
- }
+ const channelName =
+ findChannelFromVideoWeaverUrl(details.url) ??
+ findChannelFromTwitchTvUrl(details.documentUrl);
const streamStatus = getStreamStatus(channelName);
const stats = streamStatus?.stats ?? { proxied: 0, notProxied: 0 };
if (!proxy) {
diff --git a/src/common/ts/findChannelFromTwitchTvUrl.ts b/src/common/ts/findChannelFromTwitchTvUrl.ts
new file mode 100644
index 00000000..dba40715
--- /dev/null
+++ b/src/common/ts/findChannelFromTwitchTvUrl.ts
@@ -0,0 +1,17 @@
+import { twitchChannelNameRegex } from "./regexes";
+
+/**
+ * Returns the channel name from a Twitch.tv URL.
+ * Returns `null` if the URL is not a valid Twitch.tv URL.
+ * @param twitchTvUrl
+ * @returns
+ */
+export default function findChannelFromTwitchTvUrl(
+ twitchTvUrl: string | undefined
+): string | null {
+ if (!twitchTvUrl) return null;
+ const match = twitchChannelNameRegex.exec(twitchTvUrl);
+ if (!match) return null;
+ const [, channelName] = match;
+ return channelName;
+}
diff --git a/src/content/content.ts b/src/content/content.ts
index cf88d258..d19bb7e7 100644
--- a/src/content/content.ts
+++ b/src/content/content.ts
@@ -1,7 +1,7 @@
import pageScriptURL from "url:../page/page.ts";
import workerScriptURL from "url:../page/worker.ts";
+import findChannelFromTwitchTvUrl from "../common/ts/findChannelFromTwitchTvUrl";
import isChromium from "../common/ts/isChromium";
-import { twitchChannelNameRegex } from "../common/ts/regexes";
import { getStreamStatus, setStreamStatus } from "../common/ts/streamStatus";
import store from "../store";
@@ -52,13 +52,11 @@ function onStoreReady() {
*/
function clearStats() {
// TODO: Clear stats on navigation.
- const match = twitchChannelNameRegex.exec(location.href);
- if (!match) return;
- const [, streamId] = match;
- if (!streamId) return;
+ const channelName = findChannelFromTwitchTvUrl(location.href);
+ if (!channelName) return;
- if (store.state.streamStatuses.hasOwnProperty(streamId)) {
- store.state.streamStatuses[streamId].stats = {
+ if (store.state.streamStatuses.hasOwnProperty(channelName)) {
+ store.state.streamStatuses[channelName].stats = {
proxied: 0,
notProxied: 0,
};
diff --git a/src/popup/popup.ts b/src/popup/popup.ts
index 4119324c..bcb531d8 100644
--- a/src/popup/popup.ts
+++ b/src/popup/popup.ts
@@ -5,9 +5,9 @@ import {
anonymizeIpAddress,
anonymizeIpAddresses,
} from "../common/ts/anonymizeIpAddress";
+import findChannelFromTwitchTvUrl from "../common/ts/findChannelFromTwitchTvUrl";
import getProxyInfoFromUrl from "../common/ts/getProxyInfoFromUrl";
import isChromium from "../common/ts/isChromium";
-import { twitchChannelNameRegex } from "../common/ts/regexes";
import store from "../store";
import type { StreamStatus } from "../types";
@@ -60,9 +60,7 @@ async function main() {
const activeTab = tabs[0];
if (!activeTab || !activeTab.url) return;
- const match = twitchChannelNameRegex.exec(activeTab.url);
- if (!match) return;
- const [, channelName] = match;
+ const channelName = findChannelFromTwitchTvUrl(activeTab.url);
if (!channelName) return;
setStreamStatusElement(channelName);
From 14a09ed75d4114417de8f3fd3ab10c63c218b7fa Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Tue, 3 Oct 2023 17:38:12 +0200
Subject: [PATCH 16/42] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/handlers/onProxyRequest.ts | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/background/handlers/onProxyRequest.ts b/src/background/handlers/onProxyRequest.ts
index dd51ac32..0279d814 100644
--- a/src/background/handlers/onProxyRequest.ts
+++ b/src/background/handlers/onProxyRequest.ts
@@ -75,14 +75,17 @@ export default async function onProxyRequest(
const documentHost = details.documentUrl
? getHostFromUrl(details.documentUrl)
: null;
- if (documentHost && !twitchTvHostRegex.test(documentHost)) {
- // Don't proxy Usher and Video Weaver requests from non-supported websites.
- console.log(`β '${documentHost}' is not supported.`);
- return { type: "direct" };
- }
+ const isTwitchTvHost = documentHost && twitchTvHostRegex.test(documentHost);
// Usher requests.
if (store.state.proxyUsherRequests && usherHostRegex.test(host)) {
+ // Don't proxy Usher requests from non-supported hosts.
+ if (!isTwitchTvHost) {
+ console.log(
+ `β '${details.url}' from host '${documentHost}' is not supported.`
+ );
+ return { type: "direct" };
+ }
// Don't proxy whitelisted channels.
const channelName = findChannelFromUsherUrl(details.url);
if (isChannelWhitelisted(channelName)) {
@@ -99,6 +102,13 @@ export default async function onProxyRequest(
// Video Weaver requests.
if (videoWeaverHostRegex.test(host) && isFlagged) {
+ // Don't proxy Video Weaver requests from non-supported hosts.
+ if (!isTwitchTvHost) {
+ console.log(
+ `β '${details.url}' from host '${documentHost}' is not supported.`
+ );
+ return { type: "direct" };
+ }
// Don't proxy whitelisted channels.
const channelName =
findChannelFromVideoWeaverUrl(details.url) ??
From 5a01157f5b089be5825706ea72283979ed0df07a Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Tue, 3 Oct 2023 17:48:47 +0200
Subject: [PATCH 17/42] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/handlers/onProxyRequest.ts | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/background/handlers/onProxyRequest.ts b/src/background/handlers/onProxyRequest.ts
index 0279d814..670713ac 100644
--- a/src/background/handlers/onProxyRequest.ts
+++ b/src/background/handlers/onProxyRequest.ts
@@ -75,12 +75,13 @@ export default async function onProxyRequest(
const documentHost = details.documentUrl
? getHostFromUrl(details.documentUrl)
: null;
- const isTwitchTvHost = documentHost && twitchTvHostRegex.test(documentHost);
+ const isFromTwitchTvHost =
+ documentHost && twitchTvHostRegex.test(documentHost);
// Usher requests.
if (store.state.proxyUsherRequests && usherHostRegex.test(host)) {
// Don't proxy Usher requests from non-supported hosts.
- if (!isTwitchTvHost) {
+ if (!isFromTwitchTvHost) {
console.log(
`β '${details.url}' from host '${documentHost}' is not supported.`
);
@@ -103,7 +104,7 @@ export default async function onProxyRequest(
// Video Weaver requests.
if (videoWeaverHostRegex.test(host) && isFlagged) {
// Don't proxy Video Weaver requests from non-supported hosts.
- if (!isTwitchTvHost) {
+ if (!isFromTwitchTvHost) {
console.log(
`β '${details.url}' from host '${documentHost}' is not supported.`
);
From f372764c92c08479103552c8a78c9549e6e4745c Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Wed, 4 Oct 2023 14:45:44 +0200
Subject: [PATCH 18/42] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20nitpicks?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/background.ts | 6 ++---
.../handlers/onProxySettingsChanged.ts | 5 +++--
.../handlers/onStartupStoreCleanup.ts | 2 +-
src/background/handlers/onTabCreated.ts | 8 +++----
src/background/handlers/onTabRemoved.ts | 6 ++---
src/background/handlers/onTabUpdated.ts | 22 +++++++++----------
6 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/src/background/background.ts b/src/background/background.ts
index 55397d63..8db61947 100644
--- a/src/background/background.ts
+++ b/src/background/background.ts
@@ -30,6 +30,9 @@ browser.webRequest.onResponseStarted.addListener(onResponseStarted, {
});
if (isChromium) {
+ // Listen to whether proxy is set or not.
+ browser.proxy.settings.onChange.addListener(onProxySettingsChange);
+
// Check if there are any opened Twitch tabs on startup.
checkForOpenedTwitchTabs();
@@ -37,9 +40,6 @@ if (isChromium) {
browser.tabs.onCreated.addListener(onTabCreated);
browser.tabs.onUpdated.addListener(onTabUpdated);
browser.tabs.onRemoved.addListener(onTabRemoved);
-
- // Listen to whether proxy is set or not
- chrome.proxy.settings.onChange.addListener(onProxySettingsChange);
} else {
// Block tracking pixels.
browser.webRequest.onBeforeRequest.addListener(
diff --git a/src/background/handlers/onProxySettingsChanged.ts b/src/background/handlers/onProxySettingsChanged.ts
index 56820405..49735710 100644
--- a/src/background/handlers/onProxySettingsChanged.ts
+++ b/src/background/handlers/onProxySettingsChanged.ts
@@ -1,9 +1,10 @@
+import { Types } from "webextension-polyfill";
import store from "../../store";
export default function onProxySettingsChange(
- details: chrome.types.ChromeSettingGetResultDetails
+ details: Types.SettingOnChangeDetailsType
) {
- console.log("PROXY SETTINGS CHANGE: " + details.levelOfControl);
+ console.log(`βοΈ Proxy settings changed: ${details.levelOfControl}`);
store.state.chromiumProxyActive =
details.levelOfControl == "controlled_by_this_extension";
}
diff --git a/src/background/handlers/onStartupStoreCleanup.ts b/src/background/handlers/onStartupStoreCleanup.ts
index 3e92d4c7..af1d2c2b 100644
--- a/src/background/handlers/onStartupStoreCleanup.ts
+++ b/src/background/handlers/onStartupStoreCleanup.ts
@@ -12,9 +12,9 @@ export default function onStartupStoreCleanup(): void {
if (store.readyState !== "complete")
return store.addEventListener("load", onStartupStoreCleanup);
+ store.state.chromiumProxyActive = false;
store.state.dnsResponses = [];
store.state.openedTwitchTabs = [];
store.state.streamStatuses = {};
store.state.videoWeaverUrlsByChannel = {};
- store.state.chromiumProxyActive = false;
}
diff --git a/src/background/handlers/onTabCreated.ts b/src/background/handlers/onTabCreated.ts
index 71be2b8c..231a6790 100644
--- a/src/background/handlers/onTabCreated.ts
+++ b/src/background/handlers/onTabCreated.ts
@@ -12,11 +12,11 @@ export default function onTabCreated(tab: Tabs.Tab): void {
if (host != null && twitchTvHostRegex.test(host)) {
console.log(`β Opened Twitch tab: ${tab.id}`);
if (isChromium) {
- var isNonWhitelistedChannel = true;
- const url = new URL(tab.url);
- if (url.pathname && url.pathname.length > 0) {
+ let isNonWhitelistedChannel = true;
+ const Url = new URL(tab.url);
+ if (Url.pathname && Url.pathname.length > 0) {
isNonWhitelistedChannel = !isChannelWhitelisted(
- url.pathname.substring(1)
+ Url.pathname.substring(1)
);
}
if (isNonWhitelistedChannel && !store.state.chromiumProxyActive)
diff --git a/src/background/handlers/onTabRemoved.ts b/src/background/handlers/onTabRemoved.ts
index 1a36c954..4da91531 100644
--- a/src/background/handlers/onTabRemoved.ts
+++ b/src/background/handlers/onTabRemoved.ts
@@ -21,9 +21,9 @@ export default function onTabRemoved(tabId: number): void {
.get(tabId)
.then(tab => {
if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == "/") return false;
- return isChannelWhitelisted(url.pathname.substring(1));
+ const Url = new URL(tab.url);
+ if (!Url.pathname || Url.pathname == "/") return false;
+ return isChannelWhitelisted(Url.pathname.substring(1));
})
.catch(() => false);
})
diff --git a/src/background/handlers/onTabUpdated.ts b/src/background/handlers/onTabUpdated.ts
index ee151061..99b3fc50 100644
--- a/src/background/handlers/onTabUpdated.ts
+++ b/src/background/handlers/onTabUpdated.ts
@@ -27,12 +27,10 @@ export default function onTabUpdated(
if (isTwitchTab && !wasTwitchTab) {
console.log(`β Opened Twitch tab: ${tabId}`);
if (isChromium) {
- var isNonWhitelistedPage = true;
- const urlObj = new URL(url);
- if (urlObj.pathname && urlObj.pathname.length > 0) {
- isNonWhitelistedPage = !isChannelWhitelisted(
- urlObj.pathname.substring(1)
- );
+ let isNonWhitelistedPage = true;
+ const Url = new URL(url);
+ if (Url.pathname && Url.pathname.length > 0) {
+ isNonWhitelistedPage = !isChannelWhitelisted(Url.pathname.substring(1));
}
if (isNonWhitelistedPage) updateProxySettings();
}
@@ -55,9 +53,9 @@ export default function onTabUpdated(
.get(tabId)
.then(tab => {
if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == "/") return false;
- return isChannelWhitelisted(url.pathname.substring(1));
+ const Url = new URL(tab.url);
+ if (!Url.pathname || Url.pathname == "/") return false;
+ return isChannelWhitelisted(Url.pathname.substring(1));
})
.catch(() => false);
})
@@ -78,9 +76,9 @@ export default function onTabUpdated(
.get(tabId)
.then(tab => {
if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == "/") return false;
- return isChannelWhitelisted(url.pathname.substring(1));
+ const Url = new URL(tab.url);
+ if (!Url.pathname || Url.pathname == "/") return false;
+ return isChannelWhitelisted(Url.pathname.substring(1));
})
.catch(() => false);
})
From 01bd1259e09b08dd75e8f937e9120027284bfe5a Mon Sep 17 00:00:00 2001
From: Luke Fanning
Date: Sun, 24 Sep 2023 12:34:31 +0100
Subject: [PATCH 19/42] Whitelisting via tab analysis for chromium
---
src/background/background.ts | 4 ++
.../handlers/onProxySettingsChanged.ts | 6 +++
.../handlers/onStartupStoreCleanup.ts | 1 +
src/background/handlers/onTabCreated.ts | 10 +++-
src/background/handlers/onTabRemoved.ts | 22 +++++++-
src/background/handlers/onTabUpdated.ts | 50 +++++++++++++++++--
src/options/options.ts | 4 --
src/popup/popup.ts | 3 --
src/store/types.ts | 1 +
9 files changed, 86 insertions(+), 15 deletions(-)
create mode 100644 src/background/handlers/onProxySettingsChanged.ts
diff --git a/src/background/background.ts b/src/background/background.ts
index abcde524..30ac6ffd 100644
--- a/src/background/background.ts
+++ b/src/background/background.ts
@@ -10,6 +10,7 @@ import onStartupStoreCleanup from "./handlers/onStartupStoreCleanup";
import onTabCreated from "./handlers/onTabCreated";
import onTabRemoved from "./handlers/onTabRemoved";
import onTabUpdated from "./handlers/onTabUpdated";
+import onProxySettingsChange from "./handlers/onProxySettingsChanged";
console.info("π Background script loaded.");
@@ -36,6 +37,9 @@ if (isChromium) {
browser.tabs.onCreated.addListener(onTabCreated);
browser.tabs.onUpdated.addListener(onTabUpdated);
browser.tabs.onRemoved.addListener(onTabRemoved);
+
+ // Listen to whether proxy is set or not
+ chrome.proxy.settings.onChange.addListener(onProxySettingsChange);
} else {
// Block tracking pixels.
browser.webRequest.onBeforeRequest.addListener(
diff --git a/src/background/handlers/onProxySettingsChanged.ts b/src/background/handlers/onProxySettingsChanged.ts
new file mode 100644
index 00000000..0dfe524d
--- /dev/null
+++ b/src/background/handlers/onProxySettingsChanged.ts
@@ -0,0 +1,6 @@
+import store from "../../store";
+
+export default function onProxySettingsChange(details: chrome.types.ChromeSettingGetResultDetails) {
+ console.log("PROXY SETTINGS CHANGE: " + details.levelOfControl);
+ store.state.chromiumProxyActive = details.levelOfControl == "controlled_by_this_extension";
+}
\ No newline at end of file
diff --git a/src/background/handlers/onStartupStoreCleanup.ts b/src/background/handlers/onStartupStoreCleanup.ts
index 15c88c1e..3e92d4c7 100644
--- a/src/background/handlers/onStartupStoreCleanup.ts
+++ b/src/background/handlers/onStartupStoreCleanup.ts
@@ -16,4 +16,5 @@ export default function onStartupStoreCleanup(): void {
store.state.openedTwitchTabs = [];
store.state.streamStatuses = {};
store.state.videoWeaverUrlsByChannel = {};
+ store.state.chromiumProxyActive = false;
}
diff --git a/src/background/handlers/onTabCreated.ts b/src/background/handlers/onTabCreated.ts
index 9cb7e94b..1d8633f9 100644
--- a/src/background/handlers/onTabCreated.ts
+++ b/src/background/handlers/onTabCreated.ts
@@ -3,6 +3,7 @@ import getHostFromUrl from "../../common/ts/getHostFromUrl";
import isChromium from "../../common/ts/isChromium";
import { updateProxySettings } from "../../common/ts/proxySettings";
import { twitchTvHostRegex } from "../../common/ts/regexes";
+import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import store from "../../store";
export default function onTabCreated(tab: Tabs.Tab): void {
@@ -10,8 +11,13 @@ export default function onTabCreated(tab: Tabs.Tab): void {
const host = getHostFromUrl(tab.url);
if (host != null && twitchTvHostRegex.test(host)) {
console.log(`β Opened Twitch tab: ${tab.id}`);
- if (isChromium && store.state.openedTwitchTabs.length === 0) {
- updateProxySettings();
+ if (isChromium) {
+ var isNonWhitelistedChannel = true;
+ const url = new URL(tab.url);
+ if (url.pathname && url.pathname.length > 0) {
+ isNonWhitelistedChannel = !isChannelWhitelisted(url.pathname.substring(1));
+ }
+ if (isNonWhitelistedChannel && !store.state.chromiumProxyActive) updateProxySettings();
}
store.state.openedTwitchTabs.push(tab.id);
}
diff --git a/src/background/handlers/onTabRemoved.ts b/src/background/handlers/onTabRemoved.ts
index 26c81d66..74c40cb4 100644
--- a/src/background/handlers/onTabRemoved.ts
+++ b/src/background/handlers/onTabRemoved.ts
@@ -1,5 +1,7 @@
+import browser from "webextension-polyfill";
import isChromium from "../../common/ts/isChromium";
import { clearProxySettings } from "../../common/ts/proxySettings";
+import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import store from "../../store";
export default function onTabRemoved(tabId: number): void {
@@ -7,8 +9,24 @@ export default function onTabRemoved(tabId: number): void {
if (index !== -1) {
console.log(`β Closed Twitch tab: ${tabId}`);
store.state.openedTwitchTabs.splice(index, 1);
- if (isChromium && store.state.openedTwitchTabs.length === 0) {
- clearProxySettings();
+ if (isChromium) {
+ if (store.state.openedTwitchTabs.length === 0) {
+ clearProxySettings();
+ return;
+ }
+
+ Promise.all(store.state.openedTwitchTabs.map(tabId => {
+ return browser.tabs.get(tabId).then(tab => {
+ if (!tab.url) return false;
+ const url = new URL(tab.url);
+ if (!url.pathname || url.pathname == '/') return false;
+ return isChannelWhitelisted(url.pathname.substring(1));
+ }).catch(() => false);
+ })).then(res => {
+ if (!res.includes(false) && store.state.chromiumProxyActive) {
+ clearProxySettings();
+ }
+ });
}
}
}
diff --git a/src/background/handlers/onTabUpdated.ts b/src/background/handlers/onTabUpdated.ts
index c08aec9b..8ff7fff1 100644
--- a/src/background/handlers/onTabUpdated.ts
+++ b/src/background/handlers/onTabUpdated.ts
@@ -1,3 +1,4 @@
+import browser from "webextension-polyfill";
import { Tabs } from "webextension-polyfill";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
import isChromium from "../../common/ts/isChromium";
@@ -6,6 +7,7 @@ import {
updateProxySettings,
} from "../../common/ts/proxySettings";
import { twitchTvHostRegex } from "../../common/ts/regexes";
+import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import store from "../../store";
export default function onTabUpdated(
@@ -25,8 +27,13 @@ export default function onTabUpdated(
if (isTwitchTab && !wasTwitchTab) {
console.log(`β Opened Twitch tab: ${tabId}`);
- if (isChromium && store.state.openedTwitchTabs.length === 0) {
- updateProxySettings();
+ if (isChromium) {
+ var isNonWhitelistedPage = true;
+ const urlObj = new URL(url);
+ if (urlObj.pathname && urlObj.pathname.length > 0) {
+ isNonWhitelistedPage = !isChannelWhitelisted(urlObj.pathname.substring(1));
+ }
+ if (isNonWhitelistedPage) updateProxySettings();
}
store.state.openedTwitchTabs.push(tabId);
}
@@ -35,9 +42,44 @@ export default function onTabUpdated(
if (index !== -1) {
console.log(`β Closed Twitch tab: ${tabId}`);
store.state.openedTwitchTabs.splice(index, 1);
- if (isChromium && store.state.openedTwitchTabs.length === 0) {
- clearProxySettings();
+ if (isChromium) {
+ if (store.state.openedTwitchTabs.length === 0) {
+ clearProxySettings();
+ return;
+ }
+
+ Promise.all(store.state.openedTwitchTabs.map(tabId => {
+ return browser.tabs.get(tabId).then(tab => {
+ if (!tab.url) return false;
+ const url = new URL(tab.url);
+ if (!url.pathname || url.pathname == '/') return false;
+ return isChannelWhitelisted(url.pathname.substring(1));
+ }).catch(() => false);
+ })).then(res => {
+ if (!res.includes(false) && store.state.chromiumProxyActive) {
+ clearProxySettings();
+ }
+ });
}
}
}
+ if (isTwitchTab && wasTwitchTab) {
+ console.log(`Changed Twitch tab: ${tabId}`);
+ if (isChromium) {
+ Promise.all(store.state.openedTwitchTabs.map(tabId => {
+ return browser.tabs.get(tabId).then(tab => {
+ if (!tab.url) return false;
+ const url = new URL(tab.url);
+ if (!url.pathname || url.pathname == '/') return false;
+ return isChannelWhitelisted(url.pathname.substring(1));
+ }).catch(() => false);
+ })).then(res => {
+ if (!res.includes(false) && store.state.chromiumProxyActive) {
+ clearProxySettings();
+ } else if (res.includes(false) && !store.state.chromiumProxyActive) {
+ updateProxySettings();
+ }
+ });
+ }
+ }
}
diff --git a/src/options/options.ts b/src/options/options.ts
index 12592801..fd9af96b 100644
--- a/src/options/options.ts
+++ b/src/options/options.ts
@@ -116,15 +116,11 @@ function main() {
});
}
// Whitelisted channels
- if (isChromium) {
- whitelistedChannelsSectionElement.style.display = "none";
- } else {
listInit(whitelistedChannelsListElement, "whitelistedChannels", {
getAlreadyExistsAlertMessage: channelName =>
`'${channelName}' is already whitelisted`,
getPromptPlaceholder: () => "Enter a channel nameβ¦",
});
- }
// Proxies
if (isChromium) {
optimizedProxiesDivElement.style.display = "none";
diff --git a/src/popup/popup.ts b/src/popup/popup.ts
index bcb531d8..14e82d51 100644
--- a/src/popup/popup.ts
+++ b/src/popup/popup.ts
@@ -84,9 +84,6 @@ function setStreamStatusElement(channelName: string) {
setProxyStatus(channelNameLower, status);
setWhitelistStatus(channelNameLower);
streamStatusElement.style.display = "flex";
- if (isChromium) {
- whitelistStatusElement.style.display = "none";
- }
} else {
streamStatusElement.style.display = "none";
}
diff --git a/src/store/types.ts b/src/store/types.ts
index 1ca2f8b2..33398b9d 100644
--- a/src/store/types.ts
+++ b/src/store/types.ts
@@ -9,6 +9,7 @@ export interface State {
adLogEnabled: boolean;
adLogLastSent: number;
anonymousMode: boolean;
+ chromiumProxyActive: boolean;
dnsResponses: DnsResponse[];
normalProxies: string[];
openedTwitchTabs: number[];
From 79522805bc558853992118b7875b73101046b671 Mon Sep 17 00:00:00 2001
From: Luke Fanning
Date: Sun, 24 Sep 2023 12:47:35 +0100
Subject: [PATCH 20/42] Linting fix
---
src/background/background.ts | 2 +-
.../handlers/onProxySettingsChanged.ts | 11 ++--
src/background/handlers/onTabCreated.ts | 9 ++--
src/background/handlers/onTabRemoved.ts | 23 ++++----
src/background/handlers/onTabUpdated.ts | 53 +++++++++++--------
src/options/options.ts | 10 ++--
6 files changed, 65 insertions(+), 43 deletions(-)
diff --git a/src/background/background.ts b/src/background/background.ts
index 30ac6ffd..55397d63 100644
--- a/src/background/background.ts
+++ b/src/background/background.ts
@@ -5,12 +5,12 @@ import onAuthRequired from "./handlers/onAuthRequired";
import onBeforeSendHeaders from "./handlers/onBeforeSendHeaders";
import onBeforeVideoWeaverRequest from "./handlers/onBeforeVideoWeaverRequest";
import onProxyRequest from "./handlers/onProxyRequest";
+import onProxySettingsChange from "./handlers/onProxySettingsChanged";
import onResponseStarted from "./handlers/onResponseStarted";
import onStartupStoreCleanup from "./handlers/onStartupStoreCleanup";
import onTabCreated from "./handlers/onTabCreated";
import onTabRemoved from "./handlers/onTabRemoved";
import onTabUpdated from "./handlers/onTabUpdated";
-import onProxySettingsChange from "./handlers/onProxySettingsChanged";
console.info("π Background script loaded.");
diff --git a/src/background/handlers/onProxySettingsChanged.ts b/src/background/handlers/onProxySettingsChanged.ts
index 0dfe524d..56820405 100644
--- a/src/background/handlers/onProxySettingsChanged.ts
+++ b/src/background/handlers/onProxySettingsChanged.ts
@@ -1,6 +1,9 @@
import store from "../../store";
-export default function onProxySettingsChange(details: chrome.types.ChromeSettingGetResultDetails) {
- console.log("PROXY SETTINGS CHANGE: " + details.levelOfControl);
- store.state.chromiumProxyActive = details.levelOfControl == "controlled_by_this_extension";
-}
\ No newline at end of file
+export default function onProxySettingsChange(
+ details: chrome.types.ChromeSettingGetResultDetails
+) {
+ console.log("PROXY SETTINGS CHANGE: " + details.levelOfControl);
+ store.state.chromiumProxyActive =
+ details.levelOfControl == "controlled_by_this_extension";
+}
diff --git a/src/background/handlers/onTabCreated.ts b/src/background/handlers/onTabCreated.ts
index 1d8633f9..71be2b8c 100644
--- a/src/background/handlers/onTabCreated.ts
+++ b/src/background/handlers/onTabCreated.ts
@@ -1,9 +1,9 @@
import { Tabs } from "webextension-polyfill";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
+import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isChromium from "../../common/ts/isChromium";
import { updateProxySettings } from "../../common/ts/proxySettings";
import { twitchTvHostRegex } from "../../common/ts/regexes";
-import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import store from "../../store";
export default function onTabCreated(tab: Tabs.Tab): void {
@@ -15,9 +15,12 @@ export default function onTabCreated(tab: Tabs.Tab): void {
var isNonWhitelistedChannel = true;
const url = new URL(tab.url);
if (url.pathname && url.pathname.length > 0) {
- isNonWhitelistedChannel = !isChannelWhitelisted(url.pathname.substring(1));
+ isNonWhitelistedChannel = !isChannelWhitelisted(
+ url.pathname.substring(1)
+ );
}
- if (isNonWhitelistedChannel && !store.state.chromiumProxyActive) updateProxySettings();
+ if (isNonWhitelistedChannel && !store.state.chromiumProxyActive)
+ updateProxySettings();
}
store.state.openedTwitchTabs.push(tab.id);
}
diff --git a/src/background/handlers/onTabRemoved.ts b/src/background/handlers/onTabRemoved.ts
index 74c40cb4..1a36c954 100644
--- a/src/background/handlers/onTabRemoved.ts
+++ b/src/background/handlers/onTabRemoved.ts
@@ -1,7 +1,7 @@
import browser from "webextension-polyfill";
+import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isChromium from "../../common/ts/isChromium";
import { clearProxySettings } from "../../common/ts/proxySettings";
-import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import store from "../../store";
export default function onTabRemoved(tabId: number): void {
@@ -15,14 +15,19 @@ export default function onTabRemoved(tabId: number): void {
return;
}
- Promise.all(store.state.openedTwitchTabs.map(tabId => {
- return browser.tabs.get(tabId).then(tab => {
- if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == '/') return false;
- return isChannelWhitelisted(url.pathname.substring(1));
- }).catch(() => false);
- })).then(res => {
+ Promise.all(
+ store.state.openedTwitchTabs.map(tabId => {
+ return browser.tabs
+ .get(tabId)
+ .then(tab => {
+ if (!tab.url) return false;
+ const url = new URL(tab.url);
+ if (!url.pathname || url.pathname == "/") return false;
+ return isChannelWhitelisted(url.pathname.substring(1));
+ })
+ .catch(() => false);
+ })
+ ).then(res => {
if (!res.includes(false) && store.state.chromiumProxyActive) {
clearProxySettings();
}
diff --git a/src/background/handlers/onTabUpdated.ts b/src/background/handlers/onTabUpdated.ts
index 8ff7fff1..ee151061 100644
--- a/src/background/handlers/onTabUpdated.ts
+++ b/src/background/handlers/onTabUpdated.ts
@@ -1,13 +1,12 @@
-import browser from "webextension-polyfill";
-import { Tabs } from "webextension-polyfill";
+import browser, { Tabs } from "webextension-polyfill";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
+import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isChromium from "../../common/ts/isChromium";
import {
clearProxySettings,
updateProxySettings,
} from "../../common/ts/proxySettings";
import { twitchTvHostRegex } from "../../common/ts/regexes";
-import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import store from "../../store";
export default function onTabUpdated(
@@ -31,7 +30,9 @@ export default function onTabUpdated(
var isNonWhitelistedPage = true;
const urlObj = new URL(url);
if (urlObj.pathname && urlObj.pathname.length > 0) {
- isNonWhitelistedPage = !isChannelWhitelisted(urlObj.pathname.substring(1));
+ isNonWhitelistedPage = !isChannelWhitelisted(
+ urlObj.pathname.substring(1)
+ );
}
if (isNonWhitelistedPage) updateProxySettings();
}
@@ -47,15 +48,20 @@ export default function onTabUpdated(
clearProxySettings();
return;
}
-
- Promise.all(store.state.openedTwitchTabs.map(tabId => {
- return browser.tabs.get(tabId).then(tab => {
- if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == '/') return false;
- return isChannelWhitelisted(url.pathname.substring(1));
- }).catch(() => false);
- })).then(res => {
+
+ Promise.all(
+ store.state.openedTwitchTabs.map(tabId => {
+ return browser.tabs
+ .get(tabId)
+ .then(tab => {
+ if (!tab.url) return false;
+ const url = new URL(tab.url);
+ if (!url.pathname || url.pathname == "/") return false;
+ return isChannelWhitelisted(url.pathname.substring(1));
+ })
+ .catch(() => false);
+ })
+ ).then(res => {
if (!res.includes(false) && store.state.chromiumProxyActive) {
clearProxySettings();
}
@@ -66,14 +72,19 @@ export default function onTabUpdated(
if (isTwitchTab && wasTwitchTab) {
console.log(`Changed Twitch tab: ${tabId}`);
if (isChromium) {
- Promise.all(store.state.openedTwitchTabs.map(tabId => {
- return browser.tabs.get(tabId).then(tab => {
- if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == '/') return false;
- return isChannelWhitelisted(url.pathname.substring(1));
- }).catch(() => false);
- })).then(res => {
+ Promise.all(
+ store.state.openedTwitchTabs.map(tabId => {
+ return browser.tabs
+ .get(tabId)
+ .then(tab => {
+ if (!tab.url) return false;
+ const url = new URL(tab.url);
+ if (!url.pathname || url.pathname == "/") return false;
+ return isChannelWhitelisted(url.pathname.substring(1));
+ })
+ .catch(() => false);
+ })
+ ).then(res => {
if (!res.includes(false) && store.state.chromiumProxyActive) {
clearProxySettings();
} else if (res.includes(false) && !store.state.chromiumProxyActive) {
diff --git a/src/options/options.ts b/src/options/options.ts
index fd9af96b..6e5040d3 100644
--- a/src/options/options.ts
+++ b/src/options/options.ts
@@ -116,11 +116,11 @@ function main() {
});
}
// Whitelisted channels
- listInit(whitelistedChannelsListElement, "whitelistedChannels", {
- getAlreadyExistsAlertMessage: channelName =>
- `'${channelName}' is already whitelisted`,
- getPromptPlaceholder: () => "Enter a channel nameβ¦",
- });
+ listInit(whitelistedChannelsListElement, "whitelistedChannels", {
+ getAlreadyExistsAlertMessage: channelName =>
+ `'${channelName}' is already whitelisted`,
+ getPromptPlaceholder: () => "Enter a channel nameβ¦",
+ });
// Proxies
if (isChromium) {
optimizedProxiesDivElement.style.display = "none";
From a0f777fe95fffabf81b6b79354291cafff1e86e5 Mon Sep 17 00:00:00 2001
From: Luke Fanning
Date: Sun, 24 Sep 2023 12:50:26 +0100
Subject: [PATCH 21/42] Updated default state with chromiumProxyActive
---
src/store/getDefaultState.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/store/getDefaultState.ts b/src/store/getDefaultState.ts
index 8ce82b18..4eaa18ef 100644
--- a/src/store/getDefaultState.ts
+++ b/src/store/getDefaultState.ts
@@ -7,6 +7,7 @@ export default function getDefaultState() {
adLogEnabled: true,
adLogLastSent: 0,
anonymousMode: false,
+ chromiumProxyActive: false,
dnsResponses: [],
normalProxies: ["chrome.api.cdn-perfprod.com:4023"],
openedTwitchTabs: [],
From c48123aebcf2dc4b9502bc07651e6eaabee6e148 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Wed, 4 Oct 2023 14:45:44 +0200
Subject: [PATCH 22/42] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20nitpicks?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/background.ts | 6 ++---
.../handlers/onProxySettingsChanged.ts | 5 +++--
.../handlers/onStartupStoreCleanup.ts | 2 +-
src/background/handlers/onTabCreated.ts | 8 +++----
src/background/handlers/onTabRemoved.ts | 6 ++---
src/background/handlers/onTabUpdated.ts | 22 +++++++++----------
6 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/src/background/background.ts b/src/background/background.ts
index 55397d63..8db61947 100644
--- a/src/background/background.ts
+++ b/src/background/background.ts
@@ -30,6 +30,9 @@ browser.webRequest.onResponseStarted.addListener(onResponseStarted, {
});
if (isChromium) {
+ // Listen to whether proxy is set or not.
+ browser.proxy.settings.onChange.addListener(onProxySettingsChange);
+
// Check if there are any opened Twitch tabs on startup.
checkForOpenedTwitchTabs();
@@ -37,9 +40,6 @@ if (isChromium) {
browser.tabs.onCreated.addListener(onTabCreated);
browser.tabs.onUpdated.addListener(onTabUpdated);
browser.tabs.onRemoved.addListener(onTabRemoved);
-
- // Listen to whether proxy is set or not
- chrome.proxy.settings.onChange.addListener(onProxySettingsChange);
} else {
// Block tracking pixels.
browser.webRequest.onBeforeRequest.addListener(
diff --git a/src/background/handlers/onProxySettingsChanged.ts b/src/background/handlers/onProxySettingsChanged.ts
index 56820405..49735710 100644
--- a/src/background/handlers/onProxySettingsChanged.ts
+++ b/src/background/handlers/onProxySettingsChanged.ts
@@ -1,9 +1,10 @@
+import { Types } from "webextension-polyfill";
import store from "../../store";
export default function onProxySettingsChange(
- details: chrome.types.ChromeSettingGetResultDetails
+ details: Types.SettingOnChangeDetailsType
) {
- console.log("PROXY SETTINGS CHANGE: " + details.levelOfControl);
+ console.log(`βοΈ Proxy settings changed: ${details.levelOfControl}`);
store.state.chromiumProxyActive =
details.levelOfControl == "controlled_by_this_extension";
}
diff --git a/src/background/handlers/onStartupStoreCleanup.ts b/src/background/handlers/onStartupStoreCleanup.ts
index 3e92d4c7..af1d2c2b 100644
--- a/src/background/handlers/onStartupStoreCleanup.ts
+++ b/src/background/handlers/onStartupStoreCleanup.ts
@@ -12,9 +12,9 @@ export default function onStartupStoreCleanup(): void {
if (store.readyState !== "complete")
return store.addEventListener("load", onStartupStoreCleanup);
+ store.state.chromiumProxyActive = false;
store.state.dnsResponses = [];
store.state.openedTwitchTabs = [];
store.state.streamStatuses = {};
store.state.videoWeaverUrlsByChannel = {};
- store.state.chromiumProxyActive = false;
}
diff --git a/src/background/handlers/onTabCreated.ts b/src/background/handlers/onTabCreated.ts
index 71be2b8c..231a6790 100644
--- a/src/background/handlers/onTabCreated.ts
+++ b/src/background/handlers/onTabCreated.ts
@@ -12,11 +12,11 @@ export default function onTabCreated(tab: Tabs.Tab): void {
if (host != null && twitchTvHostRegex.test(host)) {
console.log(`β Opened Twitch tab: ${tab.id}`);
if (isChromium) {
- var isNonWhitelistedChannel = true;
- const url = new URL(tab.url);
- if (url.pathname && url.pathname.length > 0) {
+ let isNonWhitelistedChannel = true;
+ const Url = new URL(tab.url);
+ if (Url.pathname && Url.pathname.length > 0) {
isNonWhitelistedChannel = !isChannelWhitelisted(
- url.pathname.substring(1)
+ Url.pathname.substring(1)
);
}
if (isNonWhitelistedChannel && !store.state.chromiumProxyActive)
diff --git a/src/background/handlers/onTabRemoved.ts b/src/background/handlers/onTabRemoved.ts
index 1a36c954..4da91531 100644
--- a/src/background/handlers/onTabRemoved.ts
+++ b/src/background/handlers/onTabRemoved.ts
@@ -21,9 +21,9 @@ export default function onTabRemoved(tabId: number): void {
.get(tabId)
.then(tab => {
if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == "/") return false;
- return isChannelWhitelisted(url.pathname.substring(1));
+ const Url = new URL(tab.url);
+ if (!Url.pathname || Url.pathname == "/") return false;
+ return isChannelWhitelisted(Url.pathname.substring(1));
})
.catch(() => false);
})
diff --git a/src/background/handlers/onTabUpdated.ts b/src/background/handlers/onTabUpdated.ts
index ee151061..99b3fc50 100644
--- a/src/background/handlers/onTabUpdated.ts
+++ b/src/background/handlers/onTabUpdated.ts
@@ -27,12 +27,10 @@ export default function onTabUpdated(
if (isTwitchTab && !wasTwitchTab) {
console.log(`β Opened Twitch tab: ${tabId}`);
if (isChromium) {
- var isNonWhitelistedPage = true;
- const urlObj = new URL(url);
- if (urlObj.pathname && urlObj.pathname.length > 0) {
- isNonWhitelistedPage = !isChannelWhitelisted(
- urlObj.pathname.substring(1)
- );
+ let isNonWhitelistedPage = true;
+ const Url = new URL(url);
+ if (Url.pathname && Url.pathname.length > 0) {
+ isNonWhitelistedPage = !isChannelWhitelisted(Url.pathname.substring(1));
}
if (isNonWhitelistedPage) updateProxySettings();
}
@@ -55,9 +53,9 @@ export default function onTabUpdated(
.get(tabId)
.then(tab => {
if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == "/") return false;
- return isChannelWhitelisted(url.pathname.substring(1));
+ const Url = new URL(tab.url);
+ if (!Url.pathname || Url.pathname == "/") return false;
+ return isChannelWhitelisted(Url.pathname.substring(1));
})
.catch(() => false);
})
@@ -78,9 +76,9 @@ export default function onTabUpdated(
.get(tabId)
.then(tab => {
if (!tab.url) return false;
- const url = new URL(tab.url);
- if (!url.pathname || url.pathname == "/") return false;
- return isChannelWhitelisted(url.pathname.substring(1));
+ const Url = new URL(tab.url);
+ if (!Url.pathname || Url.pathname == "/") return false;
+ return isChannelWhitelisted(Url.pathname.substring(1));
})
.catch(() => false);
})
From 9fffbbc283b9902e4bfdd4bc4bffb02298fe2feb Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Wed, 4 Oct 2023 17:30:26 +0200
Subject: [PATCH 23/42] =?UTF-8?q?=F0=9F=8E=A8=20Cleaner=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/handlers/onTabCreated.ts | 27 ++++---
src/background/handlers/onTabRemoved.ts | 47 +++++-------
src/background/handlers/onTabUpdated.ts | 99 +++++++++----------------
src/options/page.html | 2 +
src/store/types.ts | 3 +-
5 files changed, 75 insertions(+), 103 deletions(-)
diff --git a/src/background/handlers/onTabCreated.ts b/src/background/handlers/onTabCreated.ts
index 231a6790..b47eb55f 100644
--- a/src/background/handlers/onTabCreated.ts
+++ b/src/background/handlers/onTabCreated.ts
@@ -1,4 +1,5 @@
import { Tabs } from "webextension-polyfill";
+import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isChromium from "../../common/ts/isChromium";
@@ -7,21 +8,23 @@ import { twitchTvHostRegex } from "../../common/ts/regexes";
import store from "../../store";
export default function onTabCreated(tab: Tabs.Tab): void {
- if (!tab.url || tab.id == null) return;
- const host = getHostFromUrl(tab.url);
- if (host != null && twitchTvHostRegex.test(host)) {
+ const url = tab.url || tab.pendingUrl;
+ if (!url) return;
+ const host = getHostFromUrl(url);
+ if (!host) return;
+
+ if (twitchTvHostRegex.test(host)) {
console.log(`β Opened Twitch tab: ${tab.id}`);
+ store.state.openedTwitchTabs.push(tab);
+
if (isChromium) {
- let isNonWhitelistedChannel = true;
- const Url = new URL(tab.url);
- if (Url.pathname && Url.pathname.length > 0) {
- isNonWhitelistedChannel = !isChannelWhitelisted(
- Url.pathname.substring(1)
- );
- }
- if (isNonWhitelistedChannel && !store.state.chromiumProxyActive)
+ const channelName = findChannelFromTwitchTvUrl(url);
+ const isWhitelisted = channelName
+ ? isChannelWhitelisted(channelName)
+ : false;
+ if (!isWhitelisted && !store.state.chromiumProxyActive) {
updateProxySettings();
+ }
}
- store.state.openedTwitchTabs.push(tab.id);
}
}
diff --git a/src/background/handlers/onTabRemoved.ts b/src/background/handlers/onTabRemoved.ts
index 4da91531..66e21be5 100644
--- a/src/background/handlers/onTabRemoved.ts
+++ b/src/background/handlers/onTabRemoved.ts
@@ -1,37 +1,30 @@
-import browser from "webextension-polyfill";
+import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isChromium from "../../common/ts/isChromium";
import { clearProxySettings } from "../../common/ts/proxySettings";
import store from "../../store";
export default function onTabRemoved(tabId: number): void {
- const index = store.state.openedTwitchTabs.indexOf(tabId);
- if (index !== -1) {
- console.log(`β Closed Twitch tab: ${tabId}`);
- store.state.openedTwitchTabs.splice(index, 1);
- if (isChromium) {
- if (store.state.openedTwitchTabs.length === 0) {
- clearProxySettings();
- return;
- }
+ const index = store.state.openedTwitchTabs.findIndex(tab => tab.id === tabId);
+ if (index === -1) return;
- Promise.all(
- store.state.openedTwitchTabs.map(tabId => {
- return browser.tabs
- .get(tabId)
- .then(tab => {
- if (!tab.url) return false;
- const Url = new URL(tab.url);
- if (!Url.pathname || Url.pathname == "/") return false;
- return isChannelWhitelisted(Url.pathname.substring(1));
- })
- .catch(() => false);
- })
- ).then(res => {
- if (!res.includes(false) && store.state.chromiumProxyActive) {
- clearProxySettings();
- }
- });
+ console.log(`β Closed Twitch tab: ${tabId}`);
+ store.state.openedTwitchTabs.splice(index, 1);
+
+ if (isChromium) {
+ const allTabsAreWhitelisted = store.state.openedTwitchTabs.every(tab => {
+ if (!tab.url) return false;
+ const channelName = findChannelFromTwitchTvUrl(tab.url);
+ const isWhitelisted = channelName
+ ? isChannelWhitelisted(channelName)
+ : false;
+ return isWhitelisted;
+ });
+ if (
+ (store.state.openedTwitchTabs.length === 0 || allTabsAreWhitelisted) &&
+ store.state.chromiumProxyActive
+ ) {
+ clearProxySettings();
}
}
}
diff --git a/src/background/handlers/onTabUpdated.ts b/src/background/handlers/onTabUpdated.ts
index 99b3fc50..342e032b 100644
--- a/src/background/handlers/onTabUpdated.ts
+++ b/src/background/handlers/onTabUpdated.ts
@@ -1,4 +1,5 @@
-import browser, { Tabs } from "webextension-polyfill";
+import { Tabs } from "webextension-polyfill";
+import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isChromium from "../../common/ts/isChromium";
@@ -8,6 +9,8 @@ import {
} from "../../common/ts/proxySettings";
import { twitchTvHostRegex } from "../../common/ts/regexes";
import store from "../../store";
+import onTabCreated from "./onTabCreated";
+import onTabRemoved from "./onTabRemoved";
export default function onTabUpdated(
tabId: number,
@@ -16,79 +19,49 @@ export default function onTabUpdated(
): void {
// Also check for `changeInfo.status === "complete"` because the `url` property
// is not always accurate when navigating to a new page.
- if (!(changeInfo.url || changeInfo.status === "complete")) return;
+ if (!(changeInfo.url || changeInfo.status === "loading")) return;
- const url = changeInfo.url || tab.url;
+ const url = changeInfo.url || tab.url || tab.pendingUrl;
if (!url) return;
const host = getHostFromUrl(url);
- const isTwitchTab = host != null && twitchTvHostRegex.test(host);
- const wasTwitchTab = store.state.openedTwitchTabs.includes(tabId);
+ if (!host) return;
+
+ const isTwitchTab = twitchTvHostRegex.test(host);
+ const wasTwitchTab = store.state.openedTwitchTabs.findIndex(
+ tab => tab.id === tabId
+ );
if (isTwitchTab && !wasTwitchTab) {
- console.log(`β Opened Twitch tab: ${tabId}`);
- if (isChromium) {
- let isNonWhitelistedPage = true;
- const Url = new URL(url);
- if (Url.pathname && Url.pathname.length > 0) {
- isNonWhitelistedPage = !isChannelWhitelisted(Url.pathname.substring(1));
- }
- if (isNonWhitelistedPage) updateProxySettings();
- }
- store.state.openedTwitchTabs.push(tabId);
+ onTabCreated(tab);
}
- if (!isTwitchTab && wasTwitchTab) {
- const index = store.state.openedTwitchTabs.indexOf(tabId);
- if (index !== -1) {
- console.log(`β Closed Twitch tab: ${tabId}`);
- store.state.openedTwitchTabs.splice(index, 1);
- if (isChromium) {
- if (store.state.openedTwitchTabs.length === 0) {
- clearProxySettings();
- return;
- }
- Promise.all(
- store.state.openedTwitchTabs.map(tabId => {
- return browser.tabs
- .get(tabId)
- .then(tab => {
- if (!tab.url) return false;
- const Url = new URL(tab.url);
- if (!Url.pathname || Url.pathname == "/") return false;
- return isChannelWhitelisted(Url.pathname.substring(1));
- })
- .catch(() => false);
- })
- ).then(res => {
- if (!res.includes(false) && store.state.chromiumProxyActive) {
- clearProxySettings();
- }
- });
- }
- }
+ if (!isTwitchTab && wasTwitchTab) {
+ onTabRemoved(tabId);
}
+
if (isTwitchTab && wasTwitchTab) {
- console.log(`Changed Twitch tab: ${tabId}`);
+ const index = store.state.openedTwitchTabs.findIndex(
+ tab => tab.id === tabId
+ );
+ if (index === -1) return;
+
+ console.log(`π° Updated Twitch tab: ${tabId}`);
+ store.state.openedTwitchTabs[index] = tab;
+
if (isChromium) {
- Promise.all(
- store.state.openedTwitchTabs.map(tabId => {
- return browser.tabs
- .get(tabId)
- .then(tab => {
- if (!tab.url) return false;
- const Url = new URL(tab.url);
- if (!Url.pathname || Url.pathname == "/") return false;
- return isChannelWhitelisted(Url.pathname.substring(1));
- })
- .catch(() => false);
- })
- ).then(res => {
- if (!res.includes(false) && store.state.chromiumProxyActive) {
- clearProxySettings();
- } else if (res.includes(false) && !store.state.chromiumProxyActive) {
- updateProxySettings();
- }
+ const allTabsAreWhitelisted = store.state.openedTwitchTabs.every(tab => {
+ if (!tab.url) return false;
+ const channelName = findChannelFromTwitchTvUrl(tab.url);
+ const isWhitelisted = channelName
+ ? isChannelWhitelisted(channelName)
+ : false;
+ return isWhitelisted;
});
+ if (!allTabsAreWhitelisted && !store.state.chromiumProxyActive) {
+ updateProxySettings();
+ } else if (allTabsAreWhitelisted && store.state.chromiumProxyActive) {
+ clearProxySettings();
+ }
}
}
}
diff --git a/src/options/page.html b/src/options/page.html
index 1dd6baf1..517b8813 100644
--- a/src/options/page.html
+++ b/src/options/page.html
@@ -108,6 +108,8 @@
Passport
Whitelisted channels
Support your favorite content creators by whitelisting their channels.
+ On Chromium-based browsers, whitelisting only works when all opened
+ Twitch tabs are whitelisted.
Support your favorite content creators by whitelisting their channels.
On Chromium-based browsers, whitelisting only works when all opened
- Twitch tabs are whitelisted.
+ Twitch tabs are whitelisted channels.
The proxy you are using has a limited number of simultaneous connections.
This means that you may experience buffering issues. Consider donating to
- get access to unlimited proxies.
+ get access to unlimited proxies, or
+ host your own proxy.
From cf51e055a71ad60afa6529b6f8509c3b86a400b7 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Thu, 5 Oct 2023 13:17:58 +0200
Subject: [PATCH 36/42] =?UTF-8?q?=F0=9F=92=A1=20Add=20comment?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/handlers/onTabCreated.ts | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/background/handlers/onTabCreated.ts b/src/background/handlers/onTabCreated.ts
index b47eb55f..31c5c7a1 100644
--- a/src/background/handlers/onTabCreated.ts
+++ b/src/background/handlers/onTabCreated.ts
@@ -13,6 +13,9 @@ export default function onTabCreated(tab: Tabs.Tab): void {
const host = getHostFromUrl(url);
if (!host) return;
+ // TODO: `twitchTvHostRegex` doesn't match `appeals.twitch.tv` and
+ // `dashboard.twitch.tv` which means that passport requests from those
+ // subdomains will not be proxied. This could mess up the cookie country.
if (twitchTvHostRegex.test(host)) {
console.log(`β Opened Twitch tab: ${tab.id}`);
store.state.openedTwitchTabs.push(tab);
From bf489b24f4d7ff8412b7f355d4085a9a162781a4 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Thu, 5 Oct 2023 13:28:49 +0200
Subject: [PATCH 37/42] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Reorganize=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../handlers/checkForOpenedTwitchTabs.ts | 12 ++----------
src/background/handlers/onTabRemoved.ts | 14 ++++----------
src/background/handlers/onTabUpdated.ts | 14 ++++----------
src/common/ts/areAllTabsWhitelisted.ts | 15 +++++++++++++++
4 files changed, 25 insertions(+), 30 deletions(-)
create mode 100644 src/common/ts/areAllTabsWhitelisted.ts
diff --git a/src/background/handlers/checkForOpenedTwitchTabs.ts b/src/background/handlers/checkForOpenedTwitchTabs.ts
index a9840a64..25550daf 100644
--- a/src/background/handlers/checkForOpenedTwitchTabs.ts
+++ b/src/background/handlers/checkForOpenedTwitchTabs.ts
@@ -1,6 +1,5 @@
import browser from "webextension-polyfill";
-import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
-import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
+import areAllTabsWhitelisted from "../../common/ts/areAllTabsWhitelisted";
import isChromium from "../../common/ts/isChromium";
import {
clearProxySettings,
@@ -19,14 +18,7 @@ export default function checkForOpenedTwitchTabs() {
store.state.openedTwitchTabs = tabs;
if (isChromium) {
- const allTabsAreWhitelisted = tabs.every(tab => {
- if (!tab.url) return false;
- const channelName = findChannelFromTwitchTvUrl(tab.url);
- const isWhitelisted = channelName
- ? isChannelWhitelisted(channelName)
- : false;
- return isWhitelisted;
- });
+ const allTabsAreWhitelisted = areAllTabsWhitelisted(tabs);
if (tabs.length === 0 || allTabsAreWhitelisted) {
clearProxySettings();
} else {
diff --git a/src/background/handlers/onTabRemoved.ts b/src/background/handlers/onTabRemoved.ts
index 66e21be5..735adf9a 100644
--- a/src/background/handlers/onTabRemoved.ts
+++ b/src/background/handlers/onTabRemoved.ts
@@ -1,5 +1,4 @@
-import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
-import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
+import areAllTabsWhitelisted from "../../common/ts/areAllTabsWhitelisted";
import isChromium from "../../common/ts/isChromium";
import { clearProxySettings } from "../../common/ts/proxySettings";
import store from "../../store";
@@ -12,14 +11,9 @@ export default function onTabRemoved(tabId: number): void {
store.state.openedTwitchTabs.splice(index, 1);
if (isChromium) {
- const allTabsAreWhitelisted = store.state.openedTwitchTabs.every(tab => {
- if (!tab.url) return false;
- const channelName = findChannelFromTwitchTvUrl(tab.url);
- const isWhitelisted = channelName
- ? isChannelWhitelisted(channelName)
- : false;
- return isWhitelisted;
- });
+ const allTabsAreWhitelisted = areAllTabsWhitelisted(
+ store.state.openedTwitchTabs
+ );
if (
(store.state.openedTwitchTabs.length === 0 || allTabsAreWhitelisted) &&
store.state.chromiumProxyActive
diff --git a/src/background/handlers/onTabUpdated.ts b/src/background/handlers/onTabUpdated.ts
index 4beac193..cc7227a6 100644
--- a/src/background/handlers/onTabUpdated.ts
+++ b/src/background/handlers/onTabUpdated.ts
@@ -1,7 +1,6 @@
import { Tabs } from "webextension-polyfill";
-import findChannelFromTwitchTvUrl from "../../common/ts/findChannelFromTwitchTvUrl";
+import areAllTabsWhitelisted from "../../common/ts/areAllTabsWhitelisted";
import getHostFromUrl from "../../common/ts/getHostFromUrl";
-import isChannelWhitelisted from "../../common/ts/isChannelWhitelisted";
import isChromium from "../../common/ts/isChromium";
import {
clearProxySettings,
@@ -56,14 +55,9 @@ export default function onTabUpdated(
store.state.openedTwitchTabs[index] = tab;
if (isChromium) {
- const allTabsAreWhitelisted = store.state.openedTwitchTabs.every(tab => {
- if (!tab.url) return false;
- const channelName = findChannelFromTwitchTvUrl(tab.url);
- const isWhitelisted = channelName
- ? isChannelWhitelisted(channelName)
- : false;
- return isWhitelisted;
- });
+ const allTabsAreWhitelisted = areAllTabsWhitelisted(
+ store.state.openedTwitchTabs
+ );
if (!allTabsAreWhitelisted && !store.state.chromiumProxyActive) {
updateProxySettings();
} else if (allTabsAreWhitelisted && store.state.chromiumProxyActive) {
diff --git a/src/common/ts/areAllTabsWhitelisted.ts b/src/common/ts/areAllTabsWhitelisted.ts
new file mode 100644
index 00000000..f56bc02b
--- /dev/null
+++ b/src/common/ts/areAllTabsWhitelisted.ts
@@ -0,0 +1,15 @@
+import { Tabs } from "webextension-polyfill";
+import findChannelFromTwitchTvUrl from "./findChannelFromTwitchTvUrl";
+import isChannelWhitelisted from "./isChannelWhitelisted";
+
+export default function areAllTabsWhitelisted(tabs: Tabs.Tab[]): boolean {
+ return tabs.every(tab => {
+ const url = tab.url || tab.pendingUrl;
+ if (!url) return false;
+ const channelName = findChannelFromTwitchTvUrl(url);
+ const isWhitelisted = channelName
+ ? isChannelWhitelisted(channelName)
+ : false;
+ return isWhitelisted;
+ });
+}
From 88f33829d95fb3da880cac11e30a6f5e6cf90126 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Thu, 5 Oct 2023 13:57:32 +0200
Subject: [PATCH 38/42] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/handlers/checkForOpenedTwitchTabs.ts | 6 +++---
src/background/handlers/onBeforeVideoWeaverRequest.ts | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/background/handlers/checkForOpenedTwitchTabs.ts b/src/background/handlers/checkForOpenedTwitchTabs.ts
index 25550daf..485f9eae 100644
--- a/src/background/handlers/checkForOpenedTwitchTabs.ts
+++ b/src/background/handlers/checkForOpenedTwitchTabs.ts
@@ -19,10 +19,10 @@ export default function checkForOpenedTwitchTabs() {
if (isChromium) {
const allTabsAreWhitelisted = areAllTabsWhitelisted(tabs);
- if (tabs.length === 0 || allTabsAreWhitelisted) {
- clearProxySettings();
- } else {
+ if (tabs.length > 0 && !allTabsAreWhitelisted) {
updateProxySettings();
+ } else {
+ clearProxySettings();
}
}
});
diff --git a/src/background/handlers/onBeforeVideoWeaverRequest.ts b/src/background/handlers/onBeforeVideoWeaverRequest.ts
index f4b4cf0a..30adcbf9 100644
--- a/src/background/handlers/onBeforeVideoWeaverRequest.ts
+++ b/src/background/handlers/onBeforeVideoWeaverRequest.ts
@@ -39,10 +39,10 @@ export default function onBeforeVideoWeaverRequest(
const isPurpleScreen = textLower.includes(
"https://help.twitch.tv/s/article/ad-experience-on-twitch"
);
- let proxy: string | null = null;
- if (details.proxyInfo && details.proxyInfo.type !== "direct") {
- proxy = `${details.proxyInfo.host}:${details.proxyInfo.port}`;
- }
+ const proxy =
+ details.proxyInfo && details.proxyInfo.type !== "direct"
+ ? `${details.proxyInfo.host}:${details.proxyInfo.port}`
+ : null;
const adLog = store.state.adLog.filter(
entry => details.timeStamp - entry.timestamp < 1000 * 60 * 60 * 24 * 7 // 7 days
From bcd3fe59c16d5084e8dddc10dd98345b03284fd0 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Thu, 5 Oct 2023 14:19:01 +0200
Subject: [PATCH 39/42] =?UTF-8?q?=F0=9F=93=9D=20Update=20README?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 20adeae6..cfcc2458 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,7 @@ TTV LOL PRO removes _most_ livestream ads from Twitch. This is free, don't expec
**TTV LOL PRO:**
- removes _most_ livestream ads from Twitch,
-- lets you whitelist channels (Firefox only),
+- lets you whitelist channels,
- improves TTV LOL's popup by showing stream status,
- lets you add custom primary/fallback proxies.
From e2a0782640ef026650c84292b26bc99ac9d09c75 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Thu, 5 Oct 2023 15:31:57 +0200
Subject: [PATCH 40/42] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug=20when=20updatin?=
=?UTF-8?q?g=20proxies?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/options/options.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/options/options.ts b/src/options/options.ts
index cd44fb4b..dd723619 100644
--- a/src/options/options.ts
+++ b/src/options/options.ts
@@ -95,14 +95,14 @@ function main() {
proxyUsherRequestsCheckboxElement.addEventListener("change", () => {
const checked = proxyUsherRequestsCheckboxElement.checked;
store.state.proxyUsherRequests = checked;
- if (isChromium && store.state.openedTwitchTabs.length > 0) {
+ if (isChromium && store.state.chromiumProxyActive) {
updateProxySettings();
}
});
proxyTwitchWebpageCheckboxElement.checked = store.state.proxyTwitchWebpage;
proxyTwitchWebpageCheckboxElement.addEventListener("change", () => {
store.state.proxyTwitchWebpage = proxyTwitchWebpageCheckboxElement.checked;
- if (isChromium && store.state.openedTwitchTabs.length > 0) {
+ if (isChromium && store.state.chromiumProxyActive) {
updateProxySettings();
}
});
@@ -154,7 +154,7 @@ function main() {
isAddAllowed: isNormalProxyUrlAllowed,
isEditAllowed: isNormalProxyUrlAllowed,
onEdit() {
- if (isChromium && store.state.openedTwitchTabs.length > 0) {
+ if (isChromium && store.state.chromiumProxyActive) {
updateProxySettings();
}
},
From fd76639aea3c337ee4708ab1698575648c0bb197 Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Thu, 5 Oct 2023 15:32:09 +0200
Subject: [PATCH 41/42] =?UTF-8?q?=F0=9F=92=A1=20Add=20clarifying=20comment?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/background/handlers/onTabUpdated.ts | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/background/handlers/onTabUpdated.ts b/src/background/handlers/onTabUpdated.ts
index cc7227a6..8d8e3e66 100644
--- a/src/background/handlers/onTabUpdated.ts
+++ b/src/background/handlers/onTabUpdated.ts
@@ -58,6 +58,9 @@ export default function onTabUpdated(
const allTabsAreWhitelisted = areAllTabsWhitelisted(
store.state.openedTwitchTabs
);
+ // We don't check for `store.state.openedTwitchTabs.length === 0` because
+ // there is always at least one tab open (the one that triggered this
+ // event).
if (!allTabsAreWhitelisted && !store.state.chromiumProxyActive) {
updateProxySettings();
} else if (allTabsAreWhitelisted && store.state.chromiumProxyActive) {
From 111f0cbf699dae7bb57a19b5cddac6a62e12497f Mon Sep 17 00:00:00 2001
From: younesaassila <47226184+younesaassila@users.noreply.github.com>
Date: Thu, 5 Oct 2023 15:52:42 +0200
Subject: [PATCH 42/42] =?UTF-8?q?=E2=9C=A8=20Add=20"Unset=20PAC=20script"?=
=?UTF-8?q?=20button?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/options/options.ts | 18 +++++++++++++++++-
src/options/page.html | 1 +
src/options/style.css | 1 +
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/options/options.ts b/src/options/options.ts
index dd723619..070281ad 100644
--- a/src/options/options.ts
+++ b/src/options/options.ts
@@ -2,7 +2,10 @@ import $ from "../common/ts/$";
import { readFile, saveFile } from "../common/ts/file";
import getProxyInfoFromUrl from "../common/ts/getProxyInfoFromUrl";
import isChromium from "../common/ts/isChromium";
-import { updateProxySettings } from "../common/ts/proxySettings";
+import {
+ clearProxySettings,
+ updateProxySettings,
+} from "../common/ts/proxySettings";
import sendAdLog from "../common/ts/sendAdLog";
import store from "../store";
import getDefaultState from "../store/getDefaultState";
@@ -71,6 +74,9 @@ const adLogClearButtonElement = $("#ad-log-clear-button") as HTMLButtonElement;
const exportButtonElement = $("#export-button") as HTMLButtonElement;
const importButtonElement = $("#import-button") as HTMLButtonElement;
const resetButtonElement = $("#reset-button") as HTMLButtonElement;
+const unsetPacScriptButtonElement = $(
+ "#unset-pac-script-button"
+) as HTMLButtonElement;
//#endregion
const DEFAULT_STATE = Object.freeze(getDefaultState());
@@ -170,6 +176,9 @@ function main() {
store.state.adLogEnabled = adLogEnabledCheckboxElement.checked;
});
}
+ if (!isChromium) {
+ unsetPacScriptButtonElement.style.display = "none";
+ }
}
function isOptimizedProxyUrlAllowed(url: string): AllowedResult {
@@ -503,3 +512,10 @@ resetButtonElement.addEventListener("click", () => {
store.clear();
window.location.reload(); // Reload page to update UI.
});
+
+unsetPacScriptButtonElement.addEventListener("click", () => {
+ if (isChromium) {
+ clearProxySettings();
+ alert("PAC script unset successfully.");
+ }
+});
diff --git a/src/options/page.html b/src/options/page.html
index c8b185b3..02e6183a 100644
--- a/src/options/page.html
+++ b/src/options/page.html
@@ -186,6 +186,7 @@