diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js
index 2a3e8e5..e5a657e 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.1118a
+// @version 0.1.1118b
// @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/*
@@ -415,6 +415,7 @@
'energy': '能量',
'Estimated Energy progress:': '(TornTools) 预估健身房解锁进程:',
'What would you like to train today?': '今天想练点什么?',
+ 'You do not have enough energy left': '你没有足够的剩余能量?',
'BACK TO GYM': '返回健身房',
'ACTIVATE MEMBERSHIP': '激活会员身份',
'BUY MEMBERSHIP': '购买健身房会员',
@@ -966,12 +967,21 @@
*/
String.prototype.contains = function contains(keywords) {
if (typeof keywords === 'string') {
- if (keywords.contains(/\*/))
- keywords = keywords.replace("*", '.+');
return new RegExp(keywords).test(this);
}
- if (keywords.test)
+ if (keywords.test) {
return keywords.test(this);
+ }
+ }
+
+ /**
+ * 数词转换 a an some
+ */
+ String.prototype.numWordTrans = function numWordTrans() {
+ return this.replace(/\ban\b/,'1 个')
+ .replace(/\ba\b/,'1 个')
+ .replace(/\bsome\b/,'1 个')
+ .replace(/(?<=[0-9])x\b/,' 个');
};
/**
@@ -2261,7 +2271,8 @@
if (events.length === 0) return;
events.each((i, e) => {
- if (isReceived) {// todo “收到的信息” 暂时删除发送人节点 不影响显示
+ // todo “收到的信息” 暂时删除发送人节点 不影响显示
+ if (isReceived) {
$(e).children(':first').remove();
}
@@ -2668,15 +2679,6 @@
return;
}
- /**
- * 收到帮派的pt
- */
- if ($(e).text().indexOf('points from') >= 0) {
- const pt = e.firstChild.nodeValue.split(' ')[3];
- e.firstChild.nodeValue = '你得到了从帮派取出的 ' + pt + ' PT。'
- return;
- }
-
/**
* 收到帮派的钱
*/
@@ -2692,6 +2694,29 @@
return;
}
+ /**
+ * 收到帮派的pt
+ */
+ if ($(e).text().indexOf('points from') >= 0) {
+ const pt = e.firstChild.nodeValue.split(' ')[3];
+ e.firstChild.nodeValue = '你得到了从帮派取出的 ' + pt + ' PT。'
+ return;
+ }
+
+ /**
+ * 帮派借东西
+ */
+ if ($(e).text().contains(/loaned you .+ from the faction armory/)) {
+ const [num, item] = (()=>{
+ const spl=e.lastChild.nodeValue.trim().slice().slice(11, -25).split(' ');
+ return spl.length===1?[spl[0],null]:[spl[0],spl.slice(1).join(' ')];
+ })();
+ if (num&&item){
+ e.lastChild.nodeValue = ` 从帮派军械库中借给你 ${num.numWordTrans()} ${item}。`;
+ }
+ return;
+ }
+
/**
* 教育完成
* The education course you were taking has ended. Please click here.
@@ -2718,9 +2743,9 @@
* You have successfully purchased membership in Deep Burn.
* 你已成功购买Deep Burn的健身房会员卡。
*/
- if ($(e).text().contains('You have successfully purchased membership in')) {
+ if ($(e).text().contains(/You have successfully purchased membership in/)) {
const gymName = e.firstChild.nodeValue.trim().slice(46, -1);
- e.firstChild.nodeValue = '你已成功购买 ' + gymList[gymName] + ' 的健身房会员卡。';
+ e.firstChild.nodeValue = `你已购买【${gymList[gymName]}】健身房会员卡。`;
return;
}
@@ -2734,13 +2759,25 @@
*/
if ($(e).text().indexOf('new virus') >= 0) {
const virusName = e.firstChild.nodeValue.split(' ').slice(3, 5).join(' ');
- e.firstChild.nodeValue = '你完成了 ' + virusName + ' ,它现在在你的物品库存中。你可以';
+ e.firstChild.nodeValue = `你完成了 ${virusName},它现在在你的物品库存中。你可以`;
e.childNodes[1].firstChild.nodeValue = '点此';
e.childNodes[2].nodeValue = '开始编程一个新的病毒。';
return;
}
- if ($(e).text().indexOf('doorstep') >= 0) { // 蓝星奖励
+ /**
+ * 每月蓝星奖励
+ */
+ 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;
+
+ if (bookTitle) {
+ $(e).text(`你在家门口发现了 ${item1.numWordTrans()} 和《${bookTitle}》。`);
+ }
+ else {
+ $(e).text(`你在家门口发现了 ${item1.numWordTrans()} 和 ${item2.numWordTrans()}。`);
+ }
return;
}
@@ -2761,7 +2798,7 @@
return;
}
e.firstChild.nodeValue = '你在 ';
- e.childNodes[2].nodeValue = ' 的职位从 ' + prePos + ' 变为 ' + curPos + '。';
+ e.childNodes[2].nodeValue = ` 的职位从 ${prePos} 变为 ${curPos}。`;
return;
}
@@ -2769,10 +2806,10 @@
* 加入帮派结果
*/
if ($(e).text().indexOf('join the faction') >= 0) {
- const virusName = e.childNodes[2].nodeValue.trim().split(' ')[2];
+ const rsName = e.childNodes[2].nodeValue.trim().split(' ')[2];
const rsDict = {'accepted': '通过', 'declined': '拒绝',};
e.firstChild.nodeValue = '加入帮派 ';
- e.childNodes[2].nodeValue = ' 的申请已' + rsDict[virusName] + '。';
+ e.childNodes[2].nodeValue = ` 的申请已${rsDict[rsName]}。`;
return;
}
});