diff --git a/core/constants.js b/core/constants.js index ee703d55..668a0cfe 100644 --- a/core/constants.js +++ b/core/constants.js @@ -77,6 +77,7 @@ const Setting = { 'SELECTED_ICON': 'selectedIcon', 'INTERNAL_STATISTICS': 'internalStatistics', 'INTERNAL_STATISTICS_DATA': 'internalStatisticsData', + 'DEFAULT_RANGE_STATISTIC': 'defaultRangeStatistic', 'ALLOWED_DOMAINS_GOOGLE_FONTS': 'allowedDomainsGoogleFonts', 'STORAGE_TYPE': 'storageType', 'BADGE_COLOR': 'badgeColor', @@ -96,6 +97,7 @@ const SettingDefaults = { [Setting.UPDATE_NOTIFICATION]: 0, [Setting.INTERNAL_STATISTICS]: false, [Setting.INTERNAL_STATISTICS_DATA]: {}, + [Setting.DEFAULT_RANGE_STATISTIC]: 'week', [Setting.LAST_MAPPING_UPDATE]: '2020-01-01', [Setting.NEGATE_HTML_FILTER_LIST]: false, [Setting.SELECTED_ICON]: 'Default', diff --git a/pages/statistics/statistics.js b/pages/statistics/statistics.js index b45b02c2..169e8628 100644 --- a/pages/statistics/statistics.js +++ b/pages/statistics/statistics.js @@ -30,12 +30,13 @@ statistics._onDocumentLoaded = function () { helpers.insertI18nContentIntoDocument(document); helpers.insertI18nTitlesIntoDocument(document); - // Default view is 'today' - statistics._dateRange = [new Date().toISOString().slice(0, 10)]; - document.getElementById('date-range').value = statistics._dateUnit; - - statistics._registerListener(); - statistics._getStatistics().then(statistics._renderContents); + chrome.storage.local.get([Setting.DEFAULT_RANGE_STATISTIC], function (items) { + document.getElementById('date-range').value = items.defaultRangeStatistic; + statistics._dateUnit = items.defaultRangeStatistic; + statistics._setDateRange(items.defaultRangeStatistic); + statistics._registerListener(); + statistics._getStatistics().then(statistics._renderContents); + }); }; statistics._renderContents = function () { @@ -229,6 +230,7 @@ statistics._handlerDateRange = function ({target}) { let type = target.value; if (type === 'day' || type === 'week' || type === 'month' || type === 'year') { statistics._dateUnit = type; + statistics._saveDefaultRange(type); } else if (type === 'delete') { statistics._deleteStatistic(); } @@ -245,6 +247,12 @@ statistics._deleteStatistic = function () { } }; +statistics._saveDefaultRange = function (value) { + chrome.storage.local.set({ + [Setting.DEFAULT_RANGE_STATISTIC]: value + }); +}; + statistics._registerListener = function () { document.getElementById('date-range').addEventListener('change', statistics._handlerDateRange); document.getElementById('btn-delete').addEventListener('click', function () { @@ -262,6 +270,6 @@ statistics._dataSortedCDNs = {}; statistics._dataSortedFrameworks = {}; statistics._dataOverview = []; statistics._dateRange = []; -statistics._dateUnit = 'day'; +statistics._dateUnit = 'week'; document.addEventListener('DOMContentLoaded', statistics._onDocumentLoaded); diff --git a/pages/updates/updates.html b/pages/updates/updates.html index 96ea1205..51581574 100644 --- a/pages/updates/updates.html +++ b/pages/updates/updates.html @@ -47,6 +47,7 @@
  • Added: jQuery v3.6.0 (#297)
  • Updated: angular-translate v2.7.2 -> v2.18.4 (#298)
  • Added: Bulma v0.9.2 (#299)
  • +
  • Implemented: "Week" as the default in statistics. Save last period. (#300)