2020-09-06 07:00:36 +00:00
|
|
|
var ext_api = (typeof browser === 'object') ? browser : chrome;
|
|
|
|
|
|
|
|
// daily users counter
|
2020-09-11 14:52:50 +00:00
|
|
|
function bpc_count_daily_users(dateStr) {
|
2021-12-14 16:23:40 +00:00
|
|
|
ext_api.storage.local.get({
|
|
|
|
daily_users: {},
|
|
|
|
}, function (items_local) {
|
|
|
|
daily_users = items_local.daily_users;
|
|
|
|
if (daily_users.date !== dateStr) {
|
|
|
|
daily_users.date = dateStr;
|
|
|
|
ext_api.storage.local.set({
|
|
|
|
daily_users: daily_users
|
|
|
|
}, function () {
|
|
|
|
true;
|
|
|
|
});
|
|
|
|
let count_json = 'https://bitbucket.org/bpc_redux/bpc-firefox-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
|
|
|
|
try {
|
|
|
|
fetch(count_json, {mode: 'no-cors'});
|
|
|
|
let count_mobile_json = 'https://bitbucket.org/bpc_redux/bpc-firefox-mobile-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
|
|
|
|
let count_desktop_json = 'https://bitbucket.org/bpc_redux/bpc-firefox-desktop-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
|
|
|
|
if (window.navigator && window.navigator.userAgent.match(/(mobile|android)/i))
|
|
|
|
fetch(count_mobile_json, {mode: 'no-cors'});
|
|
|
|
else
|
|
|
|
fetch(count_desktop_json, {mode: 'no-cors'});
|
|
|
|
} catch (err) {
|
|
|
|
false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-09-06 07:00:36 +00:00
|
|
|
}
|
2020-09-11 14:52:50 +00:00
|
|
|
|
|
|
|
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();
|
2020-10-31 19:06:38 +00:00
|
|
|
var daily_users;
|
2021-10-01 12:37:21 +00:00
|
|
|
ext_api.storage.local.get({counter: true}, function (result) {
|
|
|
|
if (result.counter)
|
|
|
|
bpc_count_daily_users(last_date_str);
|
|
|
|
});
|