diff --git a/src/manifest.json b/src/manifest.json index f28bec5..73da718 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -4,7 +4,7 @@ }, "description": "时间戳转换小工具。右键菜单显示转化,工具页时间戳转化", "manifest_version": 2, - "name": "时间戳转化", + "name": "时间戳转换", "content_scripts": [ { "matches": [ diff --git a/src/popup.html b/src/popup.html index f41a1e9..f6a0c1e 100644 --- a/src/popup.html +++ b/src/popup.html @@ -1,97 +1,198 @@ + - 小工具 + 时间戳转换小工具 + -
-
-
+
+
- - - - - - +
+ + + + +
- - +
+ + + +
+
- - - - -
-
+
+ + + + + +
-
+
+ + + + + +
+
-
- - - - - + +
+ + + + + +
+ 时间戳位数判断: + + + +
+
+ +
- - - - - + 小提示:鼠标滚轮中键点击可以复制或者粘贴,年月日时分秒字符串的分隔符不限 +
+
+  
- -
- -
- 时间戳位数判断: - - - -
- -
- 小提示:鼠标滚轮中键点击可以复制或者粘贴,年月日时分秒字符串的分隔符不限 -
-
-   -
+ +
- - -
+ \ No newline at end of file diff --git a/src/scripts.js b/src/scripts.js index 61c25ae..3943bb6 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -1,7 +1,7 @@ let now; let goStatus = true; let interval; -let gap = 1000; +let gap = localStorage.getItem("gapValue") === null ? 1000 : localStorage.getItem("gapValue"); let msgSpan = document.getElementById("msg"); @@ -11,6 +11,7 @@ let timestampNowInput = document.getElementById("timestamp-now"); let resultInput = document.getElementById("result"); let goonCheckBox = document.getElementById("goon"); let gapInput = document.getElementById("gap"); +gapInput.value = gap; let refreshButton = document.getElementById("refresh"); let changeButton = document.getElementById("change"); @@ -27,6 +28,11 @@ let only10Radio = document.getElementById("only-10-radio"); let only13Radio = document.getElementById("only-13-radio"); let both10_13 = document.getElementById("both-10-13-radio"); +let timeFormatSelected = document.getElementById("time_format"); + +let datetimeoption = document.getElementById("datetime"); +let dateoption = document.getElementById("date"); +let datekeyoption = document.getElementById("datekey"); function getTimestamp13() { return now.getTime(); @@ -98,17 +104,13 @@ inputInput.oninput = function () { change(); }; -gapInput.oninput = function () { +gapInput.addEventListener('change', function (event) { + var gapValue = event.target.value; + console.log("gapValue:", gapValue); + localStorage.setItem("gapValue", gapValue); refreshGap(); -}; - -gapInput.onkeypress = function (e) { - refreshGap(); - - if (e.keyCode === 13) { - refreshWithInterval(); - } -}; + refreshWithInterval(); +}); resultInput.oninput = function () { let value = resultInput.value; @@ -199,6 +201,12 @@ both10_13.onclick = function () { localStorage.timestampJudgeType = "3"; }; +timeFormatSelected.addEventListener('change', function (event) { + var format = event.target.value; + console.log('转换时间格式选中的值:', format); + localStorage.setItem("timeFormatSelected", format); +}); + function loadTimestampJudgeType() { let timestampJudgeType = localStorage.timestampJudgeType; switch (timestampJudgeType) { @@ -227,6 +235,25 @@ function loadMenuRadioAction() { showAlertCheckbox.checked = !(localStorage.showAlert === "false"); } +function loadTimeFormatSelected() { + var timeFormatSelected = localStorage.getItem("timeFormatSelected"); + console.log("timeFormatSelected:", timeFormatSelected); + switch (timeFormatSelected) { + case "yyyy-MM-dd HH:mm:ss": + datetimeoption.selected = true; + break; + case "yyyy-MM-dd": + dateoption.selected = true; + break; + case "yyyyMMdd": + datekeyoption.selected = true; + break; + default: + datetimeoption.selected = true; + break; + } +} + function getInterval() { return setInterval(function () { if (goStatus) { @@ -238,11 +265,14 @@ function getInterval() { refresh(); inputInput.focus(); -inputInput.value = localStorage.selectText; +resultInput.value = ""; +inputInput.value = ""; change(); loadGoonStatus(); +loadTimeFormatSelected(); + loadMenuRadioAction(); loadTimestampJudgeType(); diff --git a/src/utils.js b/src/utils.js index c16fe99..8d742e6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -28,12 +28,21 @@ function getTimeString(timestamp, type) { let minutes = date.getMinutes(); let seconds = date.getSeconds(); let milliseconds = date.getMilliseconds(); - + month = month < 10 ? "0" + month : month; + day = day < 10 ? "0" + day : day; + hours = hours < 10 ? "0" + hours : hours; minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; milliseconds = milliseconds < 100 ? milliseconds < 10 ? "00" + milliseconds : "0" + milliseconds : milliseconds; + let timeFormatSelected = localStorage.getItem("timeFormatSelected"); + if (timeFormatSelected === null || timeFormatSelected === "yyyy-MM-dd HH:mm:ss") { + return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds + "." + milliseconds; + } else if (timeFormatSelected === "yyyy-MM-dd") { + return year + "-" + month + "-" + day; + } else if (timeFormatSelected === "yyyyMMdd") { + return String(year) + String(month) + String(day); + } - return year + "年" + month + "月" + day + "日 " + hours + ":" + minutes + ":" + seconds + "." + milliseconds; } /**