Update daily users counter (on page)
This commit is contained in:
parent
8e4a7a1c82
commit
1ca5876066
@ -461,14 +461,22 @@ if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'
|
|||||||
extraInfoSpec.push('extraHeaders');
|
extraInfoSpec.push('extraHeaders');
|
||||||
|
|
||||||
ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
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 requestHeaders = details.requestHeaders;
|
||||||
|
|
||||||
var header_referer = '';
|
var header_referer = '';
|
||||||
for (var n in requestHeaders) {
|
for (var n in requestHeaders) {
|
||||||
if (requestHeaders[n].name.toLowerCase() == 'referer') {
|
if (requestHeaders[n].name.toLowerCase() == 'referer') {
|
||||||
header_referer = requestHeaders[n].value;
|
header_referer = requestHeaders[n].value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fix brave browser
|
// fix brave browser
|
||||||
if (!details.originUrl && !header_referer.includes(details.initiator))
|
if (!details.originUrl && !header_referer.includes(details.initiator))
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
var ext_api = (typeof browser === 'object') ? browser : chrome;
|
var ext_api = (typeof browser === 'object') ? browser : chrome;
|
||||||
|
|
||||||
// daily users counter
|
// daily users counter
|
||||||
function bpc_count_daily_users() {
|
function bpc_count_daily_users(dateStr) {
|
||||||
let date = new Date();
|
|
||||||
let dateStr = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().split("T")[0];
|
|
||||||
ext_api.storage.sync.get({
|
ext_api.storage.sync.get({
|
||||||
daily_users: {},
|
daily_users: {},
|
||||||
}, function (items) {
|
}, 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": {
|
"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'",
|
"content_security_policy": "script-src 'self'; object-src 'self'",
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"background": {
|
"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'",
|
"content_security_policy": "script-src 'self'; object-src 'self'",
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user