From 36096527c6d8be384ae1341ca1bfc683798b8454 Mon Sep 17 00:00:00 2001 From: woohoo Date: Sat, 6 Nov 2021 20:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=88=BF=E5=B1=8B=E4=B9=B0?= =?UTF-8?q?=E5=8D=96=E7=A7=9F=E8=B5=81=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 122 +++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 51 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 71847ef..2280149 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -136,10 +136,10 @@ 'Personal stats': '个人统计信息', 'Log': '日志', 'Tell your story': '说出你的故事', - 'Rental Market':'租赁市场', - 'Selling Market':'销售市场', - 'City':'城市', - 'Back to Estate Agents':'返回地产中介', + 'Rental Market': '租赁市场', + 'Selling Market': '销售市场', + 'City': '城市', + 'Back to Estate Agents': '返回地产中介', }; const newspaperDict = { 'front page': '报纸头版', @@ -153,32 +153,32 @@ 'comics': '漫画', 'chronicles': '纪事档案馆', }; - const titleDict={ - 'Home':'主页', - 'Estate Agents':'地产中介', + const titleDict = { + 'Home': '主页', + 'Estate Agents': '地产中介', }; - const propertyDict={ - 'Trailer':'拖车', - 'Apartment':'公寓', - 'Semi - Detached':'半独立式住宅', - 'Detached House':'独立式住宅', - 'Beach House':'海滩小屋', - 'Chalet':'小别墅', - 'Villa':'别墅', - 'Penthouse':'顶层公寓', - 'Mansion':'豪宅', - 'Ranch':'山庄', - 'Palace':'宫殿', - 'Castle':'城堡', - 'Private Island':'私人岛屿(PI)', - 'Owner':'所有人', - 'Happiness':'快乐值', - 'Cost':'花费', - 'Cost per Day':'平均日花费', - 'Rental Period':'租期', - 'Rent':'租赁', - 'Info':'信息', - 'Buy':'购买', + const propertyDict = { + 'Trailer': '拖车', + 'Apartment': '公寓', + 'Semi - Detached': '半独立式住宅', + 'Detached House': '独立式住宅', + 'Beach House': '海滩小屋', + 'Chalet': '小别墅', + 'Villa': '别墅', + 'Penthouse': '顶层公寓', + 'Mansion': '豪宅', + 'Ranch': '山庄', + 'Palace': '宫殿', + 'Castle': '城堡', + 'Private Island': '私人岛屿(PI)', + 'Owner': '所有人', + 'Happiness': '快乐值', + 'Cost': '花费', + 'Cost per Day': '平均日花费', + 'Rental Period': '租期', + 'Rent': '租赁', + 'Info': '信息', + 'Buy': '购买', }; const travelingDict = { // todo jsonify 'Recruit Citizens': '招募玩家', @@ -421,25 +421,26 @@ * properties 从玩家租买和自己的房子页面 */ if (window.location.href.indexOf('properties.php') >= 0) { - const propertyOB=new MutationObserver(()=>{ + const isRent = window.location.href.indexOf('rent') >= 0; + const propertyOB = new MutationObserver(() => { propertyOB.disconnect(); titleTrans(); contentTitleLinksTrans(); // 黑框标题 - $('div.title-black span').each((i,e)=>{ - e.firstChild.nodeValue='您想查看哪些房产?'; + $('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]; + $('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.users-list-title div').each((i,e)=>{ - if(propertyDict[$(e).text()]) + $('div.users-list-title div').each((i, e) => { + if (propertyDict[$(e).text()]) $(e).text(propertyDict[$(e).text()]); }); // 提示确认购买 @@ -457,15 +458,34 @@ Yes No + 你确定要以2750万美元租用另一个私人岛屿,为期30天? */ - $('div[class="confirm-text"] span.question').each((i,e)=>{ - console.log($(e).text()); + $('div[class="confirm-text"] span.question').each((i, e) => { + const cost=e.children[1].innerText.trim().split(' ')[1]; + const period=isRent?e.children[1].innerText.trim().split(' ')[6]:null; + const propName=e.firstElementChild.innerText.trim().split(' ').slice(8).join(' '); + + const hasAnother=$(e).text().indexOf('another')>0; + // console.log(cost); + // console.log(period); + // console.log(propName); + if(hasAnother){ + e.firstElementChild.firstChild.nodeValue='你确定要'; + e.firstElementChild.firstChild.nodeValue+=isRent?'租用':'购买'; + e.firstElementChild.childNodes[1].firstChild.nodeValue='另一个'; + e.firstElementChild.childNodes[2].nodeValue=propName; + } + else{ + e.firstElementChild.firstChild.nodeValue='你确定要'; + e.firstElementChild.firstChild.nodeValue+=isRent?'租用':'购买'; + e.firstElementChild.firstChild.nodeValue+='另一个 '+propName; + } }); - propertyOB.observe($('div#properties-page-wrap')[0],{childList:true,subtree:true}); + propertyOB.observe($('div#properties-page-wrap')[0], {childList: true, subtree: true}); }); - propertyOB.observe($('div#properties-page-wrap')[0],{childList:true,subtree:true}); + propertyOB.observe($('div#properties-page-wrap')[0], {childList: true, subtree: true}); return; } @@ -964,16 +984,16 @@ */ if ($(e).text().indexOf('position') >= 0) { let prePos, curPos; - const node3Spl=e.childNodes[2].nodeValue.split(' to '); - if(node3Spl.length===2){ - prePos=node3Spl[0].slice(14,node3Spl[0].length); - curPos=node3Spl[1].slice(0,node3Spl[1].length-2); - }else{ + const node3Spl = e.childNodes[2].nodeValue.split(' to '); + if (node3Spl.length === 2) { + prePos = node3Spl[0].slice(14, node3Spl[0].length); + curPos = node3Spl[1].slice(0, node3Spl[1].length - 2); + } else { console.log('职位出现" to "');// todo return; } - e.firstChild.nodeValue='你在 '; - e.childNodes[2].nodeValue=' 的职位从 '+prePos+' 变为 '+curPos+'。'; + e.firstChild.nodeValue = '你在 '; + e.childNodes[2].nodeValue = ' 的职位从 ' + prePos + ' 变为 ' + curPos + '。'; return; } @@ -1003,9 +1023,9 @@ /** * 页标题翻译 */ - function titleTrans(){ - if($('h4#skip-to-content').length===1) - if(titleDict[$('h4#skip-to-content').text().trim()]) + function titleTrans() { + if ($('h4#skip-to-content').length === 1) + if (titleDict[$('h4#skip-to-content').text().trim()]) $('h4#skip-to-content').text(titleDict[$('h4#skip-to-content').text().trim()]); }