move rememberPad to cryptpad common and simplify it a bit

This commit is contained in:
ansuz
2016-06-21 18:46:19 +02:00
parent ad40715c6e
commit 0a8137e7eb
2 changed files with 30 additions and 28 deletions

View File

@@ -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;
});