From f88e1406550b8bb4b24c138026c63ba29bdaf2b2 Mon Sep 17 00:00:00 2001 From: woohoo Date: Tue, 9 Nov 2021 18:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0edu=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 | 185 +++++++++++++++++++++++++++++++++------- 1 file changed, 154 insertions(+), 31 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 21bfcd3..5349ce2 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -25,6 +25,9 @@ 'Classified Ads': '分类广告', 'Properties': '房产', 'City': '城市', + 'Education':'教育', + 'Gym':'健身房', + 'Biology Modules':'生物学课程', }; const titleLinksDict = { 'Personal stats': '个人统计信息', @@ -35,6 +38,7 @@ 'City': '城市', 'Back to Estate Agents': '返回地产中介', 'Tutorial': '教程', + 'Back to Education':'返回', }; const sidebarDict = { // todo 从json加载 'Money': '现金', @@ -156,6 +160,15 @@ 'Intelligence': '智力 INT', 'Endurance': '耐心 END', }; + const attackDict = { + "mugged": "打劫了 ", + "attached": "攻击了 ", + "arrested": "逮捕了 ", + "hospitalized": "暴力殴打了 ", + "but": "但是", + "Someone": "有人", + "lost": "失败了" + }; const newspaperDict = { 'front page': '头版', 'archive': '归档', @@ -249,14 +262,14 @@ 'Area': '地区', }; const gymDict={ - 'Strength': '力量 STR', - 'STR': '力量 STR', - 'TRAIN': '锻炼', - 'Welcome to': '欢迎来到 ', - '!': '!', + 'Strength':'力量 STR', + 'STR':'力量 STR', + 'TRAIN':'锻炼', + 'Welcome to':'欢迎来到 ', + '!':'!', 'You walk into the gym and begin browsing the exercises available.': '你走进健身房,开始浏览可用的健身器材。', - 'You have': '你有', + 'You have':'你有', 'available to use.': '可用于锻炼。', 'energy': '能量', 'Estimated Energy progress:': '(TornTools) 预估健身房解锁进程:', @@ -277,6 +290,23 @@ 'Are you sure you would like to buy this membership?': '确定购买这个健身房会员吗?', 'Not Available': '不可用', }; + const eduDict={ + 'Biology':'生物学', + 'Biology Modules':'生物学课程', + 'Introduction to Biochemistry':'生物化学概论', + 'You do not meet the requirements for this course. Please complete the prerequisites first.': + '你不符合本课程的要求。请先学习前置课程。', + 'Description:':'描述:', + 'Learning outcomes:':'学习后可获得:', + 'Prerequisites:':'前置课程:', + 'Parameters:':'课程参数:', + 'As the ultimate module - you will focus on maximum gym gain with the least amount of input.':'', + 'Ability to withdraw and deliver blood':'抽取和输送血液的能力(使用血包)', + 'Gain {$1} {$2} upon completion':'获得{$1}点{$2}', + 'intelligence':'智力(INT)', + 'endurance':'耐心(END)', + 'manual labor':'体力(MAN)', + }; /** @@ -422,21 +452,11 @@ if (e.firstChild.nodeValue === 'Latest Events') { homeEvents = $(e).parent().next().find('span'); } else if (e.firstChild.nodeValue === 'Latest Attacks') { - const attackDict = { - "mugged": "打劫了 ", - "attached": "攻击了 ", - "arrested": "逮捕了 ", - "hospitalized": "暴力殴打了 ", - "but": "但是", - "Someone": "有人", - "lost": "失败了" - } $(e).parent().next().find('span').each(function () { let nodes = $(this)[0].childNodes; nodes.forEach((v, i) => { if (v.nodeValue !== null) { let waitToTsf = v.nodeValue.toString().indexOf(" "); - let words = v.nodeValue.replace("\n", "").toString().split(" "); words.forEach((word, j) => { if (attackDict.hasOwnProperty(word)) { @@ -559,33 +579,40 @@ e.nodeValue=gymDict[e.nodeValue.trim()]; }); // 4属性标题 - $('h3[class^="title"]').each((i, e) => { + $('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) => { + $('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) => { + // $('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) => { + }); + // 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()]) + $('div[class^="messageWrapper"] p').each((i,e)=>{ + /** + * todo + *

You dug deep and completed 15 minutes of incline sprints

+ * + */ + //$(e).attr('class').match(/gained/) + if(gymDict[$(e).text()]) $(e).text(gymDict[$(e).text()]); }); // 健身房信息 标题 @@ -620,6 +647,102 @@ return; } + /** + * 教育页面 + */ + if (window.location.href.indexOf('education.php') >= 0) { + const eduOB = new MutationObserver(eduOBInit); + + function eduOBInit() { + eduOB.disconnect(); + eduTrans(); + eduOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); + } + + function eduTrans() { + titleTrans(); + contentTitleLinksTrans(); + + // 大科目、学院标题 + $('div.content-wrapper div.title').each((i,e)=>{ + if(eduDict[$(e).text().trim()]) + e.firstChild.nodeValue=eduDict[$(e).text().trim()]; + }); + // 学院详情标题 + $('div.content-wrapper div.title-black').each((i,e)=>{ + if(e.childNodes.length===3) + if(eduDict[e.lastChild.nodeValue.trim()]) + e.lastChild.nodeValue=' '+eduDict[e.lastChild.nodeValue.trim()]; + if(eduDict[$(e).text().trim()]) + $(e).text(eduDict[$(e).text().trim()]); + }); + // 学院详情 小课程标题 + $('div.content-wrapper span.module-name').each((i,e)=>{ + if(eduDict[$(e).text().trim()]) + $(e).text(eduDict[$(e).text().trim()]); + }); + // 课程详情 7 标题 + $('div.module-desc p.title').each((i,e)=>{ + if(eduDict[$(e).text().trim()]) + $(e).text(eduDict[$(e).text().trim()]); + }); + // 学院详情 小课程提示信息 + $('div.content-wrapper div.msg-cont div').each((i,e)=>{ + if(eduDict[$(e).text().trim()]) + $(e).text(eduDict[$(e).text().trim()]); + }); + // 课程介绍中的所有li元素 + $('div.module-desc ul.info li').each((i,e)=>{ + if(e.childNodes.length===1) { + const spl = $(e).text().trim().split(' '); + switch (spl[0]) { + case 'Length:': {//Length + const d = spl[1].slice(0, -1); + const h = spl[2].slice(0, -1); + const m = spl[3].slice(0, -1); + $(e).text('时长:' + d + '天' + h + '时' + m + '分'); + return; + } + case 'Cost:': {//Cost + $(e).text('费用:' + spl[1]); + return; + } + case 'Tier:': {//Tier + $(e).text('级别:' + spl[1]); + return; + } + case 'Gain': { + if(isNumber(spl[1])) {//Gain 40 intelligence upon completion + const wsGained = spl.slice(2, -2).join(' '); + if(eduDict[$(e).text().trim().replace(spl[1],'{$1}') + .replace(wsGained,'{$2}')]) + $(e).text(eduDict[$(e).text().trim().replace(spl[1],'{$1}').replace(wsGained,'{$2}')] + .replace('{$1}',spl[1]).replace('{$2}',eduDict[wsGained]?eduDict[wsGained]:wsGained)); + } + else{ + if(eduDict[$(e).text().trim()]) + $(e).text(eduDict[$(e).text().trim()]); + } + return; + } + default:{ + if(eduDict[$(e).text().trim()]) + $(e).text(eduDict[$(e).text().trim()]); + } + } + } + else{ // 前置课程 + if(eduDict[$(e).children().text().trim()]) + $(e).children().text(eduDict[$(e).children().text().trim()]); + } + }); + } + + eduTrans(); + eduOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); + return; + } + /** * 报纸菜单 */ @@ -1103,10 +1226,10 @@ return; } return; - ; } - if (spl[0] === 'Someone') { // 被匿名 + if ($(e).find('a').text().toLowerCase().indexOf('someone') < 0 && // 避免玩家名带有someone字样 + $(e).text().split(' ')[0].toLowerCase()==='someone') { // 被匿名 if (spl.length === 6 && spl[3] === 'hospitalized') { // 匿名hos e.firstChild.nodeValue = '有人袭击你并安排你住院 ['; e.childNodes[1].firstChild.nodeValue = '查看';