Skip to content

Commit 2df1313

Browse files
committed
fix: 修改小语种模式下获取创建时间正则
1 parent 7b00cef commit 2df1313

5 files changed

Lines changed: 86 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
- chore: popup 刷新列表时滚动至顶部
2-
- delete: 移除搜索弹窗相关的新标签页跳转逻辑
1+
- fix: 修改小语种模式下获取创建时间正则

entrypoints/components/BasicSettings/MenuShowcreatetime.vue

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,56 @@ export default {
4646
},
4747
4848
convertToTimestamp(dateStr) {
49-
const cleanedDateStr = dateStr.replace(/\s+/g, ""); // 去掉所有空格
50-
const datePattern = /(\d{4})年(\d{1,2})月(\d{1,2})日(\d{2}):(\d{2})/;
51-
const dateMatch = cleanedDateStr.match(datePattern);
49+
// 处理中文格式:2025 年 7月 29 日 12:59
50+
const chinesePattern = /(\d{4})\s*\s*(\d{1,2})\s*\s*(\d{1,2})\s*\s*(\d{1,2}):(\d{2})/;
51+
const chineseMatch = dateStr.match(chinesePattern);
52+
53+
if (chineseMatch) {
54+
const year = parseInt(chineseMatch[1], 10);
55+
const month = parseInt(chineseMatch[2], 10) - 1;
56+
const day = parseInt(chineseMatch[3], 10);
57+
const hours = parseInt(chineseMatch[4], 10);
58+
const minutes = parseInt(chineseMatch[5], 10);
5259
53-
if (dateMatch) {
54-
const year = parseInt(dateMatch[1], 10);
55-
const month = parseInt(dateMatch[2], 10) - 1;
56-
const day = parseInt(dateMatch[3], 10);
57-
const hours = parseInt(dateMatch[4], 10);
58-
const minutes = parseInt(dateMatch[5], 10);
60+
const date = new Date(year, month, day, hours, minutes);
61+
return date.getTime();
62+
}
63+
64+
// 处理英文格式:Jul 29, 2025 1:20 pm
65+
const englishPattern = /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d{1,2}),\s+(\d{4})\s+(\d{1,2}):(\d{2})\s*(am|pm)/i;
66+
const englishMatch = dateStr.match(englishPattern);
67+
68+
if (englishMatch) {
69+
const monthNames = {
70+
'jan': 0, 'feb': 1, 'mar': 2, 'apr': 3, 'may': 4, 'jun': 5,
71+
'jul': 6, 'aug': 7, 'sep': 8, 'oct': 9, 'nov': 10, 'dec': 11
72+
};
73+
74+
const month = monthNames[englishMatch[1].toLowerCase()];
75+
const day = parseInt(englishMatch[2], 10);
76+
const year = parseInt(englishMatch[3], 10);
77+
let hours = parseInt(englishMatch[4], 10);
78+
const minutes = parseInt(englishMatch[5], 10);
79+
const ampm = englishMatch[6].toLowerCase();
80+
81+
// 处理12小时制
82+
if (ampm === 'pm' && hours !== 12) {
83+
hours += 12;
84+
} else if (ampm === 'am' && hours === 12) {
85+
hours = 0;
86+
}
5987
6088
const date = new Date(year, month, day, hours, minutes);
6189
return date.getTime();
6290
}
91+
6392
return null;
6493
},
6594
setInitDate() {
6695
$(".topic-list .age").each((index, element) => {
6796
const str = $(element).attr("title");
68-
const match = str.match(/创建日期:([\s\S]*?)最新:/);
97+
// 匹配第一行从冒号开始的内容,支持中英文格式和冒号
98+
const match = str.match(/^(?:创建日期|Created)[::]\s*([^\n]+)/);
6999
70100
if (match && match[1]) {
71101
const creationDate = match[1].trim();

entrypoints/components/BasicSettings/MenuShowcreatetime1.vue

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,56 @@ export default {
4444
},
4545
4646
convertToTimestamp(dateStr) {
47-
const cleanedDateStr = dateStr.replace(/\s+/g, ""); // 去掉所有空格
48-
const datePattern = /(\d{4})年(\d{1,2})月(\d{1,2})日(\d{2}):(\d{2})/;
49-
const dateMatch = cleanedDateStr.match(datePattern);
47+
// 处理中文格式:2025 年 7月 29 日 12:59
48+
const chinesePattern = /(\d{4})\s*\s*(\d{1,2})\s*\s*(\d{1,2})\s*\s*(\d{1,2}):(\d{2})/;
49+
const chineseMatch = dateStr.match(chinesePattern);
50+
51+
if (chineseMatch) {
52+
const year = parseInt(chineseMatch[1], 10);
53+
const month = parseInt(chineseMatch[2], 10) - 1;
54+
const day = parseInt(chineseMatch[3], 10);
55+
const hours = parseInt(chineseMatch[4], 10);
56+
const minutes = parseInt(chineseMatch[5], 10);
5057
51-
if (dateMatch) {
52-
const year = parseInt(dateMatch[1], 10);
53-
const month = parseInt(dateMatch[2], 10) - 1;
54-
const day = parseInt(dateMatch[3], 10);
55-
const hours = parseInt(dateMatch[4], 10);
56-
const minutes = parseInt(dateMatch[5], 10);
58+
const date = new Date(year, month, day, hours, minutes);
59+
return date.getTime();
60+
}
61+
62+
// 处理英文格式:Jul 29, 2025 1:20 pm
63+
const englishPattern = /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d{1,2}),\s+(\d{4})\s+(\d{1,2}):(\d{2})\s*(am|pm)/i;
64+
const englishMatch = dateStr.match(englishPattern);
65+
66+
if (englishMatch) {
67+
const monthNames = {
68+
'jan': 0, 'feb': 1, 'mar': 2, 'apr': 3, 'may': 4, 'jun': 5,
69+
'jul': 6, 'aug': 7, 'sep': 8, 'oct': 9, 'nov': 10, 'dec': 11
70+
};
71+
72+
const month = monthNames[englishMatch[1].toLowerCase()];
73+
const day = parseInt(englishMatch[2], 10);
74+
const year = parseInt(englishMatch[3], 10);
75+
let hours = parseInt(englishMatch[4], 10);
76+
const minutes = parseInt(englishMatch[5], 10);
77+
const ampm = englishMatch[6].toLowerCase();
78+
79+
// 处理12小时制
80+
if (ampm === 'pm' && hours !== 12) {
81+
hours += 12;
82+
} else if (ampm === 'am' && hours === 12) {
83+
hours = 0;
84+
}
5785
5886
const date = new Date(year, month, day, hours, minutes);
5987
return date.getTime();
6088
}
89+
6190
return null;
6291
},
6392
setInitDate() {
6493
$(".topic-list-item .age").each((index, element) => {
6594
const str = $(element).attr("title");
66-
67-
const match = str.match(/创建日期:([\s\S]*?)最新:/);
95+
// 匹配第一行从冒号开始的内容,支持中英文格式和冒号
96+
const match = str.match(/^(?:创建日期|Created)[::]\s*([^\n]+)/);
6897
6998
if (match && match[1]) {
7099
const creationDate = match[1].trim();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "linuxdo-scripts",
33
"description": "manifest.json description",
44
"private": true,
5-
"version": "1.3.3",
5+
"version": "1.3.4",
66
"type": "module",
77
"scripts": {
88
"dev": "wxt",

version-log.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.3.4
2+
3+
- fix: 修改小语种模式下获取创建时间正则
4+
15
## 1.3.3
26

37
- chore: popup 刷新列表时滚动至顶部

0 commit comments

Comments
 (0)