增加适配npc pt商店及卖出框的标题

This commit is contained in:
woohoo 2021-12-11 17:02:53 +08:00
parent 5bb8ada426
commit d0f1d2b325

View File

@ -1,8 +1,8 @@
// ==UserScript==
// @lastmodified 202112111613
// @lastmodified 202112111702
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1211b
// @version 0.1.1211c
// @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.1211c',
date: '20211211',
cont: `增加适配npc pt商店及卖出框的标题`,
},
{
ver: '0.1.1211b',
date: '20211211',
@ -79,6 +84,10 @@
'Items': '物品仓库',
'Travel Agency': '旅行社',
'Display Cabinet': '展示柜',
'Torn Docks': '码头车行',
'Nikeh Sports Shop': '耐克哈运动专卖',
'Torn City Super Store': '电器商店',
"Sally's Sweet Shop": '莎莉的糖果店',
};
const titleLinksDict = {
'Personal stats': '个人统计信息',
@ -2712,6 +2721,7 @@
"Yes": '是',
"No": '否',
"Are you sure you would like to buy": '你是否想买',
"Sell your points": '出售你的PT',
};
// 默认开启通知翻译
@ -3563,7 +3573,7 @@
/*
npc商店
*/
if (window.location.href.contains(/shops\.php/)) {
if (window.location.href.contains(/(shops|bigalgunshop)\.php/)) {
// 标题和右边的链接
const $cont_title = document.querySelector('.content-title');
initOB($cont_title, {childList: true, subtree: true},
@ -3574,9 +3584,10 @@
const $wrapper = document.querySelector('.content-wrapper');
// [购买部分]
const $buy_items_wrapper = $wrapper.querySelector('.buy-items-wrap');
if ($buy_items_wrapper) {
// 黑框标题
const $buy_black_title = $buy_items_wrapper.querySelector('.title-black');
if ($buy_black_title.firstChild.nodeValue && npcShopDict[$buy_black_title.firstChild.nodeValue.trim()]) {
if ($buy_black_title && npcShopDict[$buy_black_title.firstChild.nodeValue.trim()]) {
$buy_black_title.firstChild.nodeValue = npcShopDict[$buy_black_title.firstChild.nodeValue.trim()];
}
// 各个物品
@ -3623,14 +3634,25 @@
const $item_desc = $wrapper.querySelector('.show-item-info') || $wrapper.querySelector('.view-item-info');
showItemInfoTrans($item_desc);
});
}
// [卖出部分]
const $sell_items_wrapper = $wrapper.querySelector('.sell-items-wrap');
if ($sell_items_wrapper) {
// 黑框标题
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()];
if (npcShopDict[e.innerText.trim()]) {
e.innerText = npcShopDict[e.innerText.trim()];
return;
}
const spl = e.innerText.trim().split(' ');
if (spl.length > 3) {
const shop_name = spl[2] === 'the' ? spl.slice(3).join(' ') : spl.slice(2).join(' ');
const shop_name_trans = npcShopDict[shop_name] || titleDict[shop_name] || cityDict[shop_name] || null;
e.innerText = `物品给${shop_name_trans || shop_name}`;
}
} else {
if (npcShopDict[e.nodeValue.trim()]) e.nodeValue = npcShopDict[e.nodeValue.trim()];
}
@ -3669,6 +3691,16 @@
const $total_value = $sell_confirm.querySelector('span.profit').childNodes[0];
if (npcShopDict[$total_value.nodeValue.trim()]) $total_value.nodeValue = npcShopDict[$total_value.nodeValue.trim()];
}
}
// [出售PT部分]
const $sell_pt_wrapper = $wrapper.querySelector('.sell-points-wrap');
if ($sell_pt_wrapper) {
// 黑框
const $title_black = $sell_pt_wrapper.querySelector('.title-black');
if (npcShopDict[$title_black.innerText.trim()]) {
$title_black.innerText = npcShopDict[$title_black.innerText.trim()];
}
}
return;
}