修复报纸日期翻译问题

This commit is contained in:
woohoo 2021-12-11 15:23:36 +08:00
parent fad8478579
commit 28363bd87a

View File

@ -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;