更新通知

This commit is contained in:
woohoo 2021-11-21 20:26:12 +08:00
parent 3f8d74e1d2
commit 058fc901e3

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1120a
// @version 0.1.1121a
// @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/*
@ -698,6 +698,8 @@
'你收到了花费 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 买来的赛车执照。你现在可以进入城市的赛车场了。',
'You have been given a display cabinet for your 100 points. Now you can store special items there. Go to the items page to start using it.':
'你收到了花费 100 PT 买来的展示柜。现在你可以在那里储存特殊物品。进入物品页面,开始使用它。',
'successfully revived you.': ' 成功复活了你',
'Save': '保存',
'Send': '发送',
@ -715,6 +717,11 @@
'中,且你会当他们等级提升时获得奖励。',
'You have used the reward bonus code {$} and have received a boost of +250 energy.':
'你已使用奖励兑换码 {$},收到了 250 能量E。',
', the director of':
' (',
'MAN': '体力 (MAN)',
'END': '耐心 (END)',
'INT': '智力 (INT)',
};
const chatDict = {
'Global': '世界',
@ -1051,8 +1058,8 @@
};
// 默认开启通知翻译
if(!localStorage.getItem('wh_trans_event')){
localStorage.setItem('wh_trans_event','true');
if (!localStorage.getItem('wh_trans_event')) {
localStorage.setItem('wh_trans_event', 'true');
}
/**
@ -2410,36 +2417,36 @@
});
// 黑框标题
$('#events-main-wrapper .title-black').each((i,e)=>{
$('#events-main-wrapper .title-black').each((i, e) => {
if (eventsDict[$(e).text().trim()]) {
$(e).text(eventsDict[$(e).text().trim()]);
}
});
// 发送的两个按钮 + user id
$('#events-main-wrapper div.send-to a.btn').each((i,e)=>{
$('#events-main-wrapper div.send-to a.btn').each((i, e) => {
if (eventsDict[$(e).text().trim()]) {
$(e).text(eventsDict[$(e).text().trim()]);
}
});
$('#events-main-wrapper div.send-to span.cancel a').each((i,e)=>{
$('#events-main-wrapper div.send-to span.cancel a').each((i, e) => {
if (eventsDict[$(e).text().trim()]) {
$(e).text(eventsDict[$(e).text().trim()]);
}
});
$('#events-main-wrapper div.send-to span.name').each((i,e)=>{
$('#events-main-wrapper div.send-to span.name').each((i, e) => {
if (eventsDict[$(e).text().trim()]) {
$(e).text(eventsDict[$(e).text().trim()]);
}
});
// 通知翻译的开关
if (!$('div#event-trans-msg').get(0)) {
if (!$('div#event-trans-msg').get(0) && !window.location.href.contains(/index\.php/)) {
msgBox(`<div id="event-trans-msg">翻译暂时不能覆盖全部通知。<br>
如发现问题请发送通知并联系 <a href="profiles.php?XID=2687093">Woohoo[2687093]</a><br>
<input type="checkbox" id="eventTransCheck" name="eventTransCheck" /><label for="eventTransCheck">开启通知翻译</label> </div>`);
$('input#eventTransCheck').attr('checked',localStorage.getItem('wh_trans_event') === 'true');
$('input#eventTransCheck').change(function(){
$('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 {
@ -2549,31 +2556,21 @@
* You were sent Duke's Safe from DUKE
* You were sent a Diamond Bladed Knife from charapower
*/
if ($(e).text().indexOf('were sent') >= 0) {
if ($(e).text().split('from someone').length > 1) return; // todo 收到匿名发来的物资
const isWithMsg = $(e).text().indexOf('message') >= 0;
const msg = isWithMsg ? $(e).text().split(' with the message: ')[1] : null;
const wordsList = e.firstChild.nodeValue.split(' ');
// 发送的数量
let number;
if (wordsList[3] === 'some' || wordsList[3][0] === '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);
// 你收到了来自someone的【数量】物品附带信息xxx。
e.firstChild.nodeValue = '你收到了来自 ';
e.childNodes[2].nodeValue = ' 的 ';
if (number)
e.childNodes[2].nodeValue += number
e.childNodes[2].nodeValue += ' ' + item.join(' ');
if (isWithMsg)
e.childNodes[2].nodeValue += ',附带信息:' + msg;
//e.childNodes[2].nodeValue += '。';
if ($(e).text().contains(/You were sent .+ from/)) {
// 数量 物品 信息
// spl = [You were sent 1x Birthday Present from]
const spl = $(e).contents().get(0).nodeValue.trim().split(' ');
const msgSpl = $(e).text().trim().split('with the message: ');
const num = /^\$[0-9,]+\b/.test(spl[3]) ? '' : spl[3].numWordTrans();
const item = num === '' ? spl[3] : spl.slice(4, -1).join(' ');
const msg = msgSpl[1] ? msgSpl[1] : null;
e.childNodes[0].nodeValue = `你收到了 ${num} ${item},来自 `;
if (e.childNodes[2]) {
e.childNodes[2].nodeValue = ``;
}
if (msg) {
e.childNodes[2].nodeValue = `,附带信息:${msg}`;
}
return;
}
@ -2795,6 +2792,45 @@
return;
}
/**
* 公司职位变更
*/
if ($(e).text().contains(/, the director of .+, has/)) {
$(e).contents().each((i,e)=>{
if (e.nodeType === 3) {
if (eventsDict[e.nodeValue.trim()]) {
e.nodeValue = eventsDict[e.nodeValue.trim()];
}
else {
// 工资改变
if (e.nodeValue.contains(/wage/)) {
const money = e.nodeValue.trim().slice(27,-9);
e.nodeValue = ` 的老板) 将你的每日工资改为 ${money}`;
return;
}
// 职位改变
if (e.nodeValue.contains(/rank/)) {
const pos = e.nodeValue.trim().slice(27,-1);
e.nodeValue = ` 的老板) 将你的公司职位改为 ${pos}`;
return;
}
if (e.nodeValue.contains(/assigned/)) {
e.nodeValue = ` 的老板) 将你指派为新的公司老板。`;
return;
}
// 火车
if (e.nodeValue.contains(/trained/)) {
const spl = e.nodeValue.trim().split(' ');
const pri = spl[10];
const sec = spl[13].slice(0,-1);
e.nodeValue = ` 的老板) 从公司训练了你。你获得了 50 ${eventsDict[pri]} 和 25 ${eventsDict[sec]}`;
}
}
}
});
return;
}
/**
* 悬赏已被领取
*/
@ -2890,7 +2926,7 @@
/**
* 收到帮派的钱
*/
if ($(e).text().indexOf('given $') >= 0) {
if ($(e).text().contains(/You were given \$[0-9,]+ from your faction/)) {
const money = e.firstChild.nodeValue.split(' ')[3];
let isNamed = e.childNodes.length > 1;
if (isNamed) {
@ -2950,7 +2986,7 @@
/**
* 收到帮派的pt
*/
if ($(e).text().indexOf('points from') >= 0) {
if ($(e).text().contains(/You were given [0-9,]+ points? from your faction/)) {
const pt = e.firstChild.nodeValue.split(' ')[3];
e.firstChild.nodeValue = '你得到了从帮派取出的 ' + pt + ' PT。'
return;
@ -3047,16 +3083,16 @@
* 收下线
*/
if ($(e).text().contains(/You have successfully referred/)) {
$(e).contents().each((i,e)=>{
$(e).contents().each((i, e) => {
// 文字
if (e.nodeType===3) {
if (eventsDict[e.nodeValue.trim()]){
if (e.nodeType === 3) {
if (eventsDict[e.nodeValue.trim()]) {
e.nodeValue = eventsDict[e.nodeValue.trim()];
}
}
// referral list
else if (e.nodeType===1) {
if (eventsDict[$(e).text().trim()]){
else if (e.nodeType === 1) {
if (eventsDict[$(e).text().trim()]) {
$(e).text(eventsDict[$(e).text().trim()]);
}
}
@ -3083,7 +3119,7 @@
/**
* 每月蓝星奖励
*/
if ($(e).text().contains(/You found .+ and .+ on your doorstep\./)) {
if ($(e).text().contains(/You found .+ and .+ on your doorstep/)) {
const [item1, item2] = $(e).text().trim().slice(10, -18).split(' and ');
const bookTitle = item2.contains(/a book titled/) ? item2.slice(15, -1) : null;
@ -3100,12 +3136,29 @@
*/
if ($(e).text().contains(/used the reward bonus code/)) {
const code = $(e).text().trim().split(' ')[7];
if (eventsDict[$(e).text().trim().replace(code,'{$}')])
$(e).text(eventsDict[$(e).text().trim().replace(code,'{$}')]
if (eventsDict[$(e).text().trim().replace(code, '{$}')])
$(e).text(eventsDict[$(e).text().trim().replace(code, '{$}')]
.replace('{$}', code));
return;
}
/**
* 求婚
*/
if ($(e).text().contains(/accepted your proposal, you are now engaged/)) {
const spouse = $(e).children(':first').text().trim();
if (e.childNodes[1]) {
e.childNodes[1].nodeValue = ` 接受了你的求婚,你现在和 ${spouse} 订婚了!前往`;
}
if (e.childNodes[2] && e.childNodes[2].firstChild) {
e.childNodes[2].firstChild.nodeValue = `这里`;
}
if (e.childNodes[3]) {
e.childNodes[3].nodeValue = `完成仪式。`;
}
return;
}
/**
* 帮派职位变更
* Your position in