diff --git a/js/account/home.js b/js/account/home.js index 5ce0558..f4de556 100644 --- a/js/account/home.js +++ b/js/account/home.js @@ -97,13 +97,25 @@ chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_PinnedGames'], async fun } if (Settings.HomeFriendCountOn === true) { - const FriendCount = (await (await fetch('https://polytoria.com/api/friends?page=1')).json()).meta.total; + chrome.storage.local.get(['PolyPlus_FriendCount'], async function(result){ + let FriendCount = result['PolyPlus_FriendCount'].count; - const CountText = document.createElement('small'); - CountText.classList = 'text-muted fw-lighter'; - CountText.style.fontSize = '0.8rem'; - CountText.innerText = ' (' + FriendCount + ')'; - document.querySelector('#home-friendsOnline h5').appendChild(CountText); + // cache for 5 minutes + if (FriendCount === undefined || (new Date().getTime() - FriendCount.requested > 300000)) { + FriendCount = (await (await fetch('https://polytoria.com/api/friends?page=1')).json()).meta.total; + + chrome.storage.local.set({['PolyPlus_FriendCount']: { + count: FriendCount, + requested: new Date().getTime() + }}, function(){}); + } + + const CountText = document.createElement('small'); + CountText.classList = 'text-muted fw-lighter'; + CountText.style.fontSize = '0.8rem'; + CountText.innerText = ' (' + FriendCount + ')'; + document.querySelector('#home-friendsOnline h5').appendChild(CountText); + }); } if (Settings.HomeJoinFriendsButtonOn === true) { diff --git a/js/extra-pages.js b/js/extra-pages.js index f29f6d9..15a1eeb 100644 --- a/js/extra-pages.js +++ b/js/extra-pages.js @@ -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', 'PolyPlus_GreatDivideStats'], function(local){ + chrome.storage.local.get(['PolyPlus_InventoryCache', 'PolyPlus_GreatDivideStats', 'PolyPlus_FriendCount'], function(local){ document.querySelector('#main-content .container').innerHTML = `