Fix contentScript in background tab

This commit is contained in:
magnolia1234 2020-09-14 21:29:13 +02:00
parent d89b03f1db
commit 905c2f5764
2 changed files with 32 additions and 17 deletions

View file

@ -47,6 +47,7 @@ var allow_cookies = [
'intelligentinvestor.com.au', 'intelligentinvestor.com.au',
'knack.be', 'knack.be',
'lc.nl', 'lc.nl',
'lesechos.fr',
'lesoir.be', 'lesoir.be',
'limesonline.com', 'limesonline.com',
'lrb.co.uk', 'lrb.co.uk',
@ -591,24 +592,38 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
}); });
} }
ext_api.tabs.query({ if (tabId !== -1) {
active: true, ext_api.tabs.get(tabId, function (currentTab) {
currentWindow: true if (isSiteEnabled(currentTab) || medium_custom_domain) {
}, function (tabs) { ext_api.tabs.executeScript(tabId, {
if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) { file: 'contentScript.js',
if (isSiteEnabled({url: tabs[0].url}) || medium_custom_domain) { runAt: 'document_start'
// run contentScript inside tab
ext_api.tabs.executeScript({
file: 'contentScript.js',
runAt: 'document_start'
}, function (res) { }, function (res) {
if (ext_api.runtime.lastError || res[0]) { if (ext_api.runtime.lastError || res[0]) {
return; 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 }; return { requestHeaders: requestHeaders };
}, { }, {

View file

@ -13,7 +13,7 @@ function bpc_count_daily_users(dateStr) {
}, function () { }, function () {
true; 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); fetch(count_json);
} }
}); });