增加适配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== // ==UserScript==
// @lastmodified 202112111613 // @lastmodified 202112111702
// @name Torn翻译 // @name Torn翻译
// @namespace WOOH // @namespace WOOH
// @version 0.1.1211b // @version 0.1.1211c
// @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.1211c',
date: '20211211',
cont: `增加适配npc pt商店及卖出框的标题`,
},
{ {
ver: '0.1.1211b', ver: '0.1.1211b',
date: '20211211', date: '20211211',
@ -79,6 +84,10 @@
'Items': '物品仓库', 'Items': '物品仓库',
'Travel Agency': '旅行社', 'Travel Agency': '旅行社',
'Display Cabinet': '展示柜', 'Display Cabinet': '展示柜',
'Torn Docks': '码头车行',
'Nikeh Sports Shop': '耐克哈运动专卖',
'Torn City Super Store': '电器商店',
"Sally's Sweet Shop": '莎莉的糖果店',
}; };
const titleLinksDict = { const titleLinksDict = {
'Personal stats': '个人统计信息', 'Personal stats': '个人统计信息',
@ -2339,11 +2348,11 @@
'is a Jewelry Item.': '是一种珠宝物品。', 'is a Jewelry Item.': '是一种珠宝物品。',
'is a Flower Item.': '是一种花。', 'is a Flower Item.': '是一种花。',
'is a Plushie Item.': '是一种玩偶。', 'is a Plushie Item.': '是一种玩偶。',
'is a class E Car Item.': '是一辆E级赛车。', 'is a class E Car Item.': '是一辆E级赛车。',
'is a class D Car Item.': '是一辆D级赛车。', 'is a class D Car Item.': '是一辆D级赛车。',
'is a class C Car Item.': '是一辆C级赛车。', 'is a class C Car Item.': '是一辆C级赛车。',
'is a class B Car Item.': '是一辆B级赛车。', 'is a class B Car Item.': '是一辆B级赛车。',
'is a class A Car Item.': '是一辆A级赛车。', 'is a class A Car Item.': '是一辆A级赛车。',
'is a Virus Item.': '是一种电脑病毒。', 'is a Virus Item.': '是一种电脑病毒。',
'is an Other Item.': '是一个其他物品。', 'is an Other Item.': '是一个其他物品。',
'is a Book Item.': '是一本书。', 'is a Book Item.': '是一本书。',
@ -2712,6 +2721,7 @@
"Yes": '是', "Yes": '是',
"No": '否', "No": '否',
"Are you sure you would like to buy": '你是否想买', "Are you sure you would like to buy": '你是否想买',
"Sell your points": '出售你的PT',
}; };
// 默认开启通知翻译 // 默认开启通知翻译
@ -3563,7 +3573,7 @@
/* /*
npc商店 npc商店
*/ */
if (window.location.href.contains(/shops\.php/)) { if (window.location.href.contains(/(shops|bigalgunshop)\.php/)) {
// 标题和右边的链接 // 标题和右边的链接
const $cont_title = document.querySelector('.content-title'); const $cont_title = document.querySelector('.content-title');
initOB($cont_title, {childList: true, subtree: true}, initOB($cont_title, {childList: true, subtree: true},
@ -3574,100 +3584,122 @@
const $wrapper = document.querySelector('.content-wrapper'); const $wrapper = document.querySelector('.content-wrapper');
// [购买部分] // [购买部分]
const $buy_items_wrapper = $wrapper.querySelector('.buy-items-wrap'); 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()]) { const $buy_black_title = $buy_items_wrapper.querySelector('.title-black');
$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()];
// 各个物品
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'); const $items = $buy_items_wrapper.querySelectorAll('ul.items-list > li.torn-divider');
if ($item_stock) $item_stock.childNodes.forEach(e => { $items.forEach(e => {
if (e.nodeType === 1) { // 物品名
if (npcShopDict[e.innerText.trim()]) e.innerText = npcShopDict[e.innerText.trim()]; const $item_name = e.querySelector('span.desc span.name.bold');
} else { if ($item_name && itemNameDict[$item_name.innerText.trim()]) {
if (npcShopDict[e.nodeValue.trim()]) e.nodeValue = npcShopDict[e.nodeValue.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()];
});
}); });
// buy按钮 // 展开的物品详情
const $buy_btn = e.querySelector('button.wai-support'); initOB($wrapper, {childList: true, subtree: true}, () => {
if ($buy_btn && npcShopDict[$buy_btn.childNodes[0].nodeValue.trim()]) { const $item_desc = $wrapper.querySelector('.show-item-info') || $wrapper.querySelector('.view-item-info');
$buy_btn.childNodes[0].nodeValue = npcShopDict[$buy_btn.childNodes[0].nodeValue.trim()]; showItemInfoTrans($item_desc);
}
// 买前确认
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') || $wrapper.querySelector('.view-item-info');
showItemInfoTrans($item_desc);
});
// [卖出部分] // [卖出部分]
const $sell_items_wrapper = $wrapper.querySelector('.sell-items-wrap'); 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 => { const $title = $sell_items_wrapper.querySelectorAll('ul.title li');
el.childNodes.forEach(e => { $title.forEach(el => {
if (e.nodeType === 1) { el.childNodes.forEach(e => {
if (npcShopDict[e.innerText.trim()]) e.innerText = npcShopDict[e.innerText.trim()]; if (e.nodeType === 1) {
} else { if (npcShopDict[e.innerText.trim()]) {
if (npcShopDict[e.nodeValue.trim()]) e.nodeValue = npcShopDict[e.nodeValue.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()];
}
});
}); });
}); // 物品名
// 物品名 const $items_name = $sell_items_wrapper.querySelectorAll('span.name');
const $items_name = $sell_items_wrapper.querySelectorAll('span.name'); $items_name.forEach(el => {
$items_name.forEach(el => { if (itemNameDict[el.innerText.trim()]) el.innerText +=
if (itemNameDict[el.innerText.trim()]) el.innerText += ` ${itemNameDict[el.innerText.trim()]}`;
` ${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 $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()];
}
} }
// 取消按钮 // [出售PT部分]
const $cancel = $sell_items_wrapper.querySelector('span.cancel a'); const $sell_pt_wrapper = $wrapper.querySelector('.sell-points-wrap');
if ($cancel && npcShopDict[$cancel.innerText.trim()]) { if ($sell_pt_wrapper) {
$cancel.innerText = npcShopDict[$cancel.innerText.trim()]; // 黑框
} const $title_black = $sell_pt_wrapper.querySelector('.title-black');
// 卖出确认文字 if (npcShopDict[$title_black.innerText.trim()]) {
const $sell_confirm = $sell_items_wrapper.querySelector('div.sell-confirm'); $title_black.innerText = npcShopDict[$title_black.innerText.trim()];
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; return;
} }