From f3d5e18696c92e430ba0fb06e8201dc54c01d05e Mon Sep 17 00:00:00 2001 From: woohoo Date: Tue, 16 Nov 2021 17:48:28 +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=E9=80=9A=E7=9F=A5=E3=80=81=E6=88=BF=E5=B1=8B=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 143 ++++++++++++++++++++++++++++++---------- 1 file changed, 110 insertions(+), 33 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index a21c815..758ffe5 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.1116a +// @version 0.1.1116b // @description UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* @@ -36,6 +36,8 @@ 'Saved Events': '保存的通知', 'Awards': '勋章', 'Faction': '帮派', + 'Your Properties': '你的房产', + 'Spouse\'s Properties': '配偶的房产', }; const titleLinksDict = { 'Personal stats': '个人统计信息', @@ -61,6 +63,8 @@ 'Friends & faction': '好友 & 帮派成员', 'Forum': '论坛', 'Leave Faction': '离开帮派', + 'Properties': '所有房产', + 'Back to Properties': '返回所有房产', }; const sidebarDict = { // todo 从json加载 'Money': '现金', @@ -123,6 +127,42 @@ 'You are not in Torn': '你不在城里', 'Rank': '阶级', }; + const statusDict = { + 'Traveling to Mexico': '正在飞往墨西哥', + 'Traveling to Cayman Islands': '正在飞往开曼群岛', + 'Traveling to Canada': '正在飞往加拿大', + 'Traveling to Hawaii': '正在飞往夏威夷', + 'Traveling to United Kingdom': '正在飞往英国', + 'Traveling to Argentina': '正在飞往阿根廷', + 'Traveling to Switzerland': '正在飞往瑞士', + 'Traveling to Japan': '正在飞往日本', + 'Traveling to China': '正在飞往中国', + 'Traveling to UAE': '正在飞往 UAE', + 'Traveling to South Africa': '正在飞往南非', + 'Returning to Torn from Mexico': '正从墨西哥返回', + 'Returning to Torn from Cayman Islands': '正从开曼群岛返回', + 'Returning to Torn from Canada': '正从加拿大返回', + 'Returning to Torn from Hawaii': '正从夏威夷返回', + 'Returning to Torn from United Kingdom': '正从英国返回', + 'Returning to Torn from Argentina': '正从阿根廷返回', + 'Returning to Torn from Switzerland': '正从瑞士返回', + 'Returning to Torn from Japan': '正从日本返回', + 'Returning to Torn from China': '正从中国返回', + 'Returning to Torn from UAE': '正从 UAE 返回', + 'Returning to Torn from South Africa': '正从南非返回', + 'In Mexico': '在墨西哥', + 'In Cayman Islands': '在开曼群岛', + 'In Canada': '在加拿大', + 'In Hawaii': '在夏威夷', + 'In United Kingdom': '在英国', + 'In United Argentina': '在阿根廷', + 'In United Switzerland': '在瑞士', + 'In United Japan': '在日本', + 'In United China': '在中国', + 'In United UAE': '在 UAE', + 'In South Africa': '在南非', + }; + const miniProfileDict = {}; const homeDict = { 'General Information': '基本信息', 'Property Information': '房产信息', @@ -269,6 +309,8 @@ 'Sell this property': '出售该房产', 'Lease this property': '出租该房产', 'Give this property to someone': '赠送该房产给某人', + 'Pay bills': '支付账单', + 'Recent upkeep payments': '最近的维护费用', }; const travelingDict = { 'Remaining Flight Time -': '剩余时间 - ', @@ -279,7 +321,6 @@ 'Torn to Buenos Aires.': '正在飞往阿根廷布宜诺斯艾利斯(Buenos Aires)。', 'Buenos Aires to Torn.': '正从阿根廷布宜诺斯艾利斯(Buenos Aires)回城。', }; - // 界面tips todo 全收集、翻译 const tipsDict = { 'According to the Economist Intelligence Unit\'s Quality of Life Index, Switzerland is the second best place in the world to be born, after Denmark. Torn ranked 224th, despite there being only 194 recognised nations in the world.': "根据经济学人信息部提供的生活质量指数,瑞士是世界上第二个最适合出生的地方,仅次于丹麦。尽管世界上只有194个公认的国家,但托恩却排名第224位。", 'The opportunities for employment in Torn are wide and varied, from jobs in the zoo and the meat warehouse through to fantastic openings at the strip club - a description rarely used to refer to those who work there.': "托恩的就业机会广泛而多样,从动物园和肉类仓库的工作,到脱衣舞俱乐部的奇妙开场--这是一个很少用来形容在那里工作的人的描述。", @@ -625,10 +666,10 @@ // "ALL EVENTS": "所有通知", // "RECEIVED": "收到的通知", // "SAVED": "已保存通知", - "Delete selected": "删除已选", - "Save selected": "保存已选", - "Check All": "勾选所有", - "Uncheck All": "取消勾选所有", + "Delete selected": " 删除已选", + "Save selected": " 保存已选", + "Check All": " 全选", + "Uncheck All": " 取消全选", // "Events": "通知", // "Log": "日志", // "Back": "返回", @@ -909,12 +950,25 @@ "Go to hospital 250 times (Very Common)": '住院 250 次(非常常见)', }; + /** + * 时分秒转换 + */ + String.prototype.replaceHMS = function replaceHMS() { + return this.replace('hours', '小时') + .replace('hour', '小时') + .replace('minutes', '分钟') + .replace('minute', '分钟') + .replace('seconds', '秒钟') + .replace('second', '秒钟'); + }; + /** * 边栏 * 目前默认所有页面调用边栏翻译 */ - let sidebarTimeOut = 60; // 60秒后取消定时 + let sidebarTimeOut = 60; const sidebarInterval = setInterval(() => { + // 60秒后取消定时 if ($('div[class^="sidebar"]').length === 0) { sidebarTimeOut--; if (sidebarTimeOut < 0) { @@ -939,15 +993,18 @@ }); // 钱 等级 pt 技能点 $('p[class^="point-block"]').each((i, e) => { - e.firstChild.firstChild.nodeValue = sidebarDict[e.firstChild.firstChild.nodeValue]; + if (sidebarDict[e.firstChild.firstChild.nodeValue]) + e.firstChild.firstChild.nodeValue = sidebarDict[e.firstChild.firstChild.nodeValue]; }); // 4条 状态条 $('p[class^="bar-name"]').each((i, e) => { - e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; + if (sidebarDict[e.firstChild.nodeValue]) + e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; }); // 边栏菜单 $('span[class^="linkName"]').each((i, e) => { - e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; + if (sidebarDict[e.firstChild.nodeValue]) + e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; }); // [use]按钮 if ($('#pointsMerits').length !== 0) @@ -984,7 +1041,28 @@ miniprofOB.observe($('div.profile-mini-root').get(0), {attributes: true, childList: true, subtree: true}); }); const miniprofTrans = function miniprofTrans() { - // console.log('111'); + // 迷你资料卡状态 + $('div.profile-mini-root div.description span') + .contents().each((i, e) => { + if (e.nodeType === 3) { + if (statusDict[e.nodeValue.trim()]) + e.nodeValue = statusDict[e.nodeValue.trim()]; + else if (hosDict[e.nodeValue.trim()]) + e.nodeValue = hosDict[e.nodeValue.trim()]; + // 医院 监狱 + else { + const spl = e.nodeValue.split(' '); + if (spl[1] === 'hospital') + e.nodeValue = e.nodeValue + .replace('In hospital for', '在医院呆') + .replaceHMS(); + else if (spl[1] === 'jail') + e.nodeValue = e.nodeValue + .replace('In jail for', '在医院呆') + .replaceHMS(); + } + } + }); }; if ($('div.profile-mini-root').length > 0) miniprofTrans(); @@ -1246,8 +1324,8 @@ } //e.firstChild.nodeValue = homeDict[e.firstChild.nodeValue]; // 隐藏原dom元素避免与torntools发生冲突 - if ($(e).css('display')!=='none') - $(e).css('display','none').after(`
`+homeDict[e.firstChild.nodeValue]+`
`); + if ($(e).css('display') !== 'none') + $(e).css('display', 'none').after(`
` + homeDict[e.firstChild.nodeValue] + `
`); }); // 各表格左边的键 @@ -1642,7 +1720,7 @@ } /** - * properties todo + * properties房屋页面 todo */ if (window.location.href.indexOf('properties.php') >= 0) { const isRent = window.location.href.indexOf('rent') >= 0; @@ -1736,6 +1814,16 @@ } // 房屋选项 if (window.location.href.indexOf('p=options') >= 0) { + // 页面的黑框标题 + $('div.content-wrapper div.title-black').each((i, e) => { + if (propertyDict[$(e).text().trim()]) + $(e).text(propertyDict[$(e).text().trim()]); + }); + // 所有li内容 + // $('div.content-wrapper div.customize-opt li').find('*') + // .contents().each((i,e)=>{ + // if(e.nodeType!==3)return;console.log(e) + // }); return; } // 房屋详情 @@ -1851,18 +1939,18 @@ $(e).attr('data-title', $(e).attr('data-title').replace(desc, awDict[desc])); }); // 改变荣誉条时的提示 - $('div#honors div.msg').each((i,e)=>{ - if(awDict[$(e).text().trim()]) + $('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()]) + $('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()]) + $('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 @@ -1939,7 +2027,7 @@ } }); // spend cancel按钮 - $('ul#merits-list div.confirm-cont a').each((i,e)=>{ + $('ul#merits-list div.confirm-cont a').each((i, e) => { if (awDict[$(e).text().trim()]) $(e).text(awDict[$(e).text().trim()]); }); @@ -2151,22 +2239,11 @@ /** * 通知的类型选择栏 */ - $('div[class^="mailbox-wrapper m-top10"] a[class^="btn torn-btn black"]') - .contents().each((i, e) => { + $('ul.mailbox-action-wrapper a').contents().each((i, e) => { if (e.nodeValue) if (eventsDict[e.nodeValue.trim()]) e.nodeValue = eventsDict[e.nodeValue.trim()]; }); - // .each((i, e) => { - // let word = $(e).text().trim() - // - // if (word.indexOf("(") > 0) { - // if (eventsDict[word.split(" (")[0]]) { - // $(e).text($(e).text() - // .replace(word.split(" (")[0], eventsDict[word.split(" (")[0]])); - // } - // } - // }); if (events.length === 0) return; events.each((i, e) => {