diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 73d6bb1..c4b302d 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -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': '个人统计信息', @@ -2339,11 +2348,11 @@ 'is a Jewelry Item.': '是一种珠宝物品。', 'is a Flower Item.': '是一种花。', 'is a Plushie Item.': '是一种玩偶。', - 'is a class E Car Item.': '是一辆E级赛车。', - 'is a class D Car Item.': '是一辆D级赛车。', - 'is a class C Car Item.': '是一辆C级赛车。', - 'is a class B Car Item.': '是一辆B级赛车。', - 'is a class A Car Item.': '是一辆A级赛车。', + 'is a class E Car Item.': '是一辆E级赛车。', + 'is a class D Car Item.': '是一辆D级赛车。', + 'is a class C Car Item.': '是一辆C级赛车。', + 'is a class B Car Item.': '是一辆B级赛车。', + 'is a class A Car Item.': '是一辆A级赛车。', 'is a Virus Item.': '是一种电脑病毒。', 'is an Other Item.': '是一个其他物品。', 'is a Book Item.': '是一本书。', @@ -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,100 +3584,122 @@ 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()})`; + if ($buy_items_wrapper) { + // 黑框标题 + const $buy_black_title = $buy_items_wrapper.querySelector('.title-black'); + if ($buy_black_title && npcShopDict[$buy_black_title.firstChild.nodeValue.trim()]) { + $buy_black_title.firstChild.nodeValue = npcShopDict[$buy_black_title.firstChild.nodeValue.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()]; + // 各个物品 + 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()]; + }); }); - // 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') || $wrapper.querySelector('.view-item-info'); + showItemInfoTrans($item_desc); }); - }); - // 展开的物品详情 - 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 $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()]; - } + 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()]; + 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'); - $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 $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()]; + } } - // 取消按钮 - 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 $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; }