forked from iitc-project/ingress-intel-total-conversion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Manage settings | ||
**/ | ||
Settings = (function () { | ||
|
||
let storage; | ||
let date = Date.now(); | ||
|
||
|
||
function get(group, key, defaultValues) { | ||
storage[group] = storage[group] || {}; | ||
storage[group]._lastAccess = date; | ||
return (storage[group][key] || defaultValues); | ||
} | ||
|
||
|
||
function set(group, key, value) { | ||
storage[group] = storage[group] || {}; | ||
storage[group]._lastAccess=date; | ||
storage[group][key] = value; | ||
} | ||
|
||
|
||
function getGroupRef(group, defaults) { | ||
|
||
storage[group] = storage[group] || {}; | ||
if (defaults) { | ||
for (let key in defaults) { | ||
storage[group][key] = storage[group][key] || defaults[key]; | ||
} | ||
} | ||
storage[group]._lastAccess=date; | ||
return storage[group]; | ||
} | ||
|
||
|
||
|
||
function init() { | ||
let store = localStorage.getItem('iitc_settings'); | ||
storage = JSON.parse(store || '{}'); | ||
|
||
$(window).on('beforeunload',save); | ||
} | ||
|
||
|
||
function save() { | ||
cleanUp(); | ||
localStorage.setItem('iitc_settings', JSON.stringify(storage)); | ||
} | ||
|
||
function cleanUp() { | ||
let old = date - 1000*60*60*24*7; // 1Week | ||
for (let group in storage) { | ||
if (storage[group]._lastAccess<old) { | ||
delete storage[group]; | ||
} | ||
} | ||
} | ||
|
||
|
||
return { | ||
init: init, | ||
get: get, | ||
set: set, | ||
getGroupRef: getGroupRef | ||
}; | ||
|
||
|
||
})(); |