diff --git a/js/background.js b/js/background.js index e5f67da..eb8a3b4 100755 --- a/js/background.js +++ b/js/background.js @@ -124,16 +124,21 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { if (request.action === 'reload') { chrome.runtime.reload(); } else if (request.action === 'greatdivide_stats') { - chrome.storage.local.get(['PolyPlus_GreatDivideStats_' + request.userID], async function(result){ - let Statistics = result['PolyPlus_GreatDivideStats_' + request.userID] + chrome.storage.local.get(['PolyPlus_GreatDivideStats'], async function(result){ + const Cache = (result['PolyPlus_GreatDivideStats']||{[request.userID]:undefined}) // cache for 5 minutes - if (Statistics !== undefined && (new Date().getTime() - Statistics.requested < 300000)) { - Statistics = Statistics.data - } else { - Statistics = (await (await fetch('https://stats.silly.mom/player_stats?id=' + request.userID)).json()).results - if (Statistics !== null) { Statistics = Statistics[0] } - chrome.storage.local.set({['PolyPlus_GreatDivideStats_' + request.userID]: {data: Statistics, requested: new Date().getTime()}}, function(){}) + if (Cache[request.userID] === undefined || (new Date().getTime() - Cache[request.userID].requested > 300000)) { + let Statistics = (await (await fetch('https://stats.silly.mom/player_stats?id=' + request.userID)).json()).results + if (Statistics !== null) { + Statistics = Statistics[0] + } + Cache[request.userID] = { + data: Statistics, + requested: new Date().getTime() + } + + chrome.storage.local.set({['PolyPlus_GreatDivideStats']: Cache}, function(){}) } chrome.tabs.query({ active: true, currentWindow: true }, function(tabs){ @@ -141,7 +146,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { .executeScript({ target: {tabId: tabs[0].id}, func: LoadStats, - args: [Statistics] + args: [Cache[request.userID].data] }) }) }) diff --git a/js/extra-pages.js b/js/extra-pages.js index 4783b28..f29f6d9 100644 --- a/js/extra-pages.js +++ b/js/extra-pages.js @@ -264,7 +264,7 @@ if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.has }) chrome.storage.sync.getBytesInUse(['PolyPlus_Settings', 'PolyPlus_PinnedGames', 'PolyPlus_ItemWishlist', 'PolyPlus_TimePlayed', 'PolyPlus_AvatarSandboxOutfits'], function (sync) { - chrome.storage.local.getBytesInUse(['PolyPlus_InventoryCache'], function(local){ + chrome.storage.local.getBytesInUse(['PolyPlus_InventoryCache', 'PolyPlus_GreatDivideStats'], function(local){ document.getElementById('data-size').innerText = (sync + local).toLocaleString(); }) }); @@ -272,7 +272,7 @@ if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.has } else if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.hash === '#debug') { document.addEventListener('DOMContentLoaded', function () { chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_PinnedGames', 'PolyPlus_BestFriends', 'PolyPlus_ItemWishlist', 'PolyPlus_AvatarSandboxOutfits', 'PolyPlus_TimePlayed'], function(sync) { - chrome.storage.local.get(['PolyPlus_InventoryCache'], function(local){ + chrome.storage.local.get(['PolyPlus_InventoryCache', 'PolyPlus_GreatDivideStats'], function(local){ document.querySelector('#main-content .container').innerHTML = `

Poly+ Debug

-

This page is used for accessing most data-related objects stored by the extension.

+

This page is used for accessing most data-related objects stored by the extension.

+ * note: cache objects don't get cleared, instead when they are requested, if the data stored is old, new data will replace the old data.
@@ -404,7 +405,7 @@ if (window.location.pathname.split('/')[3] === 'polyplus' && window.location.has
-
+
+
+
+ ${JSON.stringify((local.PolyPlus_GreatDivideStats || {}), null, 2) + .replaceAll('\n','
') + .replaceAll(' ', ' ') + .replaceAll('\t', '    ')} +
+
+
`;