Update daily users counter (on page)

This commit is contained in:
magnolia1234 2020-09-11 16:52:50 +02:00
parent 9106319801
commit d60adee60e
4 changed files with 24 additions and 11 deletions

View file

@ -461,14 +461,22 @@ if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'
extraInfoSpec.push('extraHeaders');
ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
if (details.type === 'main_frame') {
let current_date_str = currentDateStr();
if (last_date_str < current_date_str) {
bpc_count_daily_users(current_date_str);
last_date_str = current_date_str;
}
}
var requestHeaders = details.requestHeaders;
var header_referer = '';
for (var n in requestHeaders) {
if (requestHeaders[n].name.toLowerCase() == 'referer') {
header_referer = requestHeaders[n].value;
continue;
}
if (requestHeaders[n].name.toLowerCase() == 'referer') {
header_referer = requestHeaders[n].value;
continue;
}
}
// fix brave browser
if (!details.originUrl && !header_referer.includes(details.initiator))

View file

@ -1,9 +1,7 @@
var ext_api = (typeof browser === 'object') ? browser : chrome;
// daily users counter
function bpc_count_daily_users() {
let date = new Date();
let dateStr = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().split("T")[0];
function bpc_count_daily_users(dateStr) {
ext_api.storage.sync.get({
daily_users: {},
}, function (items) {
@ -15,9 +13,16 @@ function bpc_count_daily_users() {
}, function () {
true;
});
let count_json = 'https://bitbucket.org/magnolia1234/bpc-firefox-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
let count_json = 'https://bitbucket.org/magnolia1234/bpc-chrome-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
fetch(count_json);
}
});
}
bpc_count_daily_users();
function currentDateStr() {
let date = new Date();
let dateStr = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().split("T")[0];
return dateStr;
}
var last_date_str = currentDateStr();
bpc_count_daily_users(last_date_str);

View file

@ -1,6 +1,6 @@
{
"background": {
"scripts": ["sites.js", "background.js", "bpc_count_daily_users.js"]
"scripts": ["sites.js", "bpc_count_daily_users.js", "background.js"]
},
"content_security_policy": "script-src 'self'; object-src 'self'",
"applications": {

View file

@ -1,6 +1,6 @@
{
"background": {
"scripts": ["sites.js", "background.js", "bpc_count_daily_users.js"]
"scripts": ["sites.js", "bpc_count_daily_users.js", "background.js"]
},
"content_security_policy": "script-src 'self'; object-src 'self'",
"applications": {