Skip to content

Commit 0e4061e

Browse files
committed
fix: figure out channel id in content script instead of background
1 parent 190a149 commit 0e4061e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/background/browserAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ browser.tabs.onRemoved.addListener((tabId) => {
185185
const onContentScriptMessage = async (message, sender) => {
186186
if (sender.id === browser.runtime.id) {
187187
if (message.type === 'add_points') {
188-
const channelId = new URL(sender.url).pathname.split('/').pop();
188+
const channelId = message.channelId;
189189
const pointsCollectedForChannel = extension.getChannelPoints(channelId);
190190
const updatedAmount = pointsCollectedForChannel + message.bonus;
191191
extension.setChannelPoints(channelId, updatedAmount);

src/contentScripts/worker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ function tryToGetReceivedPoints() {
5757
if (bonusAmount) {
5858
// slice to remove + at the beginning
5959
const bonusAmountInt = parseInt(bonusAmount.slice(1), 10);
60+
const channelId = document.querySelector('.tw-halo')?.getAttribute('href').split('/').pop();
6061
browser.runtime.sendMessage({
6162
type: 'add_points',
62-
bonus: bonusAmountInt
63+
bonus: bonusAmountInt,
64+
channelId
6365
});
6466

6567
clearInterval(pointsInterval);

0 commit comments

Comments
 (0)