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