From 695d22bb235abc006dc539abc884bfb066c1f7c2 Mon Sep 17 00:00:00 2001 From: woohoo Date: Tue, 16 Nov 2021 11:35:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E3=80=81=E6=88=BF=E4=BA=A7=E9=A1=B5=E9=9D=A2=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E3=80=81=E4=B8=BB=E9=A1=B5=E7=BF=BB=E8=AF=91=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E3=80=81=E5=AD=97=E6=AE=B5=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 300 +++++++++++++++++++++++++--------------- 1 file changed, 186 insertions(+), 114 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index b87faee..a21c815 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.1114b +// @version 0.1.1116a // @description UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* @@ -24,6 +24,7 @@ 'Freebies': '赠品', 'Classified Ads': '分类广告', 'Properties': '房产', + 'All Properties': '所有房产', 'City': '城市', 'Education': '教育', 'Gym': '健身房', @@ -103,7 +104,7 @@ 'Friends': '好友', 'Enemies': '敌人', 'Information': '信息', - //'Areas': '区域', + 'Areas': '区域', 'Lists': '列表', 'messages': '信息', 'events': '通知', @@ -234,7 +235,7 @@ 'Ranch': '山庄', 'Palace': '宫殿', 'Castle': '城堡', - 'Private Island': '私人岛屿(PI)', + 'Private Island': '私人岛屿 (PI)', 'Owner': '所有人', 'Owner:': '所有人:', 'Happiness': '快乐值', @@ -251,6 +252,23 @@ 'Modifications': '改造设施', 'Upkeep:': '维护费:', 'Staff:': '雇员费用:', + 'Leased to': '租给了 ', + 'Owned by your spouse': '为你的配偶所有', + 'Owned by you': '为你所有', + 'All Properties': '所有房产', + 'Your Properties': '你的房产', + "Spouse's Properties": '配偶的房产', + "Spouse's": '配偶的', + 'All': '所有', + 'Yours': '你的', + 'Customize this property': '自定义该房产', + 'Travel': '起飞', + 'Kick your spouse out of this property': '把你的配偶赶出该房产', + 'Pay upkeep': '支付维护费', + 'Move into this property': '搬进该房产', + 'Sell this property': '出售该房产', + 'Lease this property': '出租该房产', + 'Give this property to someone': '赠送该房产给某人', }; const travelingDict = { 'Remaining Flight Time -': '剩余时间 - ', @@ -759,7 +777,9 @@ 'Rank': '阶级', 'Networth': '身价', 'SPEND': '升级', + 'CHANGE': '更改', 'Cancel': '取消', + 'Are you sure you want to change your name background to this Honor?': '确定修改你的名字背景为这个荣誉吗?', 'Nerve Bar': '犯罪N上限', 'Critical Hit Rate': '暴击率', @@ -844,7 +864,7 @@ 'This upgrade will increase the amount of items you can find in the city, however it will not necessarily increase their quality.': '该升级会增加你在城市中能找到的物品数量,但不一定能提高它们的质量。', 'This upgrade will give you an increase of 5% to your investment bank interest. This upgrade will start working on your next investment.': - '这一升级将使你的银行利息增加 5%。这项升级将在你开始的下一个教育课程中开始生效。', + '这一升级将使你的银行利息增加 5%。这项升级将在下一次银行投资中生效。', 'This upgrade will give you a 5% boost in money that you mug from opponents. Perfect for experienced muggers, looking for some extra cash.': '这个升级将使你从对手那里抢来的钱增加5%。非常适合有经验的抢劫者,赚些额外的钱钱。', "This upgrade will make you more likely to stay stealthed when beating an opponent by increasing your stealth level by 0.2 per increment. When you're stealthed, your name will be listed as 'Someone' so your enemy will not know who hit them.": @@ -904,8 +924,14 @@ } // 边栏块标题 $('h2[class^="header"]').each((i, e) => { - if (sidebarDict[e.firstChild.nodeValue]) - e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; + if (!sidebarDict[e.firstChild.nodeValue]) return; + e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; + // if ($(e).css('display')!=='none' && sidebarDict[e.firstChild.nodeValue]) { + // let original=$(e).clone(true); + // original.text(original.text().replace(e.firstChild.nodeValue,sidebarDict[e.firstChild.nodeValue])); + // $(e).css('display', 'none').after(original); + // $(original).append($(e).children('i')); + // } }); // 边栏人物名字 $('span[class^="menu-name"]').each((i, e) => { @@ -938,6 +964,13 @@ e.nodeValue = sidebarDict[e.nodeValue]; }); + // let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); + // if (barDescr.length !== 0) { + // barDescr[0].childNodes.forEach(i => { + // if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue]; + // }) + // } + clearInterval(sidebarInterval); }, 1000); @@ -951,20 +984,7 @@ miniprofOB.observe($('div.profile-mini-root').get(0), {attributes: true, childList: true, subtree: true}); }); const miniprofTrans = function miniprofTrans() { - // let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); - // if (barDescr.length !== 0) { - // barDescr[0].childNodes.forEach(i => { - // if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue]; - // }) - // } - // let miniprof_tooltip = $("#body > div.ToolTipPortal > div > div:nth-child(2)"); - // if (miniprof_tooltip.length !== 0) { - // if (tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]) { - // miniprof_tooltip[0].firstChild.nodeValue = tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]; - // } - // } else { - // //todo 通配符匹配 - // } + // console.log('111'); }; if ($('div.profile-mini-root').length > 0) miniprofTrans(); @@ -1192,13 +1212,18 @@ titleTrans(); contentTitleLinksTrans(); - let homeEvents = null; + //let homeEvents = null; + // 主页黑框标题文字翻译 $('h5.box-title').each((i, e) => { if (!homeDict[e.firstChild.nodeValue]) return; + // 翻译最近5条通知 if (e.firstChild.nodeValue === 'Latest Events') { - homeEvents = $(e).parent().next().find('span'); - } else if (e.firstChild.nodeValue === 'Latest Attacks') { + //homeEvents = $(e).parent().next().find('span'); + eventsTrans($(e).parent().next().find('span')); + } + // 翻译最近5个攻击 + else if (e.firstChild.nodeValue === 'Latest Attacks') { $(e).parent().next().find('span').each(function () { let nodes = $(this)[0].childNodes; nodes.forEach((v, i) => { @@ -1219,16 +1244,18 @@ }, this); }); } - e.firstChild.nodeValue = homeDict[e.firstChild.nodeValue]; + //e.firstChild.nodeValue = homeDict[e.firstChild.nodeValue]; + // 隐藏原dom元素避免与torntools发生冲突 + if ($(e).css('display')!=='none') + $(e).css('display','none').after(`
`+homeDict[e.firstChild.nodeValue]+`
`); }); + // 各表格左边的键 $('span.divider span').each((i, e) => { if (homeDict[$(e).text()]) $(e).text(homeDict[$(e).text()]); }); - eventsTrans(homeEvents); - return; } @@ -1615,109 +1642,135 @@ } /** - * properties 从玩家租买和自己的房子页面 + * properties todo */ if (window.location.href.indexOf('properties.php') >= 0) { const isRent = window.location.href.indexOf('rent') >= 0; + // const isRentOrSell = isRent || window.location.href.indexOf('sell') >= 0; + // const isOption = window.location.href.indexOf('p=options') >= 0; + // const isExtension = window.location.href.indexOf('step=viewOfferExtension') >= 0; const propertyOB = new MutationObserver(() => { propertyOB.disconnect(); titleTrans(); contentTitleLinksTrans(); propertyTrans(); - propertyOB.observe($('div#properties-page-wrap')[0], {childList: true, subtree: true}); + propertyOB.observe($('div.content-wrapper').get(0), {childList: true, subtree: true}); }); const propertyTrans = function propertyTrans() { - // 黑框标题 - $('div.title-black span').each((i, e) => { - e.firstChild.nodeValue = '您想查看哪些房产?'; - }); - // 房屋汉化 - $('ul.info-cont label.marker-css').contents().each((i, e) => { - if (propertyDict[e.nodeValue]) - e.nodeValue = propertyDict[e.nodeValue]; - }); - //搜索按钮 - $('div.btn-search button').text('搜索'); - $('div.search-text a').text('搜索'); - // 表头信息 - $('div.users-list-title div').each((i, e) => { - if (propertyDict[$(e).text()]) - $(e).text(propertyDict[$(e).text()]); - }); - // 确认购买提示 - /** - -

Are you sure you want to rent this Castle

-

for $4,000,000 for a period of 30 days?

- Yes - No -
+ // 从玩家处租或买 + if (isRent || window.location.href.indexOf('sell') >= 0) { + // 黑框标题 + $('div.title-black span').each((i, e) => { + e.firstChild.nodeValue = '您想查看哪些房产?'; + }); + // 房屋汉化 + $('ul.info-cont label.marker-css').contents().each((i, e) => { + if (propertyDict[e.nodeValue]) + e.nodeValue = propertyDict[e.nodeValue]; + }); + //搜索按钮 + $('div.btn-search button').text('搜索'); + $('div.search-text a').text('搜索'); + // 表头信息 + $('div.users-list-title div').each((i, e) => { + if (propertyDict[$(e).text()]) + $(e).text(propertyDict[$(e).text()]); + }); + // 确认购买提示 + $('div[class="confirm-text"] span.question').each((i, e) => { + const propName = e.firstElementChild.innerText.trim().split(' ').slice(8).join(' '); - -

Are you sure you want to buy another Private Island

-

for $1,705,000,000?

- Yes - No -
- */ - $('div[class="confirm-text"] span.question').each((i, e) => { - const propName = e.firstElementChild.innerText.trim().split(' ').slice(8).join(' '); + const hasAnother = $(e).text().indexOf('another') > 0; + if (hasAnother) { + e.firstElementChild.firstChild.nodeValue = '你确定要'; + e.firstElementChild.firstChild.nodeValue += isRent ? '租用' : '购买'; + e.firstElementChild.childNodes[1].firstChild.nodeValue = '另一个'; + e.firstElementChild.childNodes[2].nodeValue = propertyDict[propName]; + } else { + e.firstElementChild.firstChild.nodeValue = '你确定要'; + e.firstElementChild.firstChild.nodeValue += isRent ? '租用' : '购买'; + e.firstElementChild.firstChild.nodeValue += propertyDict[propName]; + } + e.children[1].firstChild.nodeValue = '花费 '; + e.children[1].childNodes[2].nodeValue = isRent ? ' 租期 ' : '?'; + if (isRent) + e.children[1].childNodes[4].nodeValue = ' 天?'; + }); - const hasAnother = $(e).text().indexOf('another') > 0; - if (hasAnother) { - e.firstElementChild.firstChild.nodeValue = '你确定要'; - e.firstElementChild.firstChild.nodeValue += isRent ? '租用' : '购买'; - e.firstElementChild.childNodes[1].firstChild.nodeValue = '另一个'; - e.firstElementChild.childNodes[2].nodeValue = propertyDict[propName]; - } else { - e.firstElementChild.firstChild.nodeValue = '你确定要'; - e.firstElementChild.firstChild.nodeValue += isRent ? '租用' : '购买'; - e.firstElementChild.firstChild.nodeValue += propertyDict[propName]; - } - e.children[1].firstChild.nodeValue = '花费 '; - e.children[1].childNodes[2].nodeValue = isRent ? ' 租期 ' : '?'; - if (isRent) - e.children[1].childNodes[4].nodeValue = ' 天?'; - }); - - // 房屋详情表格 - $('div.info-block span.bold').each((i, e) => { - if (e.childElementCount === 2) { - /** - * - On - "Market" - Price - ":" - - */ - e.firstElementChild.firstChild.nodeValue = ''; - e.childNodes[2].nodeValue = '市场价'; - e.childNodes[3].firstChild.nodeValue = ''; - e.childNodes[4].nodeValue = ':'; - } else { + // 房屋详情表格 + $('div.info-block span.bold').each((i, e) => { + if (e.childElementCount === 2) { + /** + * + On + "Market" + Price + ":" + + */ + e.firstElementChild.firstChild.nodeValue = ''; + e.childNodes[2].nodeValue = '市场价'; + e.childNodes[3].firstChild.nodeValue = ''; + e.childNodes[4].nodeValue = ':'; + } else { + if (propertyDict[e.firstChild.nodeValue.trim()]) + e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue.trim()]; + } + }); + $('div.rental-period span.bold').each((i, e) => { if (propertyDict[e.firstChild.nodeValue.trim()]) e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue.trim()]; - } - }); - $('div.rental-period span.bold').each((i, e) => { - if (propertyDict[e.firstChild.nodeValue.trim()]) - e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue.trim()]; - }); - // 窄边 cost happy - $('span.title-laptop.bold').each((i, e) => { - if (propertyDict[$(e).text().trim()]) - $(e).text(propertyDict[$(e).text().trim()]); - }); - // modification - $('div.title.bold.left').each((i, e) => { - if (propertyDict[e.firstChild.nodeValue]) - e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue]; - }); + }); + // 窄边 cost happy + $('span.title-laptop.bold').each((i, e) => { + if (propertyDict[$(e).text().trim()]) + $(e).text(propertyDict[$(e).text().trim()]); + }); + // modification + $('div.title.bold.left').each((i, e) => { + if (propertyDict[e.firstChild.nodeValue]) + e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue]; + }); + + return; + } + // 房屋选项 + if (window.location.href.indexOf('p=options') >= 0) { + return; + } + // 房屋详情 + if (window.location.href.indexOf('p=propertyinfo') >= 0) { + return; + } + // 延期、合同 + if (window.location.href.indexOf('step=viewOfferExtension') >= 0) { + return; + } + // 自己的所有房产 页面 + { + // 顶部3标题 + $('ul.property-tabs a.ui-tabs-anchor div').contents().each((i, e) => { + if (propertyDict[e.nodeValue]) { + e.nodeValue = propertyDict[e.nodeValue]; + } + }); + // 图片下的描述部分 + $('ul.properties-list div.image-description').find('*') + .contents().each((i, e) => { + if (e.nodeType !== 3) return; + if (!propertyDict[e.nodeValue.trim()]) return; + e.nodeValue = propertyDict[e.nodeValue.trim()]; + }); + // 图片下的按钮的title浮动框文字 + $('div#properties-page-wrap a[title]').each((i, e) => { + if (propertyDict[$(e).attr('title')]) + $(e).attr('title', propertyDict[$(e).attr('title')]); + }); + } }; propertyTrans(); - propertyOB.observe($('div#properties-page-wrap')[0], {childList: true, subtree: true}); + propertyOB.observe($('div.content-wrapper').get(0), {childList: true, subtree: true}); return; } @@ -1797,6 +1850,21 @@ if (awDict[desc]) $(e).attr('data-title', $(e).attr('data-title').replace(desc, awDict[desc])); }); + // 改变荣誉条时的提示 + $('div#honors div.msg').each((i,e)=>{ + if(awDict[$(e).text().trim()]) + $(e).text(awDict[$(e).text().trim()]); + }); + // 改变荣誉条时的提示按钮 change + $('div#honors div.confirm-msg button').each((i,e)=>{ + if(awDict[$(e).text().trim()]) + $(e).text(awDict[$(e).text().trim()]); + }); + // 改变荣誉条时的提示按钮 cancel + $('div#honors div.confirm-msg a.cancel').each((i,e)=>{ + if(awDict[$(e).text().trim()]) + $(e).text(awDict[$(e).text().trim()]); + }); // 技能页面 Available Merits: x Merits Used: x $('div.awards-msg p').contents().each((i, e) => { if (e.nodeType === 3) @@ -1887,7 +1955,9 @@ if (window.location.href.indexOf('level2.php') >= 0) { } - /** 医院页面 **/ + /** + * 医院页面 + */ if (window.location.href.indexOf("hospitalview.php") >= 0) { const hospitalOB = new MutationObserver(hosOBInit); @@ -1948,7 +2018,9 @@ return; } - /** 帮派页面 **/ + /** + * 帮派页面 + */ if (window.location.href.indexOf("actions.php") >= 0) { const factionOB = new MutationObserver(factionOBInit);