优化了页标题右侧按钮翻译
调整了物品页面、展柜页面物品详情翻译 增加了npc商人页面的翻译 更改了标题翻译匹配的字典
This commit is contained in:
parent
fa874f4b1a
commit
fad8478579
@ -2,7 +2,7 @@
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=0"/>
|
||||
<meta content="width=device-width, initial-scale=1 user-scalable=0" name="viewport"/>
|
||||
<script type="text/javascript">
|
||||
window.onload = () => {
|
||||
const giteeRaw = 'https://gitee.com/wanyi007/torncity-zhcn-translate/raw/dev/torn-trans-zhcn.user.js';
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
// ==UserScript==
|
||||
// @lastmodified 202112091804
|
||||
// @lastmodified 202112101911
|
||||
// @name Torn翻译
|
||||
// @namespace WOOH
|
||||
// @version 0.1.1209a
|
||||
// @version 0.1.1210a
|
||||
// @description Torn UI翻译
|
||||
// @author Woohoo-[2687093] sabrina_devil[2696209]
|
||||
// @match https://www.torn.com/*
|
||||
@ -18,6 +18,28 @@
|
||||
|
||||
const CC_set = /[\u4e00-\u9fa5]/;
|
||||
|
||||
const changelist = [
|
||||
{
|
||||
todo: true,
|
||||
cont: `baza npc商店 imarket及imarket搜索结果`,
|
||||
},
|
||||
{
|
||||
ver: '0.1.1210a',
|
||||
date: '20211210',
|
||||
cont: `优化了页标题右侧按钮翻译
|
||||
调整了物品页面、展柜页面物品详情翻译
|
||||
增加了npc商人页面的翻译
|
||||
更改了标题翻译匹配的字典`,
|
||||
},
|
||||
{
|
||||
ver: '0.1.1209a',
|
||||
date: '20211209',
|
||||
cont: `添加翻译股票页面购买历史中的“Show n more”,调整了一些字段翻译
|
||||
更新了一些物品名称翻译,咸鱼修正为鳟鱼`,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
const $ = window.jQuery;
|
||||
const titleDict = {
|
||||
'Home': '主页',
|
||||
@ -1406,6 +1428,7 @@
|
||||
'Braking:': '制动:',
|
||||
'Handling:': '操控:',
|
||||
'Rate of Fire:': '开火率:',
|
||||
'Read:': '已读:',
|
||||
};
|
||||
const itemNameDict = {
|
||||
"Ammunition Pack": '弹药包',
|
||||
@ -2276,6 +2299,8 @@
|
||||
'效果:使用者变得坚硬,在120秒内增加300%的防御,并补充25%的生命。',
|
||||
"Effect: Opponent becomes Concussed, decreasing Dexterity to 1/5th for 15-20 seconds.":
|
||||
'效果:对手脑部震荡,闪避下降到1/5,持续15-20秒。',
|
||||
// other
|
||||
"Effect: Increases happiness by 5-20 if under 20% of maximum.": '',
|
||||
};
|
||||
const itemTypeDict = {
|
||||
'is a Defensive Armor.': '是一种防御性盔甲。',
|
||||
@ -2649,6 +2674,35 @@
|
||||
const pcDict = {
|
||||
'Virus Programming': '病毒编程',
|
||||
};
|
||||
const npcShopDict = {
|
||||
"Buy Items": '购买物品',
|
||||
"Buy": '买',
|
||||
"in stock)": '存货)',
|
||||
"Flower (": '花(',
|
||||
"Plushie (": '玩偶(',
|
||||
"Other (": '其他(',
|
||||
"Temporary (": '临时(',
|
||||
"Melee (": '近战(',
|
||||
"Candy (": '糖果(',
|
||||
"Booster (": '增益道具(',
|
||||
"Car (": '车辆(',
|
||||
"Electronic (": '电器(',
|
||||
"Alcohol (": '酒类(',
|
||||
"Sell": '卖出',
|
||||
"items": '物品',
|
||||
"Value": '卖价',
|
||||
"Amount": '数量',
|
||||
"items to Bits 'n' Bobs": '物品给胖鲍勃的杂货店',
|
||||
"Select All": '全选',
|
||||
"Unselect All": '全不选',
|
||||
"SELL ITEMS": '卖出物品',
|
||||
"Cancel": '取消',
|
||||
"Are you sure you would like to sell these items?": '你确定想出售这些物品吗?',
|
||||
"Total value:\n$": '总计:$',
|
||||
"Yes": '是',
|
||||
"No": '否',
|
||||
"Are you sure you would like to buy": '你是否想买',
|
||||
};
|
||||
|
||||
// 默认开启通知翻译
|
||||
if (!localStorage.getItem('wh_trans_event')) {
|
||||
@ -3399,8 +3453,10 @@
|
||||
const $loadouts_root = document.getElementById('loadoutsRoot');
|
||||
if ($loadouts_root) {
|
||||
initOB($loadouts_root, {subtree: true, attributes: true}, () => {
|
||||
const el = $loadouts_root.querySelector('div[class^="itemReview___"] div[class^="type___"]');
|
||||
if (itemPageDict[el.innerText.trim()]) el.innerText = itemPageDict[el.innerText.trim()];
|
||||
const el = $loadouts_root.querySelector('div[class^="type___"]');
|
||||
if (el && itemPageDict[el.innerText.trim()]) {
|
||||
el.innerText = itemPageDict[el.innerText.trim()];
|
||||
}
|
||||
});
|
||||
}
|
||||
// 手机选项按钮 物品名 物品详情
|
||||
@ -3453,53 +3509,7 @@
|
||||
}
|
||||
// 物品详情
|
||||
const $show_item_info = $active_tab.querySelector('li.show-item-info');
|
||||
if ($show_item_info) {
|
||||
const $item_info = $show_item_info.querySelector('span.info-msg');
|
||||
if ($item_info) {
|
||||
// torntools 插件
|
||||
const isTTModified = $item_info.classList.contains('tt-modified');
|
||||
if (isTTModified) {
|
||||
}
|
||||
// 物品名
|
||||
const itemName = $item_info.children[0].children[0]; //<span class="bold">大麻1</span>
|
||||
// 去除the
|
||||
const the_removed = itemName.innerText.trim().slice(4);
|
||||
if (itemNameDict[the_removed]) {
|
||||
itemName.innerText = `${itemNameDict[the_removed]}(${the_removed})`;
|
||||
}
|
||||
// 类型文字
|
||||
const itemType = $item_info.children[0].childNodes[2]; //itemType.nodeValue
|
||||
if (itemTypeDict[itemType.nodeValue.trim()]) {
|
||||
itemType.nodeValue = itemTypeDict[itemType.nodeValue.trim()];
|
||||
}
|
||||
// 描述
|
||||
const itemDesc = $item_info.childNodes[2]; //itemDesc.nodeValue
|
||||
if (itemDescDict[itemDesc.nodeValue.trim()]) {
|
||||
itemDesc.nodeValue = itemDescDict[itemDesc.nodeValue.trim()];
|
||||
}
|
||||
// 效果
|
||||
const itemEffect = $item_info.querySelector('div.t-green.item-effect');
|
||||
if (itemEffect && itemEffectDict[itemEffect.innerText.trim()]) {
|
||||
itemEffect.innerText = itemEffectDict[itemEffect.innerText.trim()];
|
||||
}
|
||||
// 使用需求
|
||||
const itemReq = $item_info.querySelector('div.t-red.item-effect');
|
||||
if (itemReq && itemReqDict[itemReq.innerText.trim()]) {
|
||||
itemReq.innerText = itemReqDict[itemReq.innerText.trim()];
|
||||
}
|
||||
}
|
||||
// 下方的表格
|
||||
const $info_table_title = $show_item_info.querySelectorAll('div.title');
|
||||
$info_table_title.forEach((e) => {
|
||||
if (itemPageDict[e.innerText.trim()]) {
|
||||
e.innerText = itemPageDict[e.innerText.trim()];
|
||||
}
|
||||
});
|
||||
}
|
||||
// const $item_info_key = $('li.item-info-active').next().find('li div:first-child');
|
||||
// $item_info_key.each((i, e) => {
|
||||
// if (itemPageDict[e.innerText.trim()]) e.innerText = itemPageDict[e.innerText.trim()];
|
||||
// });
|
||||
showItemInfoTrans($show_item_info);
|
||||
// 物品右操作按钮
|
||||
const $opt_icon_tooltip = $('ul.actions-wrap span.icon-h');
|
||||
if (translatedOnce.opt_icon_count !== $opt_icon_tooltip.length - 1) {
|
||||
@ -3540,6 +3550,118 @@
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
npc商店
|
||||
*/
|
||||
if (window.location.href.contains(/shops\.php/)) {
|
||||
// 标题和右边的链接
|
||||
const $cont_title = document.querySelector('.content-title');
|
||||
initOB($cont_title, {childList: true, subtree: true},
|
||||
() => {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
});
|
||||
const $wrapper = document.querySelector('.content-wrapper');
|
||||
// [购买部分]
|
||||
const $buy_items_wrapper = $wrapper.querySelector('.buy-items-wrap');
|
||||
// 黑框标题
|
||||
const $buy_black_title = $buy_items_wrapper.querySelector('.title-black');
|
||||
if ($buy_black_title.firstChild.nodeValue && npcShopDict[$buy_black_title.firstChild.nodeValue.trim()]) {
|
||||
$buy_black_title.firstChild.nodeValue = npcShopDict[$buy_black_title.firstChild.nodeValue.trim()];
|
||||
}
|
||||
// 各个物品
|
||||
const $items = $buy_items_wrapper.querySelectorAll('ul.items-list > li.torn-divider');
|
||||
$items.forEach(e => {
|
||||
// 物品名
|
||||
const $item_name = e.querySelector('span.desc span.name.bold');
|
||||
if ($item_name && itemNameDict[$item_name.innerText.trim()]) {
|
||||
$item_name.innerText = `${itemNameDict[$item_name.innerText.trim()]}(${$item_name.innerText.trim()})`;
|
||||
}
|
||||
// 类型和存货
|
||||
const $item_stock = e.querySelector('span.desc span.stock');
|
||||
if ($item_stock) $item_stock.childNodes.forEach(e => {
|
||||
if (e.nodeType === 1) {
|
||||
if (npcShopDict[e.innerText.trim()]) e.innerText = npcShopDict[e.innerText.trim()];
|
||||
} else {
|
||||
if (npcShopDict[e.nodeValue.trim()]) e.nodeValue = npcShopDict[e.nodeValue.trim()];
|
||||
}
|
||||
});
|
||||
// buy按钮
|
||||
const $buy_btn = e.querySelector('button.wai-support');
|
||||
if ($buy_btn && npcShopDict[$buy_btn.childNodes[0].nodeValue.trim()]) {
|
||||
$buy_btn.childNodes[0].nodeValue = npcShopDict[$buy_btn.childNodes[0].nodeValue.trim()];
|
||||
}
|
||||
// 买前确认
|
||||
const $confirm = e.querySelector('span.confirm');
|
||||
const $confirm_msg = $confirm.querySelector('span');
|
||||
if ($confirm_msg && npcShopDict[$confirm_msg.innerText.trim()]) {
|
||||
$confirm_msg.innerText = npcShopDict[$confirm_msg.innerText.trim()];
|
||||
}
|
||||
const $amount_item_name = $confirm.querySelector('span.count').nextSibling;
|
||||
if ($amount_item_name && !$amount_item_name.nodeValue.contains(CC_set)) {
|
||||
const item_name = $amount_item_name.nodeValue.trim().split(' ').slice(1, -1).join(' ');
|
||||
const item_name_trans = itemNameDict[item_name] || item_name;
|
||||
$amount_item_name.nodeValue = `个[${item_name_trans}],总计$`;
|
||||
}
|
||||
const $confirm_a = $confirm.querySelectorAll('span.confirm-act a');
|
||||
$confirm_a.forEach(e => {
|
||||
if (npcShopDict[e.innerText.trim()]) e.innerText = npcShopDict[e.innerText.trim()];
|
||||
});
|
||||
});
|
||||
// 展开的物品详情
|
||||
initOB($wrapper, {childList: true, subtree: true}, () => {
|
||||
const $item_desc = $wrapper.querySelector('.show-item-info');
|
||||
showItemInfoTrans($item_desc);
|
||||
});
|
||||
// [卖出部分]
|
||||
const $sell_items_wrapper = $wrapper.querySelector('.sell-items-wrap');
|
||||
// 黑框标题
|
||||
const $title = $sell_items_wrapper.querySelectorAll('ul.title li');
|
||||
$title.forEach(el => {
|
||||
el.childNodes.forEach(e => {
|
||||
if (e.nodeType === 1) {
|
||||
if (npcShopDict[e.innerText.trim()]) e.innerText = npcShopDict[e.innerText.trim()];
|
||||
} else {
|
||||
if (npcShopDict[e.nodeValue.trim()]) e.nodeValue = npcShopDict[e.nodeValue.trim()];
|
||||
}
|
||||
});
|
||||
});
|
||||
// 物品名
|
||||
const $items_name = $sell_items_wrapper.querySelectorAll('span.name');
|
||||
$items_name.forEach(el => {
|
||||
if (itemNameDict[el.innerText.trim()]) el.innerText +=
|
||||
` ${itemNameDict[el.innerText.trim()]}`;
|
||||
});
|
||||
// 按钮
|
||||
const $btn = $sell_items_wrapper.querySelectorAll('button');
|
||||
$btn.forEach(e => {
|
||||
if (npcShopDict[e.innerText.trim()]) e.innerText = npcShopDict[e.innerText.trim()];
|
||||
});
|
||||
// select btn
|
||||
const $select_btn = $sell_items_wrapper.querySelector('li.select button.wai-btn');
|
||||
if ($select_btn) {
|
||||
initOB($select_btn, {childList: true}, () => {
|
||||
if ($select_btn && npcShopDict[$select_btn.innerText.trim()]) {
|
||||
$select_btn.innerText = npcShopDict[$select_btn.innerText.trim()];
|
||||
}
|
||||
});
|
||||
}
|
||||
// 取消按钮
|
||||
const $cancel = $sell_items_wrapper.querySelector('span.cancel a');
|
||||
if ($cancel && npcShopDict[$cancel.innerText.trim()]) {
|
||||
$cancel.innerText = npcShopDict[$cancel.innerText.trim()];
|
||||
}
|
||||
// 卖出确认文字
|
||||
const $sell_confirm = $sell_items_wrapper.querySelector('div.sell-confirm');
|
||||
if ($sell_confirm) {
|
||||
const $msg = $sell_confirm.childNodes[0];
|
||||
if (npcShopDict[$msg.nodeValue.trim()]) $msg.nodeValue = npcShopDict[$msg.nodeValue.trim()];
|
||||
const $total_value = $sell_confirm.querySelector('span.profit').childNodes[0];
|
||||
if (npcShopDict[$total_value.nodeValue.trim()]) $total_value.nodeValue = npcShopDict[$total_value.nodeValue.trim()];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务
|
||||
*/
|
||||
@ -4641,37 +4763,7 @@
|
||||
});
|
||||
// 展开详细框
|
||||
const $show_item_info = $display_cabinet.querySelector('.show-item-info');
|
||||
if ($show_item_info) {
|
||||
// tt插件
|
||||
const is_tt_modified = !!$show_item_info.querySelector('.tt-modified');
|
||||
if (is_tt_modified) {
|
||||
console.warn(is_tt_modified)
|
||||
}
|
||||
// 物品名
|
||||
const $item_name = $show_item_info.querySelector('span.bold');
|
||||
// 去除物品名的the
|
||||
const the_removed = $item_name.innerText.trim().slice(4);
|
||||
// 物品的类别
|
||||
const $item_type = $item_name.nextSibling;
|
||||
// 绿字 物品效果
|
||||
const $item_effect = $show_item_info.querySelector('div.item-effect');
|
||||
if (itemNameDict[the_removed]) {
|
||||
$item_name.innerText = `${itemNameDict[the_removed]}(${the_removed})`;
|
||||
}
|
||||
if (itemTypeDict[$item_type.nodeValue.trim()]) {
|
||||
$item_type.nodeValue = itemTypeDict[$item_type.nodeValue.trim()];
|
||||
}
|
||||
if ($item_effect && itemEffectDict[$item_effect.innerText.trim()]) {
|
||||
$item_effect.innerText = itemEffectDict[$item_effect.innerText.trim()];
|
||||
}
|
||||
// 下方的表格
|
||||
const $info_table_title = $show_item_info.querySelectorAll('div.title');
|
||||
$info_table_title.forEach((e) => {
|
||||
if (itemPageDict[e.innerText.trim()]) {
|
||||
e.innerText = itemPageDict[e.innerText.trim()];
|
||||
}
|
||||
});
|
||||
}
|
||||
showItemInfoTrans($show_item_info);
|
||||
}
|
||||
});
|
||||
return;
|
||||
@ -5714,20 +5806,20 @@
|
||||
* 页标题右侧按钮
|
||||
*/
|
||||
function contentTitleLinksTrans() {
|
||||
const $links_default = $('div.content-title span:nth-child(2)');
|
||||
const $links_default = document.querySelectorAll('div.content-title span:nth-child(2)');
|
||||
const $links = $links_default.length === 0
|
||||
? $('div[class^="topSection"] span[class*="Title"]')
|
||||
? document.querySelectorAll('div[class^="topSection"] span[class*="Title"]')
|
||||
: $links_default;
|
||||
$links.each((i, e) => {
|
||||
if (titleLinksDict[$(e).text()]) {
|
||||
$(e).text(titleLinksDict[$(e).text()]);
|
||||
} else if ($(e).attr('id') === 'events') {
|
||||
if (titleLinksDict[$(e).text().split(' ')[0]])
|
||||
$(e).text($(e).text()
|
||||
$links.forEach(e => {
|
||||
if (titleLinksDict[e.innerText.trim()]) {
|
||||
e.innerText = titleLinksDict[e.innerText.trim()];
|
||||
} else if (e.id === 'events') {
|
||||
if (titleLinksDict[e.innerText.trim().split(' ')[0]])
|
||||
e.innerText = e.innerText.trim()
|
||||
.replace(
|
||||
$(e).text().split(' ')[0],
|
||||
titleLinksDict[$(e).text().split(' ')[0]]
|
||||
));
|
||||
e.innerText.trim().split(' ')[0],
|
||||
titleLinksDict[e.innerText.trim().split(' ')[0]]
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -5737,7 +5829,7 @@
|
||||
*/
|
||||
function titleTrans() {
|
||||
const $title = $('h4#skip-to-content').length === 0 ? $('h4[class^="title"]') : $('h4#skip-to-content');
|
||||
const title = titleDict[$title.text().trim()];
|
||||
const title = titleDict[$title.text().trim()] || cityDict[$title.text().trim()];
|
||||
if (title && $title.css('display') !== 'none')
|
||||
$title.after($title.clone().text(title)).css('display', 'none');
|
||||
}
|
||||
@ -5829,6 +5921,46 @@ ${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10">
|
||||
return itemNameDict[str] || str;
|
||||
}
|
||||
|
||||
/*
|
||||
展开物品详情
|
||||
*/
|
||||
function showItemInfoTrans(dom = document.querySelector('.show-item-info')) {
|
||||
if (dom) {
|
||||
const $item_info = dom.querySelector('span.info-msg');
|
||||
if ($item_info) {
|
||||
// tt插件
|
||||
const is_tt_modified = !!$item_info.querySelector('.tt-modified');
|
||||
if (is_tt_modified) {
|
||||
console.warn(is_tt_modified)
|
||||
}
|
||||
// 物品名
|
||||
const $item_name = $item_info.querySelector('span.bold');
|
||||
// 去除物品名的the
|
||||
const the_removed = $item_name.innerText.trim().slice(4);
|
||||
// 物品的类别
|
||||
const $item_type = $item_name.nextSibling;
|
||||
// 绿字 物品效果
|
||||
const $item_effect = $item_info.querySelector('div.item-effect');
|
||||
if (itemNameDict[the_removed]) {
|
||||
$item_name.innerText = `${itemNameDict[the_removed]}(${the_removed})`;
|
||||
}
|
||||
if (itemTypeDict[$item_type.nodeValue.trim()]) {
|
||||
$item_type.nodeValue = itemTypeDict[$item_type.nodeValue.trim()];
|
||||
}
|
||||
if ($item_effect && itemEffectDict[$item_effect.innerText.trim()]) {
|
||||
$item_effect.innerText = itemEffectDict[$item_effect.innerText.trim()];
|
||||
}
|
||||
}
|
||||
// 下方的表格
|
||||
const $info_table_title = dom.querySelectorAll('div.title');
|
||||
$info_table_title.forEach((e) => {
|
||||
if (itemPageDict[e.innerText.trim()]) {
|
||||
e.innerText = itemPageDict[e.innerText.trim()];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ob
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user