diff --git a/content.js b/content.js
index 358ed97..32dda83 100644
--- a/content.js
+++ b/content.js
@@ -26,7 +26,7 @@
zIndex: '2147483647',
boxShadow: '-4px 0 8px rgba(0,0,0,0.15)',
backgroundColor: 'white',
- transform: 'translateX(0)',
+ transform: 'translateX(100%)', // 默认关闭状态
transition: 'transform 0.3s ease',
});
@@ -65,7 +65,7 @@
document.body.appendChild(toggleBtn);
// 折叠 / 展开逻辑
- let visible = true;
+ let visible = false; // 默认关闭状态
toggleBtn.addEventListener('click', () => {
visible = !visible;
iframe.style.transform = visible ? 'translateX(0)' : 'translateX(100%)';
@@ -95,4 +95,4 @@
return true;
}
});
-})();
+})();
\ No newline at end of file
diff --git a/sidepanel/index.css b/sidepanel/index.css
index 818edbb..dd1b290 100644
--- a/sidepanel/index.css
+++ b/sidepanel/index.css
@@ -35,6 +35,29 @@
margin-left: auto;
}
+.input-text {
+ width: 100%;
+ padding: 0.5rem;
+ margin: 0.5rem 0;
+ box-sizing: border-box;
+}
+
+.convert-button {
+ padding: 0.5rem 1rem;
+ background-color: #28a745;
+ color: white;
+ border: none;
+ border-radius: 0.25rem;
+ cursor: pointer;
+}
+
+.select-box {
+ width: 100%;
+ padding: 0.5rem;
+ margin: 0.5rem 0;
+ box-sizing: border-box;
+}
+
.content {
padding: 1rem;
}
@@ -45,4 +68,4 @@
.page.active {
display: block;
-}
\ No newline at end of file
+}
diff --git a/sidepanel/index.html b/sidepanel/index.html
index 875aa87..6724b47 100644
--- a/sidepanel/index.html
+++ b/sidepanel/index.html
@@ -18,6 +18,7 @@
+
时间戳工具
@@ -32,6 +33,35 @@
+
+
+
+
时间戳转日期时间
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sidepanel/index.js b/sidepanel/index.js
index d38e942..1b73ab6 100644
--- a/sidepanel/index.js
+++ b/sidepanel/index.js
@@ -48,6 +48,59 @@ toggleTimestampBtn.addEventListener('click', () => {
updateTimestamp(showMilliseconds);
});
+const inputTimestamp = document.getElementById('input-timestamp');
+const convertTimestampBtn = document.getElementById('convert-timestamp-btn');
+const timestampInputResult = document.getElementById('timestamp-input-result');
+const timestampUnitSelect = document.querySelector('#page-timestamp select'); // 时间戳单位选择器
+
+convertTimestampBtn.addEventListener('click', () => {
+ const timestamp = inputTimestamp.value.trim();
+ console.log('输入时间戳:', timestamp);
+
+ if (!timestamp) {
+ timestampInputResult.value = '请输入时间戳';
+ return;
+ }
+
+ // 获取选择的时间戳单位(秒或毫秒)
+ const isSeconds = timestampUnitSelect.value === 'seconds';
+
+ // 转换为数字
+ let timestampNum = Number(timestamp);
+
+ // 如果是秒,转换为毫秒
+ if (isSeconds) {
+ timestampNum = timestampNum * 1000;
+ }
+
+ // 检查是否为有效数字
+ if (isNaN(timestampNum)) {
+ timestampInputResult.value = '请输入有效的时间戳';
+ return;
+ }
+
+ // 创建日期对象
+ const date = new Date(timestampNum);
+
+ // 检查日期是否有效
+ if (isNaN(date.getTime())) {
+ timestampInputResult.value = '无效的日期';
+ return;
+ }
+
+ console.log('转换日期对象:', date);
+ const year = date.getFullYear();
+ const month = date.getMonth() + 1;
+ const day = date.getDate();
+ const hours = date.getHours();
+ const minutes = date.getMinutes();
+ const seconds = date.getSeconds();
+
+ console.log('转换结果:', `${year}年${month}月${day}日 ${hours}时${minutes}分${seconds}秒`);
+
+ timestampInputResult.value = `${year}年${month}月${day}日 ${hours}时${minutes}分${seconds}秒`;
+});
+
// 复制时间戳到剪贴板
const copyTimestampBtn = document.getElementById('copy-timestamp-btn');
const currentTimestamp = document.getElementById('current-timestamp');
@@ -55,15 +108,18 @@ copyTimestampBtn.addEventListener('click', () => {
// 获取时间戳文本
const timestampText = currentTimestamp.textContent;
- chrome.runtime.sendMessage({ action: 'copyText', data: timestampText }, (res) => {
- if (chrome.runtime.lastError) {
- console.error('❌ 传送时间戳文本失败:', chrome.runtime.lastError);
- } else if (res?.success) {
- console.log('✅ 已复制:', timestampText);
- } else {
- console.error('❌ 复制失败:', res);
- }
- });
+ // 检查扩展上下文是否仍然有效
+ if (chrome.runtime && chrome.runtime.sendMessage) {
+ chrome.runtime.sendMessage({ action: 'copyText', data: timestampText }, (res) => {
+ if (chrome.runtime.lastError) {
+ console.error('❌ 传送时间戳文本失败:', chrome.runtime.lastError);
+ } else if (res?.success) {
+ console.log('✅ 已复制:', timestampText);
+ } else {
+ console.error('❌ 复制失败:', res);
+ }
+ });
+ }
});
function switchPage(pageName) {