From 3a3f2949dd3a56d125b2c68c02a268d1a02f4810 Mon Sep 17 00:00:00 2001
From: totoropcbeta <957584602@qq.com>
Date: Thu, 24 Oct 2024 23:11:28 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E7=AE=80=E5=8D=95UI=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/manifest.json | 2 +-
src/popup.html | 204 ++++++++++++++++++++++++++++++++--------------
src/scripts.js | 3 +-
3 files changed, 147 insertions(+), 62 deletions(-)
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..5ee1125 100644
--- a/src/popup.html
+++ b/src/popup.html
@@ -1,97 +1,181 @@
+
- 小工具
+ 时间戳转换小工具
+
-
diff --git a/src/scripts.js b/src/scripts.js
index b2cc269..0fbd299 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") === undefined ? 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) {
@@ -244,6 +271,8 @@ change();
loadGoonStatus();
+loadTimeFormatSelected();
+
loadMenuRadioAction();
loadTimestampJudgeType();
diff --git a/src/utils.js b/src/utils.js
index c16fe99..66cc79a 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -28,12 +28,19 @@ function getTimeString(timestamp, type) {
let minutes = date.getMinutes();
let seconds = date.getSeconds();
let milliseconds = date.getMilliseconds();
-
+ 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 === undefined || 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;
}
/**
From 0b8c5102efe7d8883eae581bf8bc08cd7f19e50c Mon Sep 17 00:00:00 2001
From: yuanhang08
Date: Fri, 25 Oct 2024 17:41:20 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E6=9C=88=E6=97=A5=E6=A0=BC=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/utils.js b/src/utils.js
index 66cc79a..a0e0b74 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -28,6 +28,8 @@ 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;
From 4de24392d1370be14752185d4ff4b736dc1b7b2c Mon Sep 17 00:00:00 2001
From: totoropcbeta <957584602@qq.com>
Date: Fri, 25 Oct 2024 22:15:02 +0800
Subject: [PATCH 4/4] null
---
src/scripts.js | 2 +-
src/utils.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/scripts.js b/src/scripts.js
index 0fbd299..3943bb6 100644
--- a/src/scripts.js
+++ b/src/scripts.js
@@ -1,7 +1,7 @@
let now;
let goStatus = true;
let interval;
-let gap = localStorage.getItem("gapValue") === undefined ? 1000 : localStorage.getItem("gapValue");
+let gap = localStorage.getItem("gapValue") === null ? 1000 : localStorage.getItem("gapValue");
let msgSpan = document.getElementById("msg");
diff --git a/src/utils.js b/src/utils.js
index a0e0b74..8d742e6 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -35,7 +35,7 @@ function getTimeString(timestamp, type) {
seconds = seconds < 10 ? "0" + seconds : seconds;
milliseconds = milliseconds < 100 ? milliseconds < 10 ? "00" + milliseconds : "0" + milliseconds : milliseconds;
let timeFormatSelected = localStorage.getItem("timeFormatSelected");
- if (timeFormatSelected === undefined || timeFormatSelected === "yyyy-MM-dd HH:mm:ss") {
+ 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;