From 905c2f576447a8dad5cfe14bbdb09e623b9e023a Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Mon, 14 Sep 2020 21:29:13 +0200 Subject: [PATCH] Fix contentScript in background tab --- background.js | 47 ++++++++++++++++++++++++++-------------- bpc_count_daily_users.js | 2 +- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/background.js b/background.js index ae661c7..db2b183 100644 --- a/background.js +++ b/background.js @@ -47,6 +47,7 @@ var allow_cookies = [ 'intelligentinvestor.com.au', 'knack.be', 'lc.nl', +'lesechos.fr', 'lesoir.be', 'limesonline.com', 'lrb.co.uk', @@ -591,24 +592,38 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) { }); } - ext_api.tabs.query({ - active: true, - currentWindow: true - }, function (tabs) { - if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) { - if (isSiteEnabled({url: tabs[0].url}) || medium_custom_domain) { - // run contentScript inside tab - ext_api.tabs.executeScript({ - file: 'contentScript.js', - runAt: 'document_start' + if (tabId !== -1) { + ext_api.tabs.get(tabId, function (currentTab) { + if (isSiteEnabled(currentTab) || medium_custom_domain) { + ext_api.tabs.executeScript(tabId, { + file: 'contentScript.js', + runAt: 'document_start' }, function (res) { - if (ext_api.runtime.lastError || res[0]) { - return; - } - }); + if (ext_api.runtime.lastError || res[0]) { + return; + } + }); + } + }); + } else {//mercuriovalpo.cl + ext_api.tabs.query({ + active: true, + currentWindow: true + }, function (tabs) { + if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) { + if (isSiteEnabled({url: tabs[0].url}) || medium_custom_domain) { + ext_api.tabs.executeScript({ + file: 'contentScript.js', + runAt: 'document_start' + }, function (res) { + if (ext_api.runtime.lastError || res[0]) { + return; + } + }); + } } - } - }); + }); + } return { requestHeaders: requestHeaders }; }, { diff --git a/bpc_count_daily_users.js b/bpc_count_daily_users.js index 04e3338..67adde8 100644 --- a/bpc_count_daily_users.js +++ b/bpc_count_daily_users.js @@ -13,7 +13,7 @@ function bpc_count_daily_users(dateStr) { }, function () { true; }); - let count_json = 'https://bitbucket.org/magnolia1234/bpc-chrome-daily-users/downloads/bpc-daily-users-' + dateStr + '.json'; + let count_json = 'https://bitbucket.org/magnolia1234/bpc-firefox-daily-users/downloads/bpc-daily-users-' + dateStr + '.json'; fetch(count_json); } });