2020-08-08 07:27:52 +02:00
|
|
|
/**
|
|
|
|
* Stats
|
|
|
|
* Belongs to LocalCDN (since 2020-02-26)
|
|
|
|
* (Origin: Decentraleyes)
|
|
|
|
*
|
|
|
|
* @author nobody
|
|
|
|
* @since 2020-02-26
|
|
|
|
*
|
|
|
|
* @license MPL 2.0
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2020-08-13 08:07:04 +02:00
|
|
|
'use strict';
|
2020-08-08 07:27:52 +02:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-08-08 07:27:52 +02:00
|
|
|
/**
|
|
|
|
* Stats
|
|
|
|
*/
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2024-04-28 07:18:40 +02:00
|
|
|
let stats = {};
|
2020-08-08 07:27:52 +02:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Public Methods
|
|
|
|
*/
|
|
|
|
|
2020-08-08 07:27:52 +02:00
|
|
|
stats.setStats = function (injection) {
|
2020-10-25 00:09:15 +02:00
|
|
|
let data, today, cdn, framework, newEntry, pathSegments;
|
2020-08-08 07:27:52 +02:00
|
|
|
|
2020-09-08 20:50:54 +02:00
|
|
|
data = storageManager.statistics;
|
2020-08-08 07:27:52 +02:00
|
|
|
today = new Date().toISOString().slice(0, 10);
|
|
|
|
cdn = injection.source;
|
2020-10-25 00:09:15 +02:00
|
|
|
|
|
|
|
if (injection.bundle !== '') {
|
|
|
|
pathSegments = injection.path.split('/');
|
2021-02-17 07:01:08 +01:00
|
|
|
framework = `${pathSegments[0]}/${pathSegments[1]}/${pathSegments[2]}/`;
|
2020-10-25 00:09:15 +02:00
|
|
|
} else {
|
|
|
|
framework = injection.path;
|
|
|
|
}
|
2020-08-08 07:27:52 +02:00
|
|
|
|
|
|
|
if (today in data) {
|
2020-08-13 08:07:04 +02:00
|
|
|
if (cdn in data[today]['cdns']) {
|
|
|
|
data[today]['cdns'][cdn] = ++data[today]['cdns'][cdn];
|
2020-08-08 07:27:52 +02:00
|
|
|
} else {
|
2021-02-17 07:01:08 +01:00
|
|
|
Object.assign(data[today]['cdns'], {[cdn]: 1});
|
2020-08-08 07:27:52 +02:00
|
|
|
}
|
2020-08-13 08:07:04 +02:00
|
|
|
if (framework in data[today]['frameworks']) {
|
|
|
|
data[today]['frameworks'][framework] = ++data[today]['frameworks'][framework];
|
2020-08-08 07:27:52 +02:00
|
|
|
} else {
|
2021-02-17 07:01:08 +01:00
|
|
|
Object.assign(data[today]['frameworks'], {[framework]: 1});
|
2020-08-08 07:27:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
2021-02-17 07:01:08 +01:00
|
|
|
newEntry = {'frameworks': {[framework]: 1}, 'cdns': {[cdn]: 1}};
|
2020-08-08 07:27:52 +02:00
|
|
|
data[today] = newEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
chrome.storage.local.set({
|
|
|
|
[Setting.INTERNAL_STATISTICS_DATA]: data,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
stats.getStats = function () {
|
|
|
|
chrome.storage.local.get([Setting.INTERNAL_STATISTICS_DATA], function (items) {
|
2020-09-08 20:50:54 +02:00
|
|
|
storageManager.statistics = items.internalStatisticsData || {};
|
2020-08-08 07:27:52 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
stats.getStats();
|