diff --git a/lod.html b/lod.html index 75c29f2..2b6ad87 100644 --- a/lod.html +++ b/lod.html @@ -129,6 +129,7 @@ let m3r = input_m3r.value; let lod = { + "time": Date.now(), "m0l": m0l, "m1l": m1l, "m3l": m3l, @@ -183,9 +184,13 @@ for (let i = 0; i < localStorage.length; i++) { keys.push(localStorage.key(i)); } + keys.sort(); keys.forEach(key => { + let timestamp = JSON.parse(localStorage.getItem(key)).time; + let time = new Date(timestamp).format("yyyy-MM-dd hh:mm"); let option = document.createElement("option"); - option.innerText = key; + $(option).attr("value", key); + $(option).attr("label", `保存于 ${time}`); $("#keys").append(option); }); } @@ -247,6 +252,28 @@ return m0 == '' || m1 == '' || m3 == ''; } + // 为 Date 创建日期格式化方法 + Date.prototype.format = function (fmt) { + var o = { + "M+": this.getMonth() + 1, //月份 + "d+": this.getDate(), //日 + "h+": this.getHours(), //小时 + "m+": this.getMinutes(), //分 + "s+": this.getSeconds(), //秒 + "q+": Math.floor((this.getMonth() + 3) / 3), //季度 + "S": this.getMilliseconds() //毫秒 + }; + if (/(y+)/.test(fmt)) { + fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); + } + for (var k in o) { + if (new RegExp("(" + k + ")").test(fmt)) { + fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); + } + } + return fmt; + } +