Export caches via CookieMonsterData.

This commit is contained in:
Ben Blank
2021-09-13 18:15:21 -07:00
parent 809bd4d35d
commit 74e7c64ca2
19 changed files with 136 additions and 31 deletions

18
src/Cache/FillCMDCache.js Normal file
View File

@@ -0,0 +1,18 @@
/**
* Insert the provided values into `window.CookieMonsterData.Cache`.
*
* The initial 'Cache' is dropped from the name, so e.g. `CacheWrinklersTotal`
* becomes `window.CookieMonsterData.Cache.WrinklersTotal`.
*/
export default function FillCMDCache(caches) {
if (!('Cache' in window.CookieMonsterData)) {
window.CookieMonsterData.Cache = {};
}
Object.keys(caches).forEach((name) => {
const exportName = name.replace(/^Cache/, '');
// Passing through JSON ensures that no references are retained.
window.CookieMonsterData.Cache[exportName] = JSON.parse(JSON.stringify(caches[name]));
});
}