Update daily users counter (on page)
This commit is contained in:
parent
8e4a7a1c82
commit
1ca5876066
@ -461,6 +461,14 @@ 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 = '';
|
||||
|
@ -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);
|
||||
|
@ -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": {
|
||||
|
@ -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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user