更新通知

This commit is contained in:
woohoo 2021-11-19 23:52:34 +08:00
parent 7c90052609
commit e087fe9e47

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1118b
// @version 0.1.1119a
// @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/*
@ -11,9 +11,9 @@
(function () {
'use strict';
const ___win_WHTRANS = window || window.unsafeWindow;
if (___win_WHTRANS.WHTRANS) return;
___win_WHTRANS.WHTRANS = true;
const ___window___ = window || window.unsafeWindow;
if (___window___.WHTRANS) return;
___window___.WHTRANS = true;
const $ = window.jQuery;
const titleDict = {
@ -313,12 +313,14 @@
};
const travelingDict = {
'Remaining Flight Time -': '剩余时间 - ',
'Torn to London.': '正在飞往英国伦敦London。',
'London to Torn.': '正从英国伦敦London回城。',
'Torn to Zurich.': '正在飞往瑞士苏黎世Zurich。',
'Zurich to Torn.': '正从瑞士苏黎世Zurich回城。',
'Torn to Buenos Aires.': '正在飞往阿根廷布宜诺斯艾利斯(Buenos Aires)。',
'Buenos Aires to Torn.': '正从阿根廷布宜诺斯艾利斯(Buenos Aires)回城。',
'Torn to London.': '正在飞往英国伦敦 (London)。',
'London to Torn.': '正从英国伦敦 (London) 回城。',
'Torn to Zurich.': '正在飞往瑞士苏黎世 (Zurich)。',
'Zurich to Torn.': '正从瑞士苏黎世 (Zurich) 回城。',
'Torn to Honolulu.': '正在飞往夏威夷檀香山 (Honolulu)。',
'Honolulu to Torn.': '正从夏威夷檀香山 (Honolulu) 回城。',
'Torn to Buenos Aires.': '正在飞往阿根廷布宜诺斯艾利斯 (Buenos Aires)。',
'Buenos Aires to Torn.': '正从阿根廷布宜诺斯艾利斯 (Buenos Aires) 回城。',
};
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位。",
@ -559,7 +561,7 @@
'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': '抽取和输送血液的能力(使用血包)',
'Ability to withdraw and deliver blood': '抽取和输送血液的能力 (使用血包)',
// 'Gain {$1} {$2} upon completion': '获得{$1}点{$2}',
'intelligence': '智力(INT)',
'endurance': '耐心(END)',
@ -682,6 +684,23 @@
'and earned your': ',赢得',
'bounty reward': '赏金',
'Someone hospitalized': '某人强制住院了',
'You pop the LSD pill into your mouth and down a glass of water. A headache is followed by nausea and vomiting. You have overdosed.':
'你把 LSD 塞进嘴里,然后喝下一杯水。头痛之后是恶心和呕吐。你已用药过量了。',
'Your application to join the company': '加入公司 ',
'has been declined': ' 的申请已被拒绝。',
'has been accepted': ' 的申请已被通过。',
'You have been given a bazaar for your 250 points. You can now sell items there.':
'你收到了花费 250 PT 买来的集市。现在你可以在那里出售物品。',
'You have received a Stock Ticker in exchange for 25 points. Now you can access the Stock Market and start buying shares.':
'你收到了花费 25 PT 买来的股票交易机。现在你可以进入股票市场并开始购买股票。',
'You have received a Racing License in exchange for 50 points. You can now access the Race Track in the city.':
'你收到了花费 50 PT 买来的赛车执照。你现在可以进入城市的赛车场了。',
'successfully revived you.': ' 成功复活了你',
'Save': '保存',
'Send': '发送',
'Send Event': '发送通知',
'Delete': '删除',
'failed to revive you.': ' 没能复活你。',
};
const chatDict = {
'Global': '世界',
@ -733,6 +752,7 @@
'Blocked': '拉黑',
'All': '全部',
'Enter a name or ID to add to this list': '输入用户名或ID来添加到这个列表',
'This list is empty.': '这个列表是空的。',
};
const hosDict = {
"You take a trip down to the hospital to see who's been unlucky today.": "你来了一趟医院,看看今天是谁那么倒霉",
@ -782,7 +802,7 @@
'As you progress, you will unlock new honors. To add an Honor to your name, click the one you want.':
'新的荣誉条将随着你的进步解锁。请点击想要在你的名字上显示的荣誉条。',
'As you progress, you will unlock new medals. Your medals will be pinned on your profile to show your\nprestige.':
'新的勋章将随着你的进步解锁。勋章将显示在个人资料上(展示是否够牌面)。',
'新的勋章将随着你的进步解锁。勋章将显示在个人资料上。',
'You have': '你有 ',
'merits': '技能点',
'merit': '技能点',
@ -903,7 +923,7 @@
"This upgrade will increase your maximum life by 5%. This upgrade works great with your defense and might keep you going a little longer during attacks.":
'这个升级将使你的最大生命值增加 5%。这个升级对你的战斗有很大作用,可能会让你在攻击中坚持更久。',
"This upgrade will give you a continuous boost of 3% (per upgrade) to the effect of your crime experience resulting in increased success rates.":
'这项升级将使你在每次成功犯罪时获得的经验持续提升 3%(每次升级),从而提高犯罪成功率。',
'这项升级将使你在每次成功犯罪时获得的经验持续提升 3% (每次升级),从而提高犯罪成功率。',
"This upgrade will decrease the amount of days you have to wait to complete an education course. This upgrade will start working on the next education course you start.":
'这项升级将减少你完成教育课程所需的等待天数。这项升级将在你的下一个教育课程中生效。',
'This upgrade will increase the amount of items you can find in the city, however it will not necessarily increase their quality.':
@ -941,18 +961,85 @@
"This upgrade will improve the damage and accuracy of these weapons when you use them in attacks. Pistol weapons include: Glock 17, Desert Eagle, and Flare Gun.":
'这种升级将提高使用这些武器进行攻击时的伤害和命中。手枪包括:格洛克 (Glock 17)、沙漠之鹰 (Desert Eagle)、Flare Gun。',
"This upgrade will improve the damage and accuracy of these weapons when you use them in attacks. Clubbing weapons include: Baseball Bat, Frying Pan, and Axe (Melee weapons that usually just cause a heavy blow).":
'这种升级将提高使用这些武器进行攻击时的伤害和命中。冲击武器包括:棒球棒 (Baseball Bat)、平底锅 (Frying Pan)、斧头 (Axe)(造成沉重冲击的近战武器)。',
'这种升级将提高使用这些武器进行攻击时的伤害和命中。冲击武器包括:棒球棒 (Baseball Bat)、平底锅 (Frying Pan)、斧头 (Axe) (造成沉重冲击的近战武器)。',
"This upgrade will improve the damage and accuracy of these weapons when you use them in attacks. Piercing weapons include: Pen Knife and Dagger (Melee weapons that you stab with to pierce the skin).":
'这种升级将提高使用这些武器进行攻击时的伤害和命中。穿刺武器包括:折叠刀 (Pen Knife)、匕首 (Dagger)(刺穿皮肤的近战武器)。',
'这种升级将提高使用这些武器进行攻击时的伤害和命中。穿刺武器包括:折叠刀 (Pen Knife)、匕首 (Dagger) (刺穿皮肤的近战武器)。',
"This upgrade will improve the damage and accuracy of these weapons when you use them in attacks. Slashing weapons include: Samurai Sword and Scimitar (Swords and other weapons that you would slash with).":
'这种升级将提高使用这些武器进行攻击时的伤害和命中。切割武器包括:武士刀 (Samurai Sword)、弯刀 (Scimitar)(用来劈砍的剑或其他近战武器)。',
'这种升级将提高使用这些武器进行攻击时的伤害和命中。切割武器包括:武士刀 (Samurai Sword)、弯刀 (Scimitar)(用来劈砍的剑或其他近战武器)。',
"This upgrade will improve the damage and accuracy of these weapons when you use them in attacks. Mechanical devices include: Chainsaw and Taser (Weapons with an electronic or engineered system).":
'这种升级将提高使用这些武器进行攻击时的伤害和命中。机械武器包括:电锯 (Chainsaw)、电击枪 (Taser)(带有电子或工程系统的近战武器)。',
'这种升级将提高使用这些武器进行攻击时的伤害和命中。机械武器包括:电锯 (Chainsaw)、电击枪 (Taser) (带有电子或工程系统的近战武器)。',
"This upgrade will improve the damage and accuracy of these weapons when you use them in attacks. Temporary weapons include: Grenade, Ninja Star, and Molotov Cocktail (Temporary weapons that cause damage).":
'这种升级将提高使用这些武器进行攻击时的伤害和命中。临时武器包括:手雷 (Grenade)、忍者飞镖 (Ninja Star)、鸡尾酒 (Molotov Cocktail)(造成伤害的临时武器)。',
'这种升级将提高使用这些武器进行攻击时的伤害和命中。临时武器包括:手雷 (Grenade)、忍者飞镖 (Ninja Star)、鸡尾酒 (Molotov Cocktail) (造成伤害的临时武器)。',
"Go to hospital 250 times (Very Common)": '住院 250 次(非常常见)',
"Go to hospital 250 times (Very Common)": '住院 250 次 (非常常见)',
};
const playerTitleList = {
'_wiki_url_': 'https://wiki.torn.com/wiki/Title',
'Accomplice': '',
'Addict': '',
'Alcoholic': '',
'Antagonist': '',
'Bondsman': '',
'Booster': '',
'Boxer': '',
'Buster': '',
'Coward': '',
'Citizen': '',
'Damage Dealer': '',
'Deserter': '',
'Druggy': '',
'Egotist': '',
'Felon': '',
'Healer': '',
'Hitman': '',
'Hoarder': '',
'Importer': '',
'Intimidator': '',
'Investor': '',
'Jobsworth': '',
'Killer': '',
'Loser': '',
'Marksman': '',
'Medalist': '',
'Mercenary': '',
'Merchant': '',
'Mobster': '',
'Newcomer': '',
'Nudist': '',
'One Hit Killer': '',
'Outcast': '',
'Punchbag': '',
'Samaritan': '',
'Sage': '',
'Scavenger': '',
'Silent Killer': '',
'Slayer': '',
'Soldier': '',
'Socialite': '',
'Tank': '',
'Thief': '',
'Tourist': '',
'Trader': '',
'Tycoon': '',
};
const ocList = {
'blackmail someone': '敲诈某人',
'blackmailed someone': '敲诈某人',
'kidnap someone': '绑架某人',
'kidnapped someone': '绑架某人',
'make a bomb threat': '炸弹袭击',
'made a bomb threat': '炸弹袭击',
// 'planned robbery':'有计划的抢劫',
// 'rob a money train':'抢劫运钞车',
// 'take over a cruise liner':'攻占一艘游轮',
// 'hijack a plane':'劫持飞机',
// 'political assassination':'政治暗杀 (PA)',
};
// 默认开启通知翻译
if(!localStorage.getItem('wh_trans_event')){
localStorage.setItem('wh_trans_event','true');
}
/**
* 时分秒转换
@ -1261,16 +1348,36 @@
if (chatDict[$(e).attr('placeholder')])
$(e).attr('placeholder', chatDict[$(e).attr('placeholder')]);
});
// people中的列表添加框点击后的4个按钮
$('div.ac-wrapper li a').each((i, e) => {
if (chatDict[$(e).text().trim()])
$(e).text(chatDict[$(e).text().trim()]);
});
//
if (eventsDict[$('div#chatRoot div[class^="overview"] > div > div:nth-child(2)').text().trim()]) {
$('div#chatRoot div[class^="overview"] > div > div:nth-child(2)')
.text(
eventsDict[$('div#chatRoot div[class^="overview"] > div > div:nth-child(2)').text().trim()]
);
}
};
chatTrans();
chatOB.observe($('div#chatRoot').get(0), {childList: true, subtree: true, attributes: true});
}
/**
* 搜索玩家的4个分类按钮
*/
function playerSearchBoxTrans() {
const psbtOB = new MutationObserver(_ => {
if ($('div.ac-wrapper').length === 0) return;
psbtOB.disconnect();
$('div.ac-wrapper li a').each((i, e) => {
if (chatDict[$(e).text().trim()])
$(e).text(chatDict[$(e).text().trim()]);
});
psbtOB.observe(document, {childList: false, subtree: true, attributes: true});
});
psbtOB.observe(document, {childList: false, subtree: true, attributes: true});
}
playerSearchBoxTrans();
/**
* 飞行页面
*/
@ -2257,21 +2364,55 @@
return;
}
/**
* itemuseparcel.php
*/
/**
* 通知翻译函数
* @param events
*/
function eventsTrans(events = $('span.mail-link')) {
//console.log('eventsTrans');
const index = window.location.href.indexOf('events.php#/step=received') >= 0 ? 1 : 0;
const isReceived = index === 1;
/**
* 通知的类型选择栏
*/
// 通知的类型选择栏
$('ul.mailbox-action-wrapper a').contents().each((i, e) => {
if (e.nodeValue)
if (eventsDict[e.nodeValue.trim()])
e.nodeValue = eventsDict[e.nodeValue.trim()];
});
// 桌面版右边按钮浮动提示消息
$('div.mailbox-container i[title]').each((i, e) => {
if (eventsDict[$(e).attr('title')]) {
$(e).attr('title', eventsDict[$(e).attr('title')]);
}
});
// 手机版底部按钮
$('.mobile-mail-actions-wrapper div:nth-child(2)').each((i, e) => {
if (eventsDict[$(e).text().trim()])
$(e).text(eventsDict[$(e).text().trim()]);
});
msgBox(`翻译暂时不能覆盖全部通知。<br>
如发现问题请联系并发送通知 <a href="profiles.php?XID=2687093">Woohoo[2687093]</a><br>
<input type="checkbox" id="eventTransCheck" name="eventTransCheck" /><label for="eventTransCheck">开启通知翻译</label> `);
$('input#eventTransCheck').attr('checked',localStorage.getItem('wh_trans_event') === 'true');
$('input#eventTransCheck').change(function(){
if ($(this).attr('checked') === undefined) {
localStorage.setItem('wh_trans_event', 'false');
} else {
localStorage.setItem('wh_trans_event', 'true');
}
eventsTrans();
//localStorage.setItem('wh_trans_event',$(this).attr('checked')?'true':'false');
});
if (localStorage.getItem('wh_trans_event')==='false') return;
if (events.length === 0) return;
events.each((i, e) => {
@ -2280,6 +2421,11 @@
$(e).children(':first').remove();
}
if (eventsDict[$(e).text().trim()]) {
$(e).text(eventsDict[$(e).text().trim()]);
return;
}
/**
* 赛车
* You finished 5th in the Hammerhead race. Your best lap was 01:14.87.
@ -2345,7 +2491,7 @@
replace += ' 贷款利息,点此支付:';
e.firstChild.nodeValue = replace;
e.childNodes[1].firstChild.nodeValue = '鲨客借贷Loan Shark';
e.childNodes[1].firstChild.nodeValue = '鲨客借贷';
e.childNodes[2].nodeValue = '。';
return;
}
@ -2401,7 +2547,7 @@
* ['', 'bought', '2', 'x', 'Toyota', 'MR2', 'from', 'your', 'bazaar', 'for', '$56,590.\n']
* e.childNodes[1].nodeValue
*/
if ($(e).text().indexOf('bazaar') >= 0) {
if ($(e).text().contains(/bought .+ from your bazaar for/)) {
const bazEN = e.childNodes[1].nodeValue;
const spl = bazEN.split(' ');
@ -2556,7 +2702,7 @@
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.firstChild.nodeValue = '有人袭击你并将你强制住院 [';
e.childNodes[1].firstChild.nodeValue = '查看';
return;
}
@ -2592,7 +2738,7 @@
e.childNodes[2].firstChild.nodeValue = '查看';
return;
case 'hospitalized':
e.childNodes[1].nodeValue = ' 袭击你并安排你住院 [';
e.childNodes[1].nodeValue = ' 袭击你并将你强制住院 [';
e.childNodes[2].firstChild.nodeValue = '查看';
return;
}
@ -2646,11 +2792,12 @@
*/
if ($(e).text().indexOf('organized crime') >= 0) {
const time = e.childNodes[4].nodeValue.split(' ')[2];
const OCName = e.childNodes[3].firstChild.nodeValue; // todo 汉化
const OCName = e.childNodes[3].firstChild.nodeValue;
let others = e.childNodes[2].nodeValue.split(' ')[10];
others = others === 'one' ? '1' : others;
e.firstChild.nodeValue = '你被 ';
e.childNodes[2].nodeValue = ' 选中参与一项组织犯罪OC。你和另外' + others + '人将组成一个团队,在' + time + '小时后进行';
e.childNodes[2].nodeValue = ` 选中参与一项组织犯罪(OC)。你和另外${others}人将组成一个团队,在${time}小时后进行 `;
e.childNodes[3].firstChild.nodeValue = ocList[OCName] ? ocList[OCName] : OCName;
e.childNodes[4].nodeValue = '。';
return;
}
@ -2669,7 +2816,7 @@
rs = '失败';
OCName = e.firstChild.nodeValue.slice(27, -30);
}
e.firstChild.nodeValue = '你和团队的组织犯罪OC' + OCName + ' ' + rs + '了!';
e.firstChild.nodeValue = `你和团队的组织犯罪(OC) ${ocList[OCName] ? ocList[OCName] : OCName} ${rs}了!`;
e.childNodes[1].firstChild.nodeValue = '点此查看详情';
e.childNodes[2].nodeValue = '';
return;
@ -2719,6 +2866,51 @@
return;
}
/**
* 被下悬赏
*/
if ($(e).text().contains(/has placed .+ bount.+ on you/)) {
// 是否匿名 悬赏个数 悬赏单价 原因
const spl = $(e).text().trim().split(' ');
const reasonSpl = $(e).text().trim().split(' and the reason: ');
const someone = !e.children.length;
const num = spl[3] === 'a' ? '1' : spl[3];
const price = reasonSpl[0].split(' ').slice(-1)[0];
const reason = reasonSpl[1] ? reasonSpl[1] : null;
const trans = `${someone ? '某人' : ' '}对你进行了 ${num} 次赏金为 ${price} 的悬赏${reason ? ',原因:' + reason : ''}`;
// 匿名悬赏
if (someone) {
$(e).text(trans);
}
// 实名悬赏
else {
$(e).contents().get(1).nodeValue = trans;
}
return;
}
/**
* 成功复活
*/
if ($(e).text().contains(/successfully revived you/)) {
if (e.children.length !== 1) return;
if (eventsDict[$(e).contents().get(1).nodeValue.trim()]) {
$(e).contents().get(1).nodeValue = eventsDict[$(e).contents().get(1).nodeValue.trim()]
}
return;
}
/**
* 失败复活
*/
if ($(e).text().contains(/failed to revive you/)) {
if (e.children.length !== 1) return;
if (eventsDict[$(e).contents().get(1).nodeValue.trim()]) {
$(e).contents().get(1).nodeValue = eventsDict[$(e).contents().get(1).nodeValue.trim()]
}
return;
}
/**
* 收到帮派的pt
*/
@ -2752,6 +2944,37 @@
return;
}
/**
* LSD od
*/
if ($(e).text().contains(/LSD .+ overdosed/)) {
if (eventsDict[$(e).text().trim()])
$(e).text(eventsDict[$(e).text().trim()]);
return;
}
/**
* 公司申请
*/
if ($(e).text().contains(/Your application to join the company .+ has been/)) {
$(e).contents().each((i, e) => {
if (e.nodeType === 3) {
if (eventsDict[e.nodeValue.trim()]) {
e.nodeValue = eventsDict[e.nodeValue.trim()];
}
}
});
return;
}
/**
* 银行完成
*/
if ($(e).text().contains(/Your bank investment has ended/)) {
$(e).children().text('你的银行投资已经结束。请点击这里领取你的资金。');
return;
}
/**
* 人物升级
* <span class="mail-link" id="event-865162632">Congratulations! You upgraded your level to 31!
@ -2774,6 +2997,16 @@
return;
}
/**
* 人物称号
*/
if ($(e).text().contains(/You are now known in the city as a/)) {
const trans = '现在你在这个城市中被称为';
const title = $(e).text().trim().split(' ').slice(9).join(' ').slice(0, -1);
$(e).text(`${trans} ${title}`);
return;
}
/**
* new virus病毒
* You completed the Simple Virus which is now in your inventory. You can begin programming a new virus
@ -2864,4 +3097,23 @@
$('h4#skip-to-content').css('display', 'none').after(`<span style='float:left'><h4>` + title + `</h4></span>`);
}
/**
* 翻译插件提示
*/
function msgBox(htmlCont = '') {
if ($('div.wh-trans-msg').length === 0) {
console.log('翻译插件消息框已创建');
$('div.content-title').after(`<div class="wh-trans-msg">
<div class="info-msg-cont border-round m-top10 r1738">
<div class="info-msg border-round">
<i class="info-icon"></i>
<div class="delimiter">
<div class="msg right-round">
${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10"></div>`)
} else {
console.log('翻译插件消息框内容已更改');
$('div.wh-trans-msg div.msg.right-round').html(htmlCont);
}
}
}());