From fa4369e9c9aa2f661363fc0a6308528aa584abd5 Mon Sep 17 00:00:00 2001 From: woohoo Date: Tue, 9 Nov 2021 00:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=81=A5=E8=BA=AB=E6=88=BF?= =?UTF-8?q?=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 | 170 +++++++++++++++++++++++++++++++++------- 1 file changed, 141 insertions(+), 29 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index acd640d..524cae7 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.1108a +// @version 0.1.1109a // @description UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* @@ -200,7 +200,7 @@ 'Cost:': '花费:', 'Cost per Day': '平均日花费', 'Rental Period': '租期', - 'Rental period:': '租期', + 'Rental period:': '租期:', 'Rent': '租赁', 'Info': '信息', 'Buy': '购买', @@ -248,6 +248,33 @@ 'Sort by:': '分类排序方式:', 'Area': '地区', }; + const gymDict={ + 'Strength':'力量 STR', + 'STR':'力量 STR', + 'TRAIN':'锻炼', + 'Welcome to':'欢迎来到 ', + '!':'!', + 'You walk into the gym and begin browsing the exercises available.': + '你走进健身房,开始浏览可用的健身器材。', + 'You have':'你有', + 'available to use.':'可用于锻炼。', + 'energy':'能量', + 'Estimated Energy progress:':'(TornTools) 预估健身房解锁进程:', + 'What would you like to train today?':'今天要练点什么?', + 'BACK TO GYM':'返回健身房', + 'ACTIVATE MEMBERSHIP':'激活会员身份', + 'BUY MEMBERSHIP':'购买健身房会员', + 'Cancel':'返回', + //'Damage you make on impact':'', + 'Chance of hitting opponent':'击中对手的概率', + '{$} energy per train':'每次锻炼花费{$}能量', + 'Class:':'健身房类别:', + 'Heavyweight':'重型', + 'Strength Gains':'力量获得', + 'Boxing':'拳击', + 'Are you sure you would like to buy this membership?':'确定购买这个健身房会员吗?', + 'Not Available':'不可用', + }; /** @@ -378,10 +405,10 @@ } }, 500); - const attackDict = { - "mugged": "打劫了", - "arrested": "逮捕了" - } + // const attackDict = { + // "mugged": "打劫了", + // "arrested": "逮捕了" + // } /** * 主页 todo @@ -397,30 +424,31 @@ if (!homeDict[e.firstChild.nodeValue]) return; if (e.firstChild.nodeValue === 'Latest Events') { homeEvents = $(e).parent().next().find('span'); - } else if (e.firstChild.nodeValue === 'Latest Attacks') { - const attackDict = { - "mugged": "打劫了", - "arrested": "逮捕了" - } - $(e).parent().next().find('span').each(function () { - var attackMsg = $(this).context.textContent; - - //Convert to an array for attacking ways determination - var keyAtk = attackMsg.split(" "); - var someone = keyAtk[0] === "Someone" ? "有人" : keyAtk[0]; - var textTsf = ""; - switch (keyAtk[1]) { - - case "hospitalized": - textTsf = "攻击并送" + keyAtk[2] + "入院"; - break; - - default: - textTsf = attackDict[keyAtk[1]] + keyAtk[2]; - } - $(this).context.textContent = someone + textTsf; - }); } + // else if (e.firstChild.nodeValue === 'Latest Attacks') { + // const attackDict = { + // "mugged": "打劫了", + // "arrested": "逮捕了" + // } + // $(e).parent().next().find('span').each(function () { + // var attackMsg = $(this).context.textContent; + // + // //Convert to an array for attacking ways determination + // var keyAtk = attackMsg.split(" "); + // var someone = keyAtk[0] === "Someone" ? "有人" : keyAtk[0]; + // var textTsf = ""; + // switch (keyAtk[1]) { + // + // case "hospitalized": + // textTsf = "攻击并送" + keyAtk[2] + "入院"; + // break; + // + // default: + // textTsf = attackDict[keyAtk[1]] + keyAtk[2]; + // } + // $(this).context.textContent = someone + textTsf; + // }); + // } e.firstChild.nodeValue = homeDict[e.firstChild.nodeValue]; }); @@ -504,6 +532,90 @@ return; } + /** + * 健身房页面 + */ + if (window.location.href.indexOf('gym.php') >= 0) { + const gymOB = new MutationObserver(gymOBInit); + + function gymOBInit() { + gymOB.disconnect(); + gymTrans(); + gymOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); + } + + function gymTrans() { + titleTrans(); + contentTitleLinksTrans(); + const gymName=$('div[class^="notificationText"] b').text(); + + // 顶部提示信息 + $('div[class^="notificationText"] p').contents().each((i,e)=>{ + if(e.childNodes.length===0 && gymDict[e.nodeValue.trim()]) + e.nodeValue=gymDict[e.nodeValue.trim()]; + }); + // 4属性标题 + $('h3[class^="title"]').each((i,e)=>{ + if (gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + }); + // 4属性的介绍 与冰蛙冲突 + $('div[class^="description"] p:nth-child(1)').each((i,e)=>{ + if (gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + }); + // 每次锻炼的花销 + $('div[class^="description"] p:nth-child(2)').each((i,e)=>{ + const energyPerTrain=$(e).text().split(' ').length===4?$(e).text().split(' ')[0]:null; + if(gymDict[$(e).text().replace(energyPerTrain,`{$}`)]) + $(e).text(gymDict[$(e).text().replace(energyPerTrain,`{$}`)].replace(`{$}`,energyPerTrain)); + }); + // 锻炼按钮 + $('button[class^="button"]').each((i,e)=>{ + if (gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + });// cancel按钮 + $('button[class^="cancel"]').each((i,e)=>{ + if (gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + }); + // 锻炼的提示信息 + $('div[class^="messageWrapper"] p').each((i,e)=>{ + if(gymDict[$(e).text()]) + $(e).text(gymDict[$(e).text()]); + }); + // 健身房信息 标题 + $('div[class^="gymTitle"] h3').each((i,e)=>{ + if(gymDict[$(e).text()]) + $(e).text(gymDict[$(e).text()]); + }); + // 健身房信息 属性名 + $('ul[class^="gymInfo"] b').each((i,e)=>{ + if(gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + }); + // 健身房信息 属性值 + $('ul[class^="gymInfo"] span[class^="value"]').each((i,e)=>{ + if(gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + }); + // 健身房信息 具体锻炼项目 + $('span[class^="exerciseName"]').each((i,e)=>{ + if(gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + }); + // 购买提示信息 + $('div[class^="confirmMessage"] p[role="alert"]').each((i,e)=>{ + if(gymDict[$(e).text().trim()]) + $(e).text(gymDict[$(e).text().trim()]); + }); + } + + gymTrans(); + gymOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); + return; + } + /** * 报纸菜单 */