mirror of
https://github.com/younesaassila/ttv-lol-pro.git
synced 2025-04-29 14:04:26 +02:00
Fix review comments
This commit is contained in:
parent
9f45b77b83
commit
6fcae2eea1
@ -6,6 +6,6 @@ export default function isChannelWhitelisted(
|
||||
if (!channelName) return false;
|
||||
const channelNameLower = channelName.toLowerCase();
|
||||
return store.state.whitelistedChannels.some(
|
||||
c => c.toLowerCase() === channelNameLower
|
||||
channel => channel.toLowerCase() === channelNameLower
|
||||
);
|
||||
}
|
||||
|
@ -145,43 +145,47 @@ function onPageMessage(event: MessageEvent) {
|
||||
}
|
||||
// ---
|
||||
else if (message.type === MessageType.ChannelSubStatusChange) {
|
||||
const { channelName, wasSubscribed, isSubscribed } = message;
|
||||
const isWhitelisted = isChannelWhitelisted(channelName);
|
||||
const { channelNameLower, wasSubscribed, isSubscribed } = message;
|
||||
const isWhitelisted = isChannelWhitelisted(channelNameLower);
|
||||
console.log("[TTV LOL PRO] ChannelSubStatusChange", {
|
||||
channelName,
|
||||
channelNameLower,
|
||||
wasSubscribed,
|
||||
isSubscribed,
|
||||
isWhitelisted,
|
||||
});
|
||||
const currentChannelName = findChannelFromTwitchTvUrl(location.href);
|
||||
if (store.state.whitelistChannelSubscriptions && channelName != null) {
|
||||
const currentChannelNameLower = findChannelFromTwitchTvUrl(
|
||||
location.href
|
||||
)?.toLowerCase();
|
||||
if (store.state.whitelistChannelSubscriptions && channelNameLower != null) {
|
||||
if (!wasSubscribed && isSubscribed) {
|
||||
store.state.activeChannelSubscriptions.push(channelName);
|
||||
store.state.activeChannelSubscriptions.push(channelNameLower);
|
||||
// Add to whitelist.
|
||||
if (!isWhitelisted) {
|
||||
console.log(`[TTV LOL PRO] Adding '${channelName}' to whitelist.`);
|
||||
store.state.whitelistedChannels.push(channelName);
|
||||
}
|
||||
if (channelName === currentChannelName) {
|
||||
location.reload();
|
||||
console.log(
|
||||
`[TTV LOL PRO] Adding '${channelNameLower}' to whitelist.`
|
||||
);
|
||||
store.state.whitelistedChannels.push(channelNameLower);
|
||||
if (channelNameLower === currentChannelNameLower) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
} else if (wasSubscribed && !isSubscribed) {
|
||||
store.state.activeChannelSubscriptions =
|
||||
store.state.activeChannelSubscriptions.filter(
|
||||
c => c.toLowerCase() !== channelName.toLowerCase()
|
||||
channel => channel.toLowerCase() !== channelNameLower
|
||||
);
|
||||
// Remove from whitelist.
|
||||
if (isWhitelisted) {
|
||||
console.log(
|
||||
`[TTV LOL PRO] Removing '${channelName}' from whitelist.`
|
||||
`[TTV LOL PRO] Removing '${channelNameLower}' from whitelist.`
|
||||
);
|
||||
store.state.whitelistedChannels =
|
||||
store.state.whitelistedChannels.filter(
|
||||
c => c.toLowerCase() !== channelName.toLowerCase()
|
||||
channel => channel.toLowerCase() !== channelNameLower
|
||||
);
|
||||
}
|
||||
if (channelName === currentChannelName) {
|
||||
location.reload();
|
||||
if (channelNameLower === currentChannelNameLower) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,9 @@ export function getFetch(pageState: PageState): typeof fetch {
|
||||
if (!message.channelName) break;
|
||||
const channelNameLower = message.channelName.toLowerCase();
|
||||
for (let i = 0; i < usherManifests.length; i++) {
|
||||
if (usherManifests[i].channelName === channelNameLower) {
|
||||
if (
|
||||
usherManifests[i].channelName?.toLowerCase() === channelNameLower
|
||||
) {
|
||||
usherManifests[i].deleted = true;
|
||||
}
|
||||
}
|
||||
@ -406,6 +408,8 @@ export function getFetch(pageState: PageState): typeof fetch {
|
||||
twitchGqlHostRegex.test(host) &&
|
||||
response.status < 400
|
||||
) {
|
||||
await waitForStore(pageState);
|
||||
if (!pageState.state?.whitelistChannelSubscriptions) break graphqlRes;
|
||||
responseBody ??= await readResponseBody();
|
||||
// Preliminary check to avoid parsing the response body if possible.
|
||||
if (
|
||||
@ -442,16 +446,16 @@ export function getFetch(pageState: PageState): typeof fetch {
|
||||
channelName = body.data.user.login;
|
||||
isSubscribed = body.data.user.self.subscriptionBenefit != null;
|
||||
}
|
||||
if (!channelName) break graphqlRes;
|
||||
const isLivestream = !/^\d+$/.test(channelName); // VODs have numeric IDs.
|
||||
if (!isLivestream) break graphqlRes;
|
||||
await waitForStore(pageState);
|
||||
const wasSubscribed = wasChannelSubscriber(channelName, pageState);
|
||||
const hasSubStatusChanged =
|
||||
(wasSubscribed && !isSubscribed) || (!wasSubscribed && isSubscribed);
|
||||
if (hasSubStatusChanged) {
|
||||
pageState.sendMessageToContentScript({
|
||||
type: MessageType.ChannelSubStatusChange,
|
||||
channelName,
|
||||
channelNameLower: channelName.toLowerCase(),
|
||||
wasSubscribed,
|
||||
isSubscribed,
|
||||
});
|
||||
@ -682,7 +686,7 @@ function isChannelWhitelisted(
|
||||
const channelNameLower = channelName.toLowerCase();
|
||||
return (
|
||||
pageState.state?.whitelistedChannels.some(
|
||||
c => c.toLowerCase() === channelNameLower
|
||||
channel => channel.toLowerCase() === channelNameLower
|
||||
) ?? false
|
||||
);
|
||||
}
|
||||
@ -695,7 +699,7 @@ function wasChannelSubscriber(
|
||||
const channelNameLower = channelName.toLowerCase();
|
||||
return (
|
||||
pageState.state?.activeChannelSubscriptions.some(
|
||||
c => c.toLowerCase() === channelNameLower
|
||||
channel => channel.toLowerCase() === channelNameLower
|
||||
) ?? false
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user