// ==UserScript== // @name Torn翻译 // @namespace WOOH // @version 0.1 // @description UI翻译 // @author Woohoo- // @match https://www.torn.com/* // @grant none // ==/UserScript== !(function () { 'use strict'; const $ = window.jQuery; let invervalID; /** * 飞行 */ if (window.location.href.indexOf('index.php') >= 0 && $('.travelling h4').length !== 0) { const travelingDict = { // todo jsonify 'Recruit Citizens': '招募玩家', 'Torn to London.': '正在飞往英国伦敦(London)。', 'London to Torn.': '正从英国伦敦(London)回城。', // todo 所有目的地 '\nRemaining Flight Time -\n': ' 剩余时间 - ', }; $('#skip-to-content')[0].firstChild.nodeValue += '飞行中'; // eg. Remaining Flight Time - $('span.remaining-time')[0].firstChild.nodeValue = travelingDict[$('span.remaining-time')[0].firstChild.nodeValue]; $("#recruit-citizens")[0].firstChild.nodeValue = travelingDict[$("#recruit-citizens")[0].firstChild.nodeValue]; // eg. Torn to London. new MutationObserver(mutations => { $('span.description')[0].firstChild.nodeValue = travelingDict[$('span.description')[0].firstChild.nodeValue]; }).observe($('span.description')[0], {attributes: true, childList: true, subtree: true}); return; } /** * 边栏 */ const sidebarDict = { // todo 从json加载 'Money': '现金', 'Level': '等级', 'Points': 'PT', 'Merits': '技能点', 'Energy': '能量E', 'Nerve': '犯罪N', 'Happy': '快乐', 'Life': '血量', 'Chain': '连击链Chain', 'Home': '主页', 'Items': '物品', 'City': '城市', 'Job': '工作', 'Gym': '健身房', 'Properties': '房产', 'Education': '教育', 'Crimes': '犯罪', 'Missions': '任务', 'Newspaper': '报纸', 'Jail': '监狱', 'Hospital': '医院', 'Casino': '赌场', 'Forums': '论坛', 'Hall of Fame': '名人堂', 'My Faction': '帮派', 'Recruit Citizens': '招募玩家', 'Competitions': '活动日历', 'Community Events': '社区事件', 'Friends': '好友', 'Enemies': '敌人', }; const sidebarInterval = setInterval(() => { if ($('div[class^="sidebar"]').length === 0) return; // 边栏块标题 $('h2[class^="header"]')[0].firstChild.nodeValue = '信息'; $('h2[class^="header"]')[1].firstChild.nodeValue = '区域'; // todo 当前文字替换会触发torn js bug $('h2[class^="header"]')[2].firstChild.nodeValue = '列表'; // 边栏人物名字 $('span[class^="menu-name"]')[0].firstChild.nodeValue = '名字:'; // 钱 等级 pt 技能点 $('p[class^="point-block"]').each((i, e) => { e.firstChild.firstChild.nodeValue = sidebarDict[e.firstChild.firstChild.nodeValue]; }); // 4条 状态条 $('p[class^="bar-name"]').each((i, e) => { e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; }); // 边栏菜单 $('span[class^="linkName"]').each((i, e) => { e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; }); // [use]按钮 if ($('#pointsMerits').length !== 0) $('#pointsMerits')[0].firstChild.nodeValue = '[使用]'; if ($('#pointsPoints').length !== 0) $('#pointsPoints')[0].firstChild.nodeValue = '[使用]'; clearInterval(sidebarInterval); }, 1000); // 浮窗 const tootipDict = { 'Full ': '回满', 'energy': '能量E', 'happy': '快乐', ' in ': '还需', 'You have full ': '你已有满', 'life': '血量', 'nerve': '犯罪N', 'You are currently traveling': '你正在飞行中', 'You don\'t own a Laptop!': '你没有笔记本电脑!', 'You are not in Torn': '你不在城里', 'Rank': '阶级', }; let tooltip = $('div.ToolTipPortal')[0]; let intervalID = setInterval(() => { tooltip = $('div.ToolTipPortal')[0]; if (tooltip) { clearInterval(intervalID); new MutationObserver(mutations => { let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); if (barDescr.length !== 0) { barDescr[0].childNodes.forEach(i => { if (tootipDict[i.nodeValue]) i.nodeValue = tootipDict[i.nodeValue]; }) } let miniprof_tooltip = $("#body > div.ToolTipPortal > div > div:nth-child(2)"); if (miniprof_tooltip.length !== 0) { if (tootipDict[miniprof_tooltip[0].firstChild.nodeValue]) { miniprof_tooltip[0].firstChild.nodeValue = tootipDict[miniprof_tooltip[0].firstChild.nodeValue]; } } else { //todo 通配符匹配 } }).observe(tooltip, {attributes: true, childList: true, subtree: true}); } }, 500); /** * 主页 */ if (window.location.href.indexOf('index.php') >= 0 && $('h4#skip-to-content').text().indexOf('Home') >= 0) { } /** * 通知 */ if (window.location.href.indexOf('events.php') >= 0) { let events;// = $('span.mail-link'); const eventMutation = new MutationObserver(() => { events = $('span.mail-link'); eventsTrans(); }); //初始化中内容未加载 let eventInterval = setInterval(() => { events = $('span.mail-link'); if (events.length === 0) { return; } clearInterval(eventInterval); eventMutation.observe($('div#events-main-wrapper')[0], {childList: true, subtree: true}); eventsTrans(); }, 1000); function eventsTrans() { if (events.length === 0) return; events.each((i, e) => { /** * 赛车 * You finished 5th in the Hammerhead race. Your best lap was 01:14.87. * You finished 1st in the Docks race. Your best lap was 04:01.33. * You finished 1st in the Hammerhead race and have received 3 racing points! Your best lap was 01:06.92. * You finished 4th in the Docks race. Your best lap was 03:29.27 beating your previous best lap record of 03:35.77 by 00:06.50. * You have crashed your Honda NSX on the Sewage race! The upgrades Paddle Shift Gearbox (Short Ratio) and Carbon Fiber Roof were lost. * You have crashed your Ford Mustang on the Docks race! Your car has been recovered. */ if ($(e).text().indexOf('finished') >= 0) { if ($(e).text().indexOf('crashed') >= 0) return; // todo 撞车 const isGainRacingPoint = $(e).text().indexOf('racing point'); let racingPoint = isGainRacingPoint >= 0 ? $(e).text()[isGainRacingPoint - 2] : null; const isBeat = $(e).text().indexOf('beating') >= 0; let record, bestBy; if (isBeat) { record = $(e).text().split('record of ')[1].split(' by ')[0]; bestBy = $(e).text().split('record of ')[1].split(' by ')[1].split('. ')[0]; } const pos = e.childNodes[1].firstChild.nodeValue.match(/[0-9]+/)[0]; const splitList = e.childNodes[2].nodeValue.split(' '); const bestLap = e.childNodes[2].nodeValue.split(' best lap was ')[1].split(' ')[0]; let map = splitList[3]; map = map === 'Two' ? 'Two Islands' : map; map = map === 'Stone' ? 'Stone Park' : map; e.firstChild.nodeValue = '你在赛车比赛 ' + map + ' 中获得了第 '; e.childNodes[1].firstChild.nodeValue = pos; e.childNodes[2].nodeValue = ' 名。'; if (isGainRacingPoint >= 0) { e.childNodes[2].nodeValue += '你获得了' + racingPoint + '赛车点数。'; } e.childNodes[2].nodeValue += '你的最佳成绩是 ' + bestLap; if (isBeat) e.childNodes[2].nodeValue += ',比上次成绩 ' + record + ' 快 ' + bestBy; e.childNodes[2].nodeValue += '。' e.childNodes[2].nodeValue += ' ['; e.childNodes[3].firstChild.nodeValue = '查看'; return; } /** * 还贷 */ if ($(e).text().indexOf('Loan Shark') >= 0) { const node1Value = e.firstChild.nodeValue; // You have been charged $29,000 for your loan. You can pay this by visiting the //e.childNodes[1].firstChild.nodeValue; // Loan Shark // const node3Value=e.childNodes[2].nodeValue; 内容是 ". " let charge = node1Value.split(' ')[4]; let replace; replace = '你需要支付 '; replace += charge; replace += ' 贷款利息,点此支付:'; e.firstChild.nodeValue = replace; e.childNodes[1].firstChild.nodeValue = '鲨客借贷(Loan Shark)'; e.childNodes[2].nodeValue = '。'; return; } /** * 收到钱物 * You were sent $21,000,000 from * JNZR * . * 附带信息: with the message: Manuscript fee OCT * e.firstChild.nodeValue * e.childNodes[1].firstChild.nodeValue * e.childNodes[2].nodeValue * * You were sent 4x Xanax from RaichuQ with the message: Manuscript fee OCT * You were sent $21,000,000 from JNZR. * You were sent some Xanax from runningowl * You were sent 1x Present from Duke with the message: Is it your birthday? * You were sent Duke's Safe from DUKE * You were sent a Diamond Bladed Knife from charapower */ if ($(e).text().indexOf('sent') >= 0) { const isWithMsg= $(e).text().indexOf('message') >= 0; const msg=isWithMsg?$(e).text().split(' with the message: ')[1]:null; const wordsList=e.firstChild.nodeValue.split(' '); console.log(wordsList); // 发送的数量 let number; if(wordsList[3]==='some'||wordsList[3]==='a') // 收到一个可数的不可堆叠或不可数的东西 number='1x'; else if(wordsList[3][wordsList[3].length-1]==='x') // 收到可数的可堆叠东西 number=wordsList[3]; else number=null; const item=number===null?wordsList.slice(3,wordsList.length-2):wordsList.slice(4,wordsList.length-2); console.log(item); // 你收到了来自someone的【数量】物品,附带信息:xxx。 e.firstChild.nodeValue='你收到了来自 '; e.childNodes[2].nodeValue=' 的 '; if(number) e.childNodes[2].nodeValue+=number e.childNodes[2].nodeValue+=' '+item; if(isWithMsg) e.childNodes[2].nodeValue+=',附带信息:'+msg; e.childNodes[2].nodeValue+='。'; return; } /** * bazaar * Dewei3 bought 2 x Toyota MR2 from your bazaar for $56,590. * ['', 'bought', '2', 'x', 'Toyota', 'MR2', 'from', 'your', 'bazaar', 'for', '$56,590.\n'] * e.childNodes[1].nodeValue */ if ($(e).text().indexOf('bazaar') >= 0) { const bazEN=e.childNodes[1].nodeValue; const spl=bazEN.split(' '); const num=spl[2]; const item=spl.slice(4,spl.indexOf('from')).join(' '); const money=spl[spl.length-1].replace('.',''); e.childNodes[1].nodeValue=' 花费 '+money+' 从你的 bazaar 买了 '+num+' 个 '+' '+item+'。'; return; } if ($(e).text().indexOf('trade') >= 0) { // 交易 if ($(e).text().indexOf('You must now accept') >= 0) { // 接受交易 return; } if ($(e).text().indexOf('expired') >= 0) { // 交易过期 return; } if ($(e).text().indexOf('initiated') >= 0) { // 交易发起 return; } return; } if ($(e).text().indexOf('mugged') >= 0) { // 被mug if ($(e).text().indexOf('Someone') >= 0) { // 被匿名mug return; } else { return; } } if ($(e).text().indexOf('attacked') >= 0) { // 被打 if ($(e).text().indexOf('Someone') >= 0) { // 被匿名 if ($(e).text().indexOf('hospitalized') >= 0) { // 被打住院 return; } return; } if ($(e).text().indexOf('but lost') >= 0) { // 收lost return; } if ($(e).text().indexOf('hospitalized') >= 0) { // 被实名打住院 return; } } /** * 每日彩票 * 有人在Lucky Shot彩票中赢得11,832,100,000美元! * zstorm won $5,574,200 in the Daily Dime lottery! */ if ($(e).text().indexOf('lottery') >= 0) { console.log('彩票') const split=e.childNodes[1].nodeValue.split(' '); const type=split[split.length-3]+' '+split[split.length-2]; const money=split[2]; e.childNodes[1].nodeValue=' 在 '+type+' 彩票中赢得了 '+money+'!'; return; } if ($(e).text().indexOf('organized crime') >= 0) { // oc开启 return; } if ($(e).text().indexOf('You and your team') >= 0) { // oc结束 return; } /** * bust 捞人 * Spookyt * failed to bust you out of jail. */ if ($(e).text().indexOf('bust') >= 0) { // 劫狱成功 if ($(e).text().indexOf('to bust') >= 0) { // 劫狱失败 e.childNodes[1].nodeValue=' 想捞你出来但是把自己搭进去了。'; return; } e.childNodes[1].nodeValue=' 成功把你捞了出来。'; return; } if ($(e).text().indexOf('doorstep') >= 0) { // 蓝星奖励 return; } }); } } })();