From 70ce199f4f5b449ea12deb38092123ef7da194b6 Mon Sep 17 00:00:00 2001 From: woohoo Date: Wed, 1 Dec 2021 20:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=A9=E5=93=81=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=BF=BB=E8=AF=91=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 84 +++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 0fdde3c..4cb8c3b 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Torn翻译 // @namespace WOOH -// @version 0.1.1130b +// @version 0.1.1201a // @description Torn UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* @@ -2182,6 +2182,9 @@ const itemDescDict = { 'A lottery voucher which can be traded in for 100 lottery tickets for the weekly draw, courtesy of the Lucky Shot Casino.': '', + "Increases one's energy.": '提高能量。', + "Temporarily passively increases all statistics while attacking or defending by 25%.": + '在攻击或防守时暂时地获得25%战斗属性增益。', }; const itemEffectDict = { // 彩票 @@ -2221,6 +2224,7 @@ 'is a Book Item.': '是一本书。', 'is a Special Item.': '是一种特殊物品。', }; + const itemReqDict = {}; const tornSettingsDict = { 'API Keys': 'API 密钥', 'General settings': '通用设置', @@ -3008,7 +3012,7 @@ const [hours, minutes] = spl.length === 5 ? [parseInt(spl[0]), parseInt(spl[3])] : [0, parseInt(spl[0])]; - if (fullEnergyTime < (hours * 60 + minutes)*2) { + if (fullEnergyTime < (hours * 60 + minutes) * 2) { if (!$(e).parent().hasClass('wh-translated')) { $(e).parent() .prepend(`
警告:该次飞行往返时间大于体力回复时间,将会爆体!
`) @@ -3280,14 +3284,15 @@ * 物品页面 */ if (window.location.href.contains(/item\.php/)) { - // let count = 0; const $$ = $('.content-wrapper'); const options = { - characterData: false, + characterData: true, attributes: false, subtree: true, childList: true, }; + // let isAllItemTrans = false; + const translated = {cat: '', count: -1}; const OB = new MutationObserver(() => { OB.disconnect(); titleTrans(); @@ -3306,39 +3311,54 @@ const $cat = $('div.title-black span.items-name'); if (itemPageDict[$cat.text().trim()]) $cat.text(itemPageDict[$cat.text().trim()]); // 物品名翻译 - const $item_name = $('ul.current-cont').length === 0 - ? $('ul#items-search-tab').children().length === 0 - ? $('ul#all-items span.name') - : $('ul#items-search-tab span.name') - : $('ul.current-cont span.name'); - $item_name.each((i, e) => { - if (!$(e).hasClass('wh-translated')) { - if (itemNameDict[$(e).text().trim()]) { - $(e).addClass('wh-translated') - .after(`${itemNameDict[$(e).text().trim()]}`); + const $active_item_list = $('ul.itemsList[aria-expanded="true"] span.name'); + const $active_tab = $('ul.itemsList[aria-expanded="true"]'); + const itemCat = $active_tab.attr('id'); + if ($active_item_list.length - 1 !== translated.count || itemCat !== translated.cat) { + let count = -1; + $active_item_list.each((i, e) => { + if (!$(e).hasClass('wh-translated')) { + if (itemNameDict[$(e).text().trim()]) { + $(e).addClass('wh-translated') + .after(`${itemNameDict[$(e).text().trim()]}`); + } } + count = i; + }); + if (count !== -1) { + translated.cat = itemCat; + translated.count = count; } - }); + } else { + //console.log('已翻译过了') + } // 物品详情 const $item_info = $('li.show-item-info div.item-cont span.info-msg'); - $item_info.contents().each((i, e) => { - // 物品描述 - if (e.nodeType !== 3) return; - if (itemDescDict[e.nodeValue.trim()]) e.nodeValue = itemDescDict[e.nodeValue.trim()]; - }); - $item_info.find('*').contents().each((i, e) => { - // the+物品名 物品种类 效果 - if (e.nodeType !== 3) return; - if (e.nodeValue.trim() === '') return; - if (i === 3) { - if (itemNameDict[e.nodeValue.trim().slice(4)]) { - e.nodeValue = itemNameDict[e.nodeValue.trim().slice(4)]; - } - return; + $item_info.each((i, e) => { + // torntools 插件 + const isTTModified = $(e).hasClass('tt-modified'); + if (isTTModified) { + } + const itemName = e.children[0].children[0]; //大麻1 + const itemType = e.children[0].childNodes[2]; //itemType.nodeValue + const itemDesc = e.childNodes[2]; //itemDesc.nodeValue + const itemEffect = $(e).children('div.t-green.item-effect').get(0) || null; + const itemReq = $(e).children('div.t-red.item-effect').get(0) || null; + if (itemNameDict[itemName.innerText.trim().slice(4)]) { + itemName.innerText = itemNameDict[itemName.innerText.trim().slice(4)]; + } + if (itemTypeDict[itemType.nodeValue.trim()]) { + itemType.nodeValue = itemTypeDict[itemType.nodeValue.trim()]; + } + if (itemDescDict[itemDesc.nodeValue.trim()]) { + itemDesc.nodeValue = itemDescDict[itemDesc.nodeValue.trim()]; + } + if (itemEffect && itemEffectDict[itemEffect.innerText.trim()]) { + itemEffect.innerText = itemEffectDict[itemEffect.innerText.trim()]; + } + if (itemReq && itemReqDict[itemReq.innerText.trim()]) { + itemReq.innerText = itemReqDict[itemReq.innerText.trim()]; } - //console.log(e.nodeValue.trim()) - if (itemTypeDict[e.nodeValue.trim()]) e.nodeValue = itemTypeDict[e.nodeValue.trim()]; - else if (itemEffectDict[e.nodeValue.trim()]) e.nodeValue = itemEffectDict[e.nodeValue.trim()]; }); }; trans();