调整通知,更新报纸、房屋交易

This commit is contained in:
woohoo 2021-11-08 01:06:38 +08:00
parent c603a85c8d
commit 51a709047a

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1106b
// @version 0.1.1108a
// @description UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/*
@ -9,8 +9,12 @@
// ==/UserScript==
!(function () {
(function () {
'use strict';
const ___win_WHTRANS = window || window.unsafeWindow;
if (___win_WHTRANS.WHTRANS) return;
___win_WHTRANS.WHTRANS = true;
const $ = window.jQuery;
const sidebarDict = { // todo 从json加载
'Money': '现金',
@ -143,20 +147,29 @@
'Tutorial': '教程',
};
const newspaperDict = {
'front page': '报纸头版',
'front page': '头版',
'archive': '归档',
'job listing': '工作清单',
'properties': '房产信息',
'job listing': '工作',
'properties': '房产',
'freebies': '赠品',
'classified ads': '分类广告',
'personals': '个人情感',
'classified ads': '广告',
'personals': '情感',
'bounties': '悬赏',
'comics': '漫画',
'chronicles': '纪事档案馆',
'TCSE Market Index':'TCSE 股票指数',
'Weekly bazaars':'每周小店',
'LOTTERY':'幸运彩票',
'BOUNTIES':'精选悬赏',
'TC PERSONALS':'托恩情感',
'Why not visit our sponsor?':'为什么不访问我们的赞助商呢?',
'View all':'查看所有',
'Advertise here':'在此刊登广告',
};
const titleDict = {
'Home': '主页',
'Estate Agents': '地产中介',
'Newspaper':'报纸',
};
const propertyDict = {
'Trailer': '拖车',
@ -174,13 +187,18 @@
'Castle': '城堡',
'Private Island': '私人岛屿PI',
'Owner': '所有人',
'Owner:': '所有人:',
'Happiness': '快乐值',
'Happiness:': '快乐值:',
'Cost': '花费',
'Cost:': '花费:',
'Cost per Day': '平均日花费',
'Rental Period': '租期',
'Rent': '租赁',
'Info': '信息',
'Buy': '购买',
'Property:': '房屋:',
'Modifications': '改造设施',
};
const travelingDict = { // todo jsonify
'Recruit Citizens': '招募玩家',
@ -301,7 +319,7 @@
// 手机 区域菜单
$('div[class*="areas-mobile"] span:nth-child(2)').contents().each((i, e) => {
console.log(e);
//console.log(e);
if (sidebarDict[e.nodeValue])
e.nodeValue = sidebarDict[e.nodeValue];
});
@ -368,44 +386,50 @@
/**
* 报纸菜单
*/
if (window.location.href.indexOf('newspaper.php') >= 0 ||
window.location.href.indexOf('joblist.php') >= 0 ||
window.location.href.indexOf('freebies.php') >= 0 ||
window.location.href.indexOf('newspaper_class.php') >= 0 ||
window.location.href.indexOf('personals.php') >= 0 ||
window.location.href.indexOf('bounties.php') >= 0 ||
if (window.location.href.indexOf('newspaper.php') >= 0 || window.location.href.indexOf('joblist.php') >= 0 ||
window.location.href.indexOf('freebies.php') >= 0 || window.location.href.indexOf('newspaper_class.php') >= 0 ||
window.location.href.indexOf('personals.php') >= 0 || window.location.href.indexOf('bounties.php') >= 0 ||
window.location.href.indexOf('comics.php') >= 0) {
const newspaperOB = new MutationObserver(newspaperOBInit);
function newspaperOBInit(){
newspaperOB.disconnect();
newspaperTrans();
newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true});
}
function newspaperTrans(){
titleTrans();
let newspaperMenuOB = new MutationObserver(newspaperFunc);
const isOnBountyPage = window.location.href.indexOf('bounties.php') >= 0;
function newspaperFunc(isOBRunning = true) {
contentTitleLinksTrans();
if ($('a.newspaper-link').length === 0) return;
// 报纸菜单
// 导航菜单
$('a.newspaper-link').contents().each((i, e) => {
if (newspaperDict[e.nodeValue])
e.nodeValue = newspaperDict[e.nodeValue];
});
// 公众号广告
$('div.price.left').contents()[2].nodeValue = '文章翻译请关注中文公众号Torncity';
if (isOBRunning && !isOnBountyPage) {
newspaperMenuOB.disconnect();
// 日期翻译
const date = new Date($('span.date-label').text());
if(date.format('yyyy')!=='NaN')
$('span.date-label').text(date.format('yyyy年MM月dd日'));
// 右边栏
$('div[class^="sideCont"] [class^="title"]').contents().each((i, e) => {
if(newspaperDict[e.nodeValue])
e.nodeValue=newspaperDict[e.nodeValue];
});
// 彩票信息
$('span[class^="winner"]').each((i,e)=>{});
// 底部链接
// Why not visit our sponsor?
if(newspaperDict[$('div.link-left').text().trim()])
$('div.link-left').text(newspaperDict[$('div.link-left').text().trim()]);
// View all | Advertise here
$('div.link-right a').contents().each((i,e)=>{
if(newspaperDict[e.nodeValue.trim()])
e.nodeValue=newspaperDict[e.nodeValue.trim()];
})
}
if (isOnBountyPage) {
let btInterval = setInterval(() => {
newspaperMenuOB.disconnect();
clearInterval(btInterval);
}, 1000);
}
}
if ($('a.newspaper-link').length === 0 || isOnBountyPage) {
newspaperMenuOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true});
} else {
newspaperFunc(false);
}
contentTitleLinksTrans();
newspaperTrans();
newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true});
return;
}
@ -443,13 +467,15 @@
if (propertyDict[e.nodeValue])
e.nodeValue = propertyDict[e.nodeValue];
});
//搜索按钮
$('div.btn-search button').text('搜索');
$('div.search-text a').text('搜索');
// 表头信息
$('div.users-list-title div').each((i, e) => {
if (propertyDict[$(e).text()])
$(e).text(propertyDict[$(e).text()]);
});
// 提示确认购买
// 确认购买提示
/**
<span class="question">
<p>Are you sure you want to rent this Castle</p>
@ -466,8 +492,6 @@
</span>
*/
$('div[class="confirm-text"] span.question').each((i, e) => {
//const cost=e.children[1].innerText.trim().split(' ')[1];
//const period=isRent?e.children[1].innerText.trim().split(' ')[6]:null;
const propName = e.firstElementChild.innerText.trim().split(' ').slice(8).join(' ');
const hasAnother = $(e).text().indexOf('another') > 0;
@ -476,8 +500,7 @@
e.firstElementChild.firstChild.nodeValue += isRent ? '租用' : '购买';
e.firstElementChild.childNodes[1].firstChild.nodeValue = '另一个';
e.firstElementChild.childNodes[2].nodeValue = propertyDict[propName];
}
else{
} else {
e.firstElementChild.firstChild.nodeValue = '你确定要';
e.firstElementChild.firstChild.nodeValue += isRent ? '租用' : '购买';
e.firstElementChild.firstChild.nodeValue += propertyDict[propName];
@ -488,6 +511,38 @@
e.children[1].childNodes[4].nodeValue = ' 天?';
});
// 房屋详情表格
$('div.info-block span.bold').each((i, e) => {
// 2 6 10 14 18 22 26 30 ...
if (i % 4 === 2) {
/**
* <span class="bold">
<span class="title-laptop">On </span>
"Market"
<span class="title-desktop"> Price</span>
":"
</span>
*/
e.firstElementChild.firstChild.nodeValue = '';
e.childNodes[2].nodeValue = '市场价';
e.childNodes[3].firstChild.nodeValue = '';
e.childNodes[4].nodeValue = '';
} else {
if (propertyDict[e.firstChild.nodeValue.trim()])
e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue.trim()];
}
});
// 窄边 cost happy
$('span.title-laptop.bold').each((i, e) => {
if (propertyDict[$(e).text().trim()])
$(e).text(propertyDict[$(e).text().trim()]);
});
// modification
$('div.title.bold.left').each((i, e) => {
if (propertyDict[e.firstChild.nodeValue])
e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue];
});
propertyOB.observe($('div#properties-page-wrap')[0], {childList: true, subtree: true});
});
@ -559,20 +614,20 @@
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];
const bestLap = e.childNodes[2].nodeValue.split(' best lap was ')[1].slice(0, 8);//.split(' ')[0];
let map = splitList[3];
map = map === 'Two' ? 'Two Islands' : map;
map = map === 'Stone' ? 'Stone Park' : map;
e.firstChild.nodeValue = '你在赛车比赛 ' + map + ' 中获得第 ';
e.firstChild.nodeValue = '你在赛车比赛 ' + map + ' 中获得第 ';
e.childNodes[1].firstChild.nodeValue = pos;
e.childNodes[2].nodeValue = ' 名';
e.childNodes[2].nodeValue = ' 名';
if (isGainRacingPoint >= 0) {
e.childNodes[2].nodeValue += '获得' + racingPoint + '赛车点数。';
e.childNodes[2].nodeValue += '获得' + racingPoint + '赛车点数Racing Points。';
}
e.childNodes[2].nodeValue += '你的最佳成绩是 ' + bestLap;
e.childNodes[2].nodeValue += '你的最佳圈速是 ' + bestLap;
if (isBeat)
e.childNodes[2].nodeValue += ',比之前最佳 ' + record + ' 快 ' + bestBy;
e.childNodes[2].nodeValue += '。'
@ -913,13 +968,19 @@
* failed to bust you out of jail.
*/
if ($(e).text().indexOf('bust') >= 0) {
if ($(e).text().indexOf('to bust') >= 0) { // 失败
e.childNodes[1].nodeValue = ' 尝试把你从监狱里救出来,但是失败了。';
if (e.childNodes[1].nodeValue[1] === 'f') { // 失败
e.childNodes[1].nodeValue = ' 没能把你从监狱救出来。';
return;
}
if (e.childNodes[1].nodeValue[1] === 'w') { // 失败被抓
e.childNodes[1].nodeValue = ' 在尝试救你出狱时被抓了。';
return;
}
if (e.childNodes[1].nodeValue[1] === 's') {
e.childNodes[1].nodeValue = ' 成功把你从监狱里救了出来。';
return;
}
}
/**
* 保释
@ -930,6 +991,30 @@
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().indexOf('given $') >= 0) {
const money = e.firstChild.nodeValue.split(' ')[3];
let isNamed = e.childNodes.length > 1;
if (isNamed) {
e.firstChild.nodeValue = '';
e.childNodes[2].nodeValue = ' 为你从帮派取了 ' + money + '。';
} else {
e.firstChild.nodeValue = '你得到了从帮派取出的 ' + money + '。';
}
return;
}
/**
* 教育完成
* <a href="/education.php" i-data="i_199_234_363_14">The education course you were taking has ended. Please click here.</a>
@ -1035,4 +1120,4 @@
$('h4#skip-to-content').text(titleDict[$('h4#skip-to-content').text().trim()]);
}
})();
}());