From 4d4e9a063e89bedca83ff506164005a15c54d2f8 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Tue, 23 Jun 2020 21:02:46 +0800 Subject: [PATCH] Ensure the LocalStroage keys are valid. Also update the cache key name. --- assets/js/_utils/pageviews.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/assets/js/_utils/pageviews.js b/assets/js/_utils/pageviews.js index 415a26c..931b5a5 100644 --- a/assets/js/_utils/pageviews.js +++ b/assets/js/_utils/pageviews.js @@ -94,8 +94,8 @@ var getInitStatus = (function() { var PvCache = (function() { const KEY_PV = "pv"; - const KEY_CREATION = "pv-created-date"; - const KEY_PV_TYPE = "pv-type"; + const KEY_CREATION = "pv_created_date"; + const KEY_PV_TYPE = "pv_type"; var PvType = { ORIGIN: "origin", @@ -148,6 +148,13 @@ var PvCache = (function() { }, newerThan: function(pv) { return PvCache.getAllPagevies() > pv.totalsForAllResults["ga:pageviews"]; + }, + inspectKeys: function() { + if (localStorage.getItem(KEY_PV) == null + || localStorage.getItem(KEY_PV_TYPE) == null + || localStorage.getItem(KEY_CREATION) == null) { + localStorage.clear(); + } } }; @@ -184,6 +191,8 @@ $(function() { if ($('.pageviews').length > 0) { + PvCache.inspectKeys(); + let cache = PvCache.getData(); if (cache) {