forked from cfjedimaster/brackets-jsdownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsdownloader.js
42 lines (32 loc) · 902 Bytes
/
jsdownloader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var JSDownloader = (function() {
var INDEX_URL = "jsdownloader_index.json";
var INDEX_KEY = "jsdownloader.index";
//Number of minutes to cache (smaller now since local)
var CACHE_LEN = 1000*60*60;
var index;
return {
getIndex:function() {
var raw = JSON.parse(localStorage.getItem(INDEX_KEY));
return raw.index;
},
hasCachedIndex:function() {
var cache = localStorage.getItem(INDEX_KEY);
if(!cache) return false;
var ob = JSON.parse(cache);
var then = new Date(ob.created);
var now = new Date();
if((now.getTime() - then.getTime()) > CACHE_LEN) return false;
return true;
},
loadIndex:function(base,cb) {
$.get(base + INDEX_URL, {}, function(res,code) {
console.dir(res);
var ob = {};
ob.created = new Date();
ob.index = res;
localStorage.setItem(INDEX_KEY, JSON.stringify(ob));
cb();
},"json");
}
};
}());