2020-09-06 09:00:36 +02:00
|
|
|
var ext_api = (typeof browser === 'object') ? browser : chrome;
|
2024-01-10 08:54:04 +01:00
|
|
|
var manifestData = ext_api.runtime.getManifest();
|
|
|
|
var url_loc = manifestData.key ? 'chrome' : 'firefox';
|
2020-09-06 09:00:36 +02:00
|
|
|
|
|
|
|
// daily users counter
|
2020-09-11 16:52:50 +02:00
|
|
|
function bpc_count_daily_users(dateStr) {
|
2021-12-14 17:23:40 +01: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;
|
|
|
|
});
|
2023-02-11 09:20:49 +01:00
|
|
|
let count_json = 'https://bitbucket.org/bpc_redux/bpc-' + url_loc + '-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
|
2021-12-14 17:23:40 +01:00
|
|
|
try {
|
|
|
|
fetch(count_json, {mode: 'no-cors'});
|
2023-02-11 09:20:49 +01:00
|
|
|
let count_mobile_json = 'https://bitbucket.org/bpc_redux/bpc-' + url_loc + '-mobile-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
|
|
|
|
let count_desktop_json = 'https://bitbucket.org/bpc_redux/bpc-' + url_loc + '-desktop-daily-users/downloads/bpc-daily-users-' + dateStr + '.json';
|
2021-12-14 17:23:40 +01:00
|
|
|
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 09:00:36 +02:00
|
|
|
}
|
2020-09-11 16:52:50 +02: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 20:06:38 +01:00
|
|
|
var daily_users;
|
2023-05-08 20:05:06 +02:00
|
|
|
ext_api.storage.local.get({counter: true}, function (result) {
|
|
|
|
if (result.counter)
|
|
|
|
bpc_count_daily_users(last_date_str);
|
|
|
|
});
|
|
|
|
|