wuhu-torn-helper/zhcn_translate.js
2021-11-03 07:18:36 +00:00

272 lines
10 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==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]按钮
$('#pointsMerits')[0].firstChild.nodeValue = '[使用]';
$('#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');
//初始化中内容未加载
let eventInterval = setInterval(() => {
console.log('循环判断内容是否已加载')
if (events.length === 0) {
events = $('span.mail-link');
return;
}
clearInterval(eventInterval);
eventsTrans();
}, 1000);
function eventsTrans() {
events.each((i, e) => {
if ($(e).text().indexOf('finished') >= 0) { // 赛车
const isBestLap = $(e).text().indexOf('best lap') >= 0;
const isGainRacingPoint = $(e).text().indexOf('racing point') >= 0;
const pos = e.childNodes[1].firstChild.nodeValue
.split('')[0].match(/[0-9]+/)[0];
const splitList = e.childNodes[2].nodeValue.split(' ');
let map = splitList[3];
map = map === 'Two' ? 'Two Islands' : map;
map = map === 'Stone' ? 'Stone Park' : map;
e.firstChild.nodeValue = '你在 ' + map + ' 赛车比赛中获得了第 '//+pos+'名。';
e.childNodes[1].nodeValue = pos;
e.childNodes[2].nodeValue = '名。';
if (isGainRacingPoint) {
const racingPoint = splitList[-9];
e.childNodes[2].nodeValue += '你获得了' + racingPoint + '赛车点数。';
}
if (isBestLap) {
const bestLap = splitList[-2];
e.childNodes[2].nodeValue += '你的最好成绩是' + bestLap + '。';
}
e.childNodes[2].nodeValue += ' [';
e.childNodes[3].firstChild.nodeValue = '查看';
return;
}
if ($(e).text().indexOf('Loan Shark') >= 0) { // 还贷
return;
}
if ($(e).text().indexOf('sent') >= 0) { // 收到钱物
if ($(e).text().indexOf('message') >= 0) { // 附带信息
return;
} else {
return;
}
}
if ($(e).text().indexOf('bazaar') >= 0) { // bazaar
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;
}
}
if ($(e).text().indexOf('lottery') >= 0) { // 每日彩票
return;
}
if ($(e).text().indexOf('organized crime') >= 0) { // oc开启
return;
}
if ($(e).text().indexOf('You and your team') >= 0) { // oc结束
return;
}
if ($(e).text().indexOf('successfully busted') >= 0) { // 劫狱成功
return;
}
if ($(e).text().indexOf('trying to bust') >= 0 ||
$(e).text().indexOf('failed to bust') >= 0) { // 劫狱失败
return;
}
if ($(e).text().indexOf('Loan Shark') >= 0) { // 还贷
return;
}
if ($(e).text().indexOf('doorstep') >= 0) { // 蓝星奖励
return;
}
});
}
}
})();