@@ -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 ();
0 commit comments