Skip to content

Commit

Permalink
🔖 Release version 2.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
younesaassila authored Feb 3, 2024
2 parents ee37296 + b116523 commit 4df5ca8
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 40 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ttv-lol-pro",
"version": "2.3.3",
"version": "2.3.4",
"description": "TTV LOL PRO removes most livestream ads from Twitch.",
"@parcel/bundler-default": {
"minBundles": 10000000,
Expand Down
20 changes: 10 additions & 10 deletions src/background/handlers/onContentScriptMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { MessageType, ProxyRequestType } from "../../types";
type Timeout = string | number | NodeJS.Timeout | undefined;

const timeoutMap: Map<ProxyRequestType, Timeout> = new Map();
const fetchTimeoutMsOverride: Map<ProxyRequestType, number> = new Map([
[ProxyRequestType.Usher, 7000], // Account for slow page load.
]);

export default function onContentScriptMessage(
message: any,
Expand All @@ -23,13 +26,15 @@ export default function onContentScriptMessage(
}

// Set new timeout for request type.
const fetchTimeoutMs = 3000; // Time for fetch to be called.
const fetchTimeoutMs = fetchTimeoutMsOverride.has(requestType)
? fetchTimeoutMsOverride.get(requestType)!
: 3000; // Time for fetch to be called.
const replyTimeoutMs = Date.now() - message.timestamp; // Time for reply to be received.
timeoutMap.set(
requestType,
setTimeout(() => {
console.log(
`[TTV LOL PRO] Disabling full mode (request type: ${requestType}, timeout)`
`🔴 Disabled full mode (request type: ${requestType}, timeout)`
);
timeoutMap.delete(requestType);
if (store.state.chromiumProxyActive) {
Expand All @@ -42,7 +47,7 @@ export default function onContentScriptMessage(
}

console.log(
`[TTV LOL PRO] Enabled full mode for ${
`🟢 Enabled full mode for ${
fetchTimeoutMs + replyTimeoutMs
}ms (request type: ${requestType})`
);
Expand All @@ -51,10 +56,7 @@ export default function onContentScriptMessage(
type: MessageType.EnableFullModeResponse,
});
} catch (error) {
console.error(
"[TTV LOL PRO] Failed to send EnableFullModeResponse message",
error
);
console.error("❌ Failed to send EnableFullModeResponse message", error);
}
}

Expand All @@ -68,8 +70,6 @@ export default function onContentScriptMessage(
if (store.state.chromiumProxyActive) {
updateProxySettings([...timeoutMap.keys()]);
}
console.log(
`[TTV LOL PRO] Disabled full mode (request type: ${requestType})`
);
console.log(`🔴 Disabled full mode (request type: ${requestType})`);
}
}
4 changes: 2 additions & 2 deletions src/common/ts/findChannelFromTwitchTvUrl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { twitchChannelNameRegex } from "./regexes";

/**
* Returns the channel name from a Twitch.tv URL.
* Returns the channel name from a Twitch.tv URL in lowercase.
* Returns `null` if the URL is not a valid Twitch.tv URL.
* @param twitchTvUrl
* @returns
Expand All @@ -13,5 +13,5 @@ export default function findChannelFromTwitchTvUrl(
const match = twitchChannelNameRegex.exec(twitchTvUrl);
if (!match) return null;
const [, channelName] = match;
return channelName;
return channelName.toLowerCase();
}
9 changes: 8 additions & 1 deletion src/common/ts/updateDnsResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export default async function updateDnsResponses() {
}

try {
const response = await fetch(`https://dns.google/resolve?name=${host}`);
const response = await fetch(
`https://cloudflare-dns.com/dns-query?name=${host}`,
{
headers: {
Accept: "application/dns-json",
},
}
);
const json = await response.json();
const { Answer } = json;
if (!Array.isArray(Answer)) {
Expand Down
19 changes: 8 additions & 11 deletions src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,22 @@ function injectPageScript() {

function onStoreLoad() {
// Clear stats for stream on page load/reload.
clearStats();
const channelName = findChannelFromTwitchTvUrl(location.href);
clearStats(channelName);
}

/**
* Clear stats for stream on page load/reload.
* @returns
*/
function clearStats() {
const channelName = findChannelFromTwitchTvUrl(location.href);
function clearStats(channelName: string | null) {
if (!channelName) return;

if (store.state.streamStatuses.hasOwnProperty(channelName)) {
setStreamStatus(channelName, {
proxied: false,
reason: "",
});
const channelNameLower = channelName.toLowerCase();
if (store.state.streamStatuses.hasOwnProperty(channelNameLower)) {
delete store.state.streamStatuses[channelNameLower];
}
console.log(
`[TTV LOL PRO] Cleared stats for channel '${channelName}' (content script).`
`[TTV LOL PRO] Cleared stats for channel '${channelNameLower}' (content script).`
);
}

Expand Down Expand Up @@ -154,7 +151,7 @@ function onPageMessage(event: MessageEvent) {
});
break;
case MessageType.ClearStats:
clearStats();
clearStats(message.channelName);
break;
}
}
2 changes: 1 addition & 1 deletion src/manifest.chromium.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "TTV LOL PRO",
"description": "TTV LOL PRO removes most livestream ads from Twitch.",
"homepage_url": "https://github.com/younesaassila/ttv-lol-pro",
"version": "2.3.3",
"version": "2.3.4",
"background": {
"service_worker": "background/background.ts",
"type": "module"
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "TTV LOL PRO",
"description": "TTV LOL PRO removes most livestream ads from Twitch.",
"homepage_url": "https://github.com/younesaassila/ttv-lol-pro",
"version": "2.3.3",
"version": "2.3.4",
"background": {
"scripts": ["background/background.ts"],
"persistent": false
Expand Down
10 changes: 10 additions & 0 deletions src/options/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ <h1 class="title">Options</h1>
<!-- Passport -->
<section id="passport" class="section">
<h2>Passport</h2>
<small>
Controls which types of requests are proxied. Increase the slider
<b>only if you are seeing ads</b> with the current setting.
</small>
<br />
<small>
If you are seeing "Commercial break in progress" ads, increasing the
slider will not help.
</small>
<br />
<div id="passport-level-container">
<img
src="../common/images/passport.png"
Expand Down
15 changes: 11 additions & 4 deletions src/page/getFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ export function getFetch(pageState: PageState): typeof fetch {
switch (message.type) {
case MessageType.ClearStats:
console.log("[TTV LOL PRO] Cleared stats (getFetch).");
usherManifests = [];
cachedPlaybackTokenRequestHeaders = null;
cachedPlaybackTokenRequestBody = null;
cachedUsherRequestUrl = null;
const channelNameLower = message.channelName.toLowerCase();
usherManifests = usherManifests.filter(
manifest => manifest.channelName !== channelNameLower
);
if (cachedPlaybackTokenRequestBody?.includes(channelNameLower)) {
cachedPlaybackTokenRequestHeaders = null;
cachedPlaybackTokenRequestBody = null;
}
if (cachedUsherRequestUrl?.includes(channelNameLower)) {
cachedUsherRequestUrl = null;
}
break;
}
});
Expand Down
26 changes: 19 additions & 7 deletions src/page/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ window.addEventListener("message", event => {
}
});

function onChannelChange(callback: (channelName: string) => void) {
function onChannelChange(
callback: (channelName: string, oldChannelName: string | null) => void
) {
let channelName: string | null = findChannelFromTwitchTvUrl(location.href);

const NATIVE_PUSH_STATE = window.history.pushState;
Expand All @@ -161,8 +163,9 @@ function onChannelChange(callback: (channelName: string) => void) {
const fullUrl = toAbsoluteUrl(url.toString());
const newChannelName = findChannelFromTwitchTvUrl(fullUrl);
if (newChannelName != null && newChannelName !== channelName) {
const oldChannelName = channelName;
channelName = newChannelName;
callback(channelName);
callback(channelName, oldChannelName);
}
return NATIVE_PUSH_STATE.call(window.history, data, unused, url);
}
Expand All @@ -178,8 +181,9 @@ function onChannelChange(callback: (channelName: string) => void) {
const fullUrl = toAbsoluteUrl(url.toString());
const newChannelName = findChannelFromTwitchTvUrl(fullUrl);
if (newChannelName != null && newChannelName !== channelName) {
const oldChannelName = channelName;
channelName = newChannelName;
callback(channelName);
callback(channelName, oldChannelName);
}
return NATIVE_REPLACE_STATE.call(window.history, data, unused, url);
}
Expand All @@ -188,17 +192,25 @@ function onChannelChange(callback: (channelName: string) => void) {
window.addEventListener("popstate", () => {
const newChannelName = findChannelFromTwitchTvUrl(location.href);
if (newChannelName != null && newChannelName !== channelName) {
const oldChannelName = channelName;
channelName = newChannelName;
callback(channelName);
callback(channelName, oldChannelName);
}
});
}

onChannelChange(() => {
sendMessageToContentScript({ type: MessageType.ClearStats });
sendMessageToPageScript({ type: MessageType.ClearStats });
onChannelChange((channelName, oldChannelName) => {
sendMessageToContentScript({
type: MessageType.ClearStats,
channelName: oldChannelName,
});
sendMessageToPageScript({
type: MessageType.ClearStats,
channelName: oldChannelName,
});
sendMessageToWorkerScript(pageState.twitchWorker, {
type: MessageType.ClearStats,
channelName: oldChannelName,
});
});

Expand Down
5 changes: 5 additions & 0 deletions src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { alpha2 } from "../common/ts/countryCodes";
import findChannelFromTwitchTvUrl from "../common/ts/findChannelFromTwitchTvUrl";
import isChannelWhitelisted from "../common/ts/isChannelWhitelisted";
import isChromium from "../common/ts/isChromium";
import store from "../store";
import type { StreamStatus } from "../types";

Expand Down Expand Up @@ -183,6 +184,7 @@ copyDebugInfoButtonElement.addEventListener("click", async e => {
channelNameLower != null
? store.state.streamStatuses[channelNameLower]
: null;
const proxySettings = await browser.proxy.settings.get({});

const debugInfo = [
`**Debug Info**\n`,
Expand Down Expand Up @@ -221,6 +223,9 @@ copyDebugInfoButtonElement.addEventListener("click", async e => {
`- Country: ${status.proxyCountry ?? "N/A"}\n`,
].join("")
: "",
isChromium
? `Proxy level of control: ${proxySettings.levelOfControl}\n`
: "",
].join("")
: "",
store.state.adLog.length > 0
Expand Down

0 comments on commit 4df5ca8

Please sign in to comment.