move rememberPad to cryptpad common and simplify it a bit
This commit is contained in:
@@ -15,5 +15,35 @@ define([
|
||||
return secret;
|
||||
};
|
||||
|
||||
var rememberPad = common.rememberPad = window.rememberPad = function () {
|
||||
// bail out early
|
||||
if (!/#/.test(window.location.hash)) { return; }
|
||||
|
||||
var storageKey = 'CryptPad_RECENTPADS';
|
||||
|
||||
var recentPadsStr = localStorage[storageKey];
|
||||
|
||||
var recentPads = [];
|
||||
if (recentPadsStr) {
|
||||
try {
|
||||
recentPads = JSON.parse(recentPadsStr);
|
||||
} catch (err) {
|
||||
// couldn't parse the localStorage?
|
||||
// just overwrite it.
|
||||
}
|
||||
}
|
||||
|
||||
var now = new Date();
|
||||
var timeframe = 1000 * 60 * 60 * 24 * 30;
|
||||
|
||||
var out = recentPads.filter(function (pad) {
|
||||
return (pad && pad[0] !== window.location.href &&
|
||||
(now.getTime() - new Date(pad[1]).getTime()) < timeframe);
|
||||
});
|
||||
|
||||
out.push([window.location.href, now]);
|
||||
localStorage[storageKey] = JSON.stringify(out);
|
||||
};
|
||||
|
||||
return common;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user