更新版本号、房产页面更新、主页翻译逻辑修改、字段修正

This commit is contained in:
woohoo 2021-11-16 11:35:40 +08:00
parent fb7195a523
commit 695d22bb23

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Torn翻译 // @name Torn翻译
// @namespace WOOH // @namespace WOOH
// @version 0.1.1114b // @version 0.1.1116a
// @description UI翻译 // @description UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209] // @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/* // @match https://www.torn.com/*
@ -24,6 +24,7 @@
'Freebies': '赠品', 'Freebies': '赠品',
'Classified Ads': '分类广告', 'Classified Ads': '分类广告',
'Properties': '房产', 'Properties': '房产',
'All Properties': '所有房产',
'City': '城市', 'City': '城市',
'Education': '教育', 'Education': '教育',
'Gym': '健身房', 'Gym': '健身房',
@ -103,7 +104,7 @@
'Friends': '好友', 'Friends': '好友',
'Enemies': '敌人', 'Enemies': '敌人',
'Information': '信息', 'Information': '信息',
//'Areas': '区域', 'Areas': '区域',
'Lists': '列表', 'Lists': '列表',
'messages': '信息', 'messages': '信息',
'events': '通知', 'events': '通知',
@ -234,7 +235,7 @@
'Ranch': '山庄', 'Ranch': '山庄',
'Palace': '宫殿', 'Palace': '宫殿',
'Castle': '城堡', 'Castle': '城堡',
'Private Island': '私人岛屿PI', 'Private Island': '私人岛屿 (PI)',
'Owner': '所有人', 'Owner': '所有人',
'Owner:': '所有人:', 'Owner:': '所有人:',
'Happiness': '快乐值', 'Happiness': '快乐值',
@ -251,6 +252,23 @@
'Modifications': '改造设施', 'Modifications': '改造设施',
'Upkeep:': '维护费:', 'Upkeep:': '维护费:',
'Staff:': '雇员费用:', 'Staff:': '雇员费用:',
'Leased to': '租给了 ',
'Owned by your spouse': '为你的配偶所有',
'Owned by you': '为你所有',
'All Properties': '所有房产',
'Your Properties': '你的房产',
"Spouse's Properties": '配偶的房产',
"Spouse's": '配偶的',
'All': '所有',
'Yours': '你的',
'Customize this property': '自定义该房产',
'Travel': '起飞',
'Kick your spouse out of this property': '把你的配偶赶出该房产',
'Pay upkeep': '支付维护费',
'Move into this property': '搬进该房产',
'Sell this property': '出售该房产',
'Lease this property': '出租该房产',
'Give this property to someone': '赠送该房产给某人',
}; };
const travelingDict = { const travelingDict = {
'Remaining Flight Time -': '剩余时间 - ', 'Remaining Flight Time -': '剩余时间 - ',
@ -759,7 +777,9 @@
'Rank': '阶级', 'Rank': '阶级',
'Networth': '身价', 'Networth': '身价',
'SPEND': '升级', 'SPEND': '升级',
'CHANGE': '更改',
'Cancel': '取消', 'Cancel': '取消',
'Are you sure you want to change your name background to this Honor?': '确定修改你的名字背景为这个荣誉吗?',
'Nerve Bar': '犯罪N上限', 'Nerve Bar': '犯罪N上限',
'Critical Hit Rate': '暴击率', 'Critical Hit Rate': '暴击率',
@ -844,7 +864,7 @@
'This upgrade will increase the amount of items you can find in the city, however it will not necessarily increase their quality.': 'This upgrade will increase the amount of items you can find in the city, however it will not necessarily increase their quality.':
'该升级会增加你在城市中能找到的物品数量,但不一定能提高它们的质量。', '该升级会增加你在城市中能找到的物品数量,但不一定能提高它们的质量。',
'This upgrade will give you an increase of 5% to your investment bank interest. This upgrade will start working on your next investment.': 'This upgrade will give you an increase of 5% to your investment bank interest. This upgrade will start working on your next investment.':
'这一升级将使你的银行利息增加 5%。这项升级将在你开始的下一个教育课程中开始生效。', '这一升级将使你的银行利息增加 5%。这项升级将在下一次银行投资中生效。',
'This upgrade will give you a 5% boost in money that you mug from opponents. Perfect for experienced muggers, looking for some extra cash.': 'This upgrade will give you a 5% boost in money that you mug from opponents. Perfect for experienced muggers, looking for some extra cash.':
'这个升级将使你从对手那里抢来的钱增加5%。非常适合有经验的抢劫者,赚些额外的钱钱。', '这个升级将使你从对手那里抢来的钱增加5%。非常适合有经验的抢劫者,赚些额外的钱钱。',
"This upgrade will make you more likely to stay stealthed when beating an opponent by increasing your stealth level by 0.2 per increment. When you're stealthed, your name will be listed as 'Someone' so your enemy will not know who hit them.": "This upgrade will make you more likely to stay stealthed when beating an opponent by increasing your stealth level by 0.2 per increment. When you're stealthed, your name will be listed as 'Someone' so your enemy will not know who hit them.":
@ -904,8 +924,14 @@
} }
// 边栏块标题 // 边栏块标题
$('h2[class^="header"]').each((i, e) => { $('h2[class^="header"]').each((i, e) => {
if (sidebarDict[e.firstChild.nodeValue]) if (!sidebarDict[e.firstChild.nodeValue]) return;
e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue];
// if ($(e).css('display')!=='none' && sidebarDict[e.firstChild.nodeValue]) {
// let original=$(e).clone(true);
// original.text(original.text().replace(e.firstChild.nodeValue,sidebarDict[e.firstChild.nodeValue]));
// $(e).css('display', 'none').after(original);
// $(original).append($(e).children('i'));
// }
}); });
// 边栏人物名字 // 边栏人物名字
$('span[class^="menu-name"]').each((i, e) => { $('span[class^="menu-name"]').each((i, e) => {
@ -938,6 +964,13 @@
e.nodeValue = sidebarDict[e.nodeValue]; e.nodeValue = sidebarDict[e.nodeValue];
}); });
// let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]');
// if (barDescr.length !== 0) {
// barDescr[0].childNodes.forEach(i => {
// if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue];
// })
// }
clearInterval(sidebarInterval); clearInterval(sidebarInterval);
}, 1000); }, 1000);
@ -951,20 +984,7 @@
miniprofOB.observe($('div.profile-mini-root').get(0), {attributes: true, childList: true, subtree: true}); miniprofOB.observe($('div.profile-mini-root').get(0), {attributes: true, childList: true, subtree: true});
}); });
const miniprofTrans = function miniprofTrans() { const miniprofTrans = function miniprofTrans() {
// let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); // console.log('111');
// if (barDescr.length !== 0) {
// barDescr[0].childNodes.forEach(i => {
// if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue];
// })
// }
// let miniprof_tooltip = $("#body > div.ToolTipPortal > div > div:nth-child(2)");
// if (miniprof_tooltip.length !== 0) {
// if (tooltipDict[miniprof_tooltip[0].firstChild.nodeValue]) {
// miniprof_tooltip[0].firstChild.nodeValue = tooltipDict[miniprof_tooltip[0].firstChild.nodeValue];
// }
// } else {
// //todo 通配符匹配
// }
}; };
if ($('div.profile-mini-root').length > 0) if ($('div.profile-mini-root').length > 0)
miniprofTrans(); miniprofTrans();
@ -1192,13 +1212,18 @@
titleTrans(); titleTrans();
contentTitleLinksTrans(); contentTitleLinksTrans();
let homeEvents = null; //let homeEvents = null;
// 主页黑框标题文字翻译
$('h5.box-title').each((i, e) => { $('h5.box-title').each((i, e) => {
if (!homeDict[e.firstChild.nodeValue]) return; if (!homeDict[e.firstChild.nodeValue]) return;
// 翻译最近5条通知
if (e.firstChild.nodeValue === 'Latest Events') { if (e.firstChild.nodeValue === 'Latest Events') {
homeEvents = $(e).parent().next().find('span'); //homeEvents = $(e).parent().next().find('span');
} else if (e.firstChild.nodeValue === 'Latest Attacks') { eventsTrans($(e).parent().next().find('span'));
}
// 翻译最近5个攻击
else if (e.firstChild.nodeValue === 'Latest Attacks') {
$(e).parent().next().find('span').each(function () { $(e).parent().next().find('span').each(function () {
let nodes = $(this)[0].childNodes; let nodes = $(this)[0].childNodes;
nodes.forEach((v, i) => { nodes.forEach((v, i) => {
@ -1219,16 +1244,18 @@
}, this); }, this);
}); });
} }
e.firstChild.nodeValue = homeDict[e.firstChild.nodeValue]; //e.firstChild.nodeValue = homeDict[e.firstChild.nodeValue];
// 隐藏原dom元素避免与torntools发生冲突
if ($(e).css('display')!=='none')
$(e).css('display','none').after(`<h5 class="box-title">`+homeDict[e.firstChild.nodeValue]+`</h5>`);
}); });
// 各表格左边的键
$('span.divider span').each((i, e) => { $('span.divider span').each((i, e) => {
if (homeDict[$(e).text()]) if (homeDict[$(e).text()])
$(e).text(homeDict[$(e).text()]); $(e).text(homeDict[$(e).text()]);
}); });
eventsTrans(homeEvents);
return; return;
} }
@ -1615,18 +1642,23 @@
} }
/** /**
* properties 从玩家租买和自己的房子页面 * properties todo
*/ */
if (window.location.href.indexOf('properties.php') >= 0) { if (window.location.href.indexOf('properties.php') >= 0) {
const isRent = window.location.href.indexOf('rent') >= 0; const isRent = window.location.href.indexOf('rent') >= 0;
// const isRentOrSell = isRent || window.location.href.indexOf('sell') >= 0;
// const isOption = window.location.href.indexOf('p=options') >= 0;
// const isExtension = window.location.href.indexOf('step=viewOfferExtension') >= 0;
const propertyOB = new MutationObserver(() => { const propertyOB = new MutationObserver(() => {
propertyOB.disconnect(); propertyOB.disconnect();
titleTrans(); titleTrans();
contentTitleLinksTrans(); contentTitleLinksTrans();
propertyTrans(); propertyTrans();
propertyOB.observe($('div#properties-page-wrap')[0], {childList: true, subtree: true}); propertyOB.observe($('div.content-wrapper').get(0), {childList: true, subtree: true});
}); });
const propertyTrans = function propertyTrans() { const propertyTrans = function propertyTrans() {
// 从玩家处租或买
if (isRent || window.location.href.indexOf('sell') >= 0) {
// 黑框标题 // 黑框标题
$('div.title-black span').each((i, e) => { $('div.title-black span').each((i, e) => {
e.firstChild.nodeValue = '您想查看哪些房产?'; e.firstChild.nodeValue = '您想查看哪些房产?';
@ -1645,21 +1677,6 @@
$(e).text(propertyDict[$(e).text()]); $(e).text(propertyDict[$(e).text()]);
}); });
// 确认购买提示 // 确认购买提示
/**
<span class="question">
<p>Are you sure you want to rent this Castle</p>
<p> for <span class="bold">$4,000,000</span> for a period of <span class="bold">30</span> days?</p>
<a class="t-blue bold m-left10 yes-btn c-pointer" href="#" data-id="258786" data-market="rental" data-price="4000000" i-data="i_759_415_21_14">Yes</a>
<a class="t-blue no-btn bold m-left10 c-pointer" href="#" i-data="i_793_415_16_14">No</a>
</span>
<span class="question">
<p>Are you sure you want to buy <span class="t-red bold">another</span> Private Island</p>
<p> for <span class="bold">$1,705,000,000</span>?</p>
<a class="t-blue bold m-left10 yes-btn c-pointer" href="#" data-id="3176475" data-market="selling" data-price="1705000000">Yes</a>
<a href="#" class="t-blue no-btn bold m-left10 c-pointer">No</a>
</span>
*/
$('div[class="confirm-text"] span.question').each((i, e) => { $('div[class="confirm-text"] span.question').each((i, e) => {
const propName = e.firstElementChild.innerText.trim().split(' ').slice(8).join(' '); const propName = e.firstElementChild.innerText.trim().split(' ').slice(8).join(' ');
@ -1714,10 +1731,46 @@
if (propertyDict[e.firstChild.nodeValue]) if (propertyDict[e.firstChild.nodeValue])
e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue]; e.firstChild.nodeValue = propertyDict[e.firstChild.nodeValue];
}); });
return;
}
// 房屋选项
if (window.location.href.indexOf('p=options') >= 0) {
return;
}
// 房屋详情
if (window.location.href.indexOf('p=propertyinfo') >= 0) {
return;
}
// 延期、合同
if (window.location.href.indexOf('step=viewOfferExtension') >= 0) {
return;
}
// 自己的所有房产 页面
{
// 顶部3标题
$('ul.property-tabs a.ui-tabs-anchor div').contents().each((i, e) => {
if (propertyDict[e.nodeValue]) {
e.nodeValue = propertyDict[e.nodeValue];
}
});
// 图片下的描述部分
$('ul.properties-list div.image-description').find('*')
.contents().each((i, e) => {
if (e.nodeType !== 3) return;
if (!propertyDict[e.nodeValue.trim()]) return;
e.nodeValue = propertyDict[e.nodeValue.trim()];
});
// 图片下的按钮的title浮动框文字
$('div#properties-page-wrap a[title]').each((i, e) => {
if (propertyDict[$(e).attr('title')])
$(e).attr('title', propertyDict[$(e).attr('title')]);
});
}
}; };
propertyTrans(); propertyTrans();
propertyOB.observe($('div#properties-page-wrap')[0], {childList: true, subtree: true}); propertyOB.observe($('div.content-wrapper').get(0), {childList: true, subtree: true});
return; return;
} }
@ -1797,6 +1850,21 @@
if (awDict[desc]) if (awDict[desc])
$(e).attr('data-title', $(e).attr('data-title').replace(desc, awDict[desc])); $(e).attr('data-title', $(e).attr('data-title').replace(desc, awDict[desc]));
}); });
// 改变荣誉条时的提示
$('div#honors div.msg').each((i,e)=>{
if(awDict[$(e).text().trim()])
$(e).text(awDict[$(e).text().trim()]);
});
// 改变荣誉条时的提示按钮 change
$('div#honors div.confirm-msg button').each((i,e)=>{
if(awDict[$(e).text().trim()])
$(e).text(awDict[$(e).text().trim()]);
});
// 改变荣誉条时的提示按钮 cancel
$('div#honors div.confirm-msg a.cancel').each((i,e)=>{
if(awDict[$(e).text().trim()])
$(e).text(awDict[$(e).text().trim()]);
});
// 技能页面 Available Merits: x Merits Used: x // 技能页面 Available Merits: x Merits Used: x
$('div.awards-msg p').contents().each((i, e) => { $('div.awards-msg p').contents().each((i, e) => {
if (e.nodeType === 3) if (e.nodeType === 3)
@ -1887,7 +1955,9 @@
if (window.location.href.indexOf('level2.php') >= 0) { if (window.location.href.indexOf('level2.php') >= 0) {
} }
/** 医院页面 **/ /**
* 医院页面
*/
if (window.location.href.indexOf("hospitalview.php") >= 0) { if (window.location.href.indexOf("hospitalview.php") >= 0) {
const hospitalOB = new MutationObserver(hosOBInit); const hospitalOB = new MutationObserver(hosOBInit);
@ -1948,7 +2018,9 @@
return; return;
} }
/** 帮派页面 **/ /**
* 帮派页面
*/
if (window.location.href.indexOf("actions.php") >= 0) { if (window.location.href.indexOf("actions.php") >= 0) {
const factionOB = new MutationObserver(factionOBInit); const factionOB = new MutationObserver(factionOBInit);