Skip to content

Commit 69f67be

Browse files
committed
fix: lookup gained points if clicked after disabled state. Reduce throttle time window
1 parent 44c5be2 commit 69f67be

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/background/browserAction.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ const iconsDisabled = {
2121
}
2222

2323
const twitchUrlRegexp = /^https:\/\/www.twitch.tv\/*/;
24-
const TEN_MINUTES_MS = 10 * 60 * 1000;
24+
const TEN_SECONDS_MS = 10 * 1000;
2525

2626
const throttledSetPoints = (setChannelPointsFn) => {
2727
const calls = {};
2828
return async (channelId, points) => {
2929
if (!calls[channelId]) {
30-
calls[channelId] = Date.now() - TEN_MINUTES_MS - 1;
30+
calls[channelId] = Date.now() - TEN_SECONDS_MS - 1;
3131
}
3232

3333
const now = Date.now();
3434
const lastTime = calls[channelId];
3535

36-
if (now - lastTime >= TEN_MINUTES_MS) {
36+
if (now - lastTime >= TEN_SECONDS_MS) {
3737
calls[channelId] = now;
3838
return setChannelPointsFn(channelId, points);
3939
}
@@ -82,7 +82,7 @@ const Extension = () => {
8282
};
8383

8484
const updateBadgeForChannel = async ({ channelId, tabId }) => {
85-
const points = state.channelPoints[channelId] || 0;
85+
const points = getChannelPoints(channelId);
8686
if (tabId) {
8787
browser.browserAction.setBadgeText({
8888
text: String(points),
@@ -131,6 +131,7 @@ const Extension = () => {
131131
setEnabled: async (value) => {
132132
await browser.storage.local.set({ isEnabled: value });
133133
await updateTab({ isEnabled: value });
134+
updateExtensionIcon(value);
134135
state.isEnabled = value;
135136
}
136137
}
@@ -184,9 +185,8 @@ browser.tabs.onRemoved.addListener((tabId) => {
184185
const onContentScriptMessage = async (message, sender) => {
185186
if (sender.id === browser.runtime.id) {
186187
if (message.type === 'add_points') {
187-
const currentState = await browser.storage.local.get();
188188
const channelId = new URL(sender.url).pathname.split('/').pop();
189-
const pointsCollectedForChannel = currentState[channelId] || 0;
189+
const pointsCollectedForChannel = extension.getChannelPoints(channelId);
190190
const updatedAmount = pointsCollectedForChannel + message.bonus;
191191
extension.setChannelPoints(channelId, updatedAmount);
192192
}

src/contentScripts/worker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ function initialize() {
113113
clearTimeout(timeout);
114114

115115
// initial check for the button
116-
attemptToClick();
116+
const clicked = attemptToClick();
117+
if (clicked) {
118+
tryToGetReceivedPoints();
119+
}
117120

118121
if (isLive()) {
119122
waitForBonusButton();

0 commit comments

Comments
 (0)