From 28363bd87abf1b69a155816c76b50b7cca89b663 Mon Sep 17 00:00:00 2001 From: woohoo Date: Sat, 11 Dec 2021 15:23:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=A5=E7=BA=B8=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E7=BF=BB=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index eb05b1b..e12a325 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -1,8 +1,8 @@ // ==UserScript== -// @lastmodified 202112101911 +// @lastmodified 202112111523 // @name Torn翻译 // @namespace WOOH -// @version 0.1.1210a +// @version 0.1.1211a // @description Torn UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* @@ -23,6 +23,11 @@ todo: true, cont: `baza npc商店 imarket及imarket搜索结果`, }, + { + ver: '0.1.1211a', + date: '20211211', + cont: `修复报纸日期翻译问题`, + }, { ver: '0.1.1210a', date: '20211210', @@ -4179,9 +4184,28 @@ // 公众号广告 $('div.price.left').contents()[2].nodeValue = '文章翻译请关注中文公众号Torncity'; // 日期翻译 - const date = new Date($('span.date-label').text()); - if (date.format('yyyy') !== 'NaN') - $('span.date-label').text(date.format('yyyy年MM月dd日')); + const $date_label = document.querySelector('span.date-label'); + const date_reg = /^[FMSTW][adehinorstuy]+, [ADFJMNOS][abceglnoprtuvy]+ [1-3]?[0-9], 20[0-9][0-9]$/; + if ($date_label && $date_label.innerText.trim().contains(date_reg)) { + const date_format = $date_label.innerText.trim().replaceAll(',', ''); + const date_spl = date_format.split(' '); + const date = {w: date_spl[0], m: date_spl[1], d: date_spl[2], y: date_spl[3]}; + const month_trans = { + 'Jan': 1, + 'Feb': 2, + 'Mar': 3, + 'Apr': 4, + 'May': 5, + 'Jun': 6, + 'Jul': 7, + 'Aug': 8, + 'Sep': 9, + 'Oct': 10, + 'Nov': 11, + 'Dec': 12 + }; + $date_label.innerText = `${date.y}年${month_trans[date.m] || date.m}月${date.d}日`; + } // 菜单下的信息 工作 壁纸 广告 悬赏 $('div.help-message').find('*').contents().each((i, e) => { if (!e.nodeValue || e.nodeValue.trim() === '') return;