Update daily users counter (on page)

This commit is contained in:
magnolia1234 2020-09-11 16:52:16 +02:00
parent 8e4a7a1c82
commit 1ca5876066
4 changed files with 23 additions and 10 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) {
@ -20,4 +18,11 @@ function bpc_count_daily_users() {
}
});
}
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'",
"browser_action": {

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'",
"browser_action": {