修改了profile页面的日期翻译错误,优化代码

This commit is contained in:
woohoo 2021-12-21 12:52:35 +08:00
parent 96713042fe
commit 9d0b1c4c14

View File

@ -1,8 +1,8 @@
// ==UserScript== // ==UserScript==
// @lastmodified 202112191659 // @lastmodified 202112211252
// @name Torn翻译 // @name Torn翻译
// @namespace WOOH // @namespace WOOH
// @version 0.1.1219a // @version 0.1.1221a
// @description Torn UI翻译 // @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209] // @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/* // @match https://www.torn.com/*
@ -23,6 +23,11 @@
todo: true, todo: true,
cont: `baza npc商店 imarket及imarket搜索结果`, cont: `baza npc商店 imarket及imarket搜索结果`,
}, },
{
ver: '0.1.1221a',
date: '20211221',
cont: `修改了profile页面的日期翻译错误优化代码`,
},
{ {
ver: '0.1.1219a', ver: '0.1.1219a',
date: '20211219', date: '20211219',
@ -4134,21 +4139,23 @@
playerStatusTrans($('.profile-status .profile-container span')); playerStatusTrans($('.profile-status .profile-container span'));
// 表格 // 表格
$('ul.info-table li div').each((i, e) => { $('ul.info-table li div').each((i, e) => {
const $e = $(e);
// 左 // 左
if ($(e).attr('class').contains(/user-information-section/)) { if ($e.attr('class').contains(/user-information-section/)) {
e = e.children[0]; const elem = e.children[0];
if (profileDict[$(e).text().trim()]) $(e).text(profileDict[$(e).text().trim()]); const $elem = $(elem);
if (profileDict[$elem.text().trim()]) $elem.text(profileDict[$elem.text().trim()]);
} }
// 右 值 // 右 值
else { else {
if (profileDict[$(e).text().trim()]) { if (profileDict[$e.text().trim()]) {
$(e).children().text(profileDict[$(e).text().trim()]); $e.children().text(profileDict[$e.text().trim()]);
return; return;
} }
switch (i) { switch (i) {
case 5: case 5: // 帮派
case 7: { case 7: { // 公司
if ($(e).text().contains(CC_set)) return; if ($e.text().contains(CC_set)) return;
const $span = e.children[0].children[0]; const $span = e.children[0].children[0];
const pos = $span.firstChild.nodeValue.trim().split(' ').slice(0, -1).join(' '); const pos = $span.firstChild.nodeValue.trim().split(' ').slice(0, -1).join(' ');
$span.firstChild.nodeValue = ''; $span.firstChild.nodeValue = '';
@ -4156,30 +4163,32 @@
return; return;
} }
case 11: { case 11: {
$(e).find('span *').contents().each((i, e) => { // 住宅
if (e.nodeType === 3) { $e.find('span *').contents().each((i, el) => {
if (profileDict[e.nodeValue.trim()]) { if (el.nodeType === 3) {
e.nodeValue = profileDict[e.nodeValue.trim()] if (profileDict[el.nodeValue.trim()]) {
} else if (propertyDict[e.nodeValue.trim()]) { el.nodeValue = profileDict[el.nodeValue.trim()]
e.nodeValue = propertyDict[e.nodeValue.trim()] } else if (propertyDict[el.nodeValue.trim()]) {
el.nodeValue = propertyDict[el.nodeValue.trim()]
} }
} }
}); });
return; return;
} }
case 13: { case 13: {
if ($(e).text().contains(CC_set)) return; // 结婚状态
const days = $(e).text().contains(/ [0-9]+ /) if ($e.text().contains(CC_set)) return;
? $(e).text().trim().split(' ')[4] const days = $e.text().contains(/ [0-9]+ /)
? $e.text().trim().split(' ')[4]
: null; : null;
if (days) { if (days) {
e.children[0].children[0].childNodes[0].nodeValue = '与 '; e.children[0].children[0].childNodes[0].nodeValue = '与 ';
e.children[0].children[0].childNodes[2].nodeValue = ` 结婚${days}`; e.children[0].children[0].childNodes[2].nodeValue = ` 结婚${days}`;
} else { } else {
$(e).find('span *').contents().each((i, e) => { $e.find('span *').contents().each((i, el) => {
if (e.nodeType === 3) { if (el.nodeType === 3) {
if (profileDict[e.nodeValue.trim()]) { if (profileDict[el.nodeValue.trim()]) {
e.nodeValue = profileDict[e.nodeValue.trim()] el.nodeValue = profileDict[el.nodeValue.trim()]
} }
} }
}); });
@ -4188,8 +4197,8 @@
} }
case 23: { case 23: {
// 39 minutes ago // 39 minutes ago
if ($(e).text().contains(/ago/)) { if ($e.text().contains(/ago/)) {
$(e).children().text($(e).text() $e.children().text($e.text()
.replace('ago', '前') .replace('ago', '前')
.replace('and', '') .replace('and', '')
.replace('seconds', '秒') .replace('seconds', '秒')
@ -4198,9 +4207,10 @@
.replace('minute', '分') .replace('minute', '分')
.replace('hours', '时') .replace('hours', '时')
.replace('hour', '时') .replace('hour', '时')
.replace('days', '时') .replace('days', '日')
.replace('day', '时') .replace('day', '日')
) .replaceAll(' ', '')
);
} }
return; return;
} }
@ -5445,11 +5455,11 @@ margin: 0 0 3px;
const $city_wrapper = $root.querySelector('#ct-wrap'); const $city_wrapper = $root.querySelector('#ct-wrap');
if ($city_wrapper) { if ($city_wrapper) {
const $pos = $city_wrapper.querySelector('.map-title span[class^="position___"]') || $city_wrapper.querySelector('.status-title span[class^="position___"]'); const $pos = $city_wrapper.querySelector('.map-title span[class^="position___"]') || $city_wrapper.querySelector('.status-title span[class^="position___"]');
if(!$pos) return; if (!$pos) return;
const $pos_spl = $pos.innerText.trim().split(','); const $pos_spl = $pos.innerText.trim().split(',');
const player_position={}; const player_position = {};
player_position.x=parseInt($pos_spl[0]); player_position.x = parseInt($pos_spl[0]);
player_position.y=parseInt($pos_spl[1]); player_position.y = parseInt($pos_spl[1]);
const $wh_loot_container = $root.querySelector('#wh-loot-container'); const $wh_loot_container = $root.querySelector('#wh-loot-container');
if (!$wh_loot_container) { if (!$wh_loot_container) {
const insert_html = `<div id="wh-loot-container" class="m-bottom10"> const insert_html = `<div id="wh-loot-container" class="m-bottom10">
@ -5481,15 +5491,15 @@ margin: 0 0 3px;
if ($wh_loot_container_items) $wh_loot_container_items.innerHTML = ``; if ($wh_loot_container_items) $wh_loot_container_items.innerHTML = ``;
if ($wh_loot_container_chests) $wh_loot_container_chests.innerHTML = ``; if ($wh_loot_container_chests) $wh_loot_container_chests.innerHTML = ``;
item_list.forEach(e => { item_list.forEach(e => {
let path='·'; let path = '·';
if (e.x<player_position.x&&e.y<player_position.y) path='↙'; if (e.x < player_position.x && e.y < player_position.y) path = '↙';
if (e.x<player_position.x&&e.y===player_position.y) path='←'; if (e.x < player_position.x && e.y === player_position.y) path = '←';
if (e.x<player_position.x&&e.y>player_position.y) path='↖'; if (e.x < player_position.x && e.y > player_position.y) path = '↖';
if (e.x===player_position.x&&e.y>player_position.y) path='↑'; if (e.x === player_position.x && e.y > player_position.y) path = '↑';
if (e.x>player_position.x&&e.y>player_position.y) path='↗'; if (e.x > player_position.x && e.y > player_position.y) path = '↗';
if (e.x>player_position.x&&e.y===player_position.y) path='→'; if (e.x > player_position.x && e.y === player_position.y) path = '→';
if (e.x>player_position.x&&e.y<player_position.y) path='↘'; if (e.x > player_position.x && e.y < player_position.y) path = '↘';
if (e.x===player_position.x&&e.y<player_position.y) path='↓'; if (e.x === player_position.x && e.y < player_position.y) path = '↓';
if (e.name === 'chests') { if (e.name === 'chests') {
chest_count++; chest_count++;
$wh_loot_container_chests.innerHTML += `<span style="display: inline-block;background-color: ${chestTypeColorDict[e.type] || 'silver'};color: white;margin: 0 1em 0 0;border-radius: 4px;padding: 0.5em;">${path}[${e.x},${e.y}] - ${chestTypeDict[e.type]}${lootTypeDict[e.name]}<img src="${e.url}" style="height: 1em; width: 1em;"/></span>` $wh_loot_container_chests.innerHTML += `<span style="display: inline-block;background-color: ${chestTypeColorDict[e.type] || 'silver'};color: white;margin: 0 1em 0 0;border-radius: 4px;padding: 0.5em;">${path}[${e.x},${e.y}] - ${chestTypeDict[e.type]}${lootTypeDict[e.name]}<img src="${e.url}" style="height: 1em; width: 1em;"/></span>`