更新股票页面

This commit is contained in:
woohoo 2021-11-23 19:01:32 +08:00
parent deff52881b
commit b9e240a4c4

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Torn翻译 // @name Torn翻译
// @namespace WOOH // @namespace WOOH
// @version 0.1.1121a // @version 0.1.1123a
// @description Torn UI翻译 // @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209] // @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/* // @match https://www.torn.com/*
@ -37,6 +37,7 @@
'Awards': '勋章', 'Awards': '勋章',
'Faction': '帮派', 'Faction': '帮派',
'Your Properties': '你的房产', 'Your Properties': '你的房产',
'Stock Market': '股市',
'Spouse\'s Properties': '配偶的房产', 'Spouse\'s Properties': '配偶的房产',
}; };
const titleLinksDict = { const titleLinksDict = {
@ -688,7 +689,7 @@
'bounty reward': '赏金', 'bounty reward': '赏金',
'Someone hospitalized': '某人强制住院了', 'Someone hospitalized': '某人强制住院了',
'You pop the LSD pill into your mouth and down a glass of water. A headache is followed by nausea and vomiting. You have overdosed.': 'You pop the LSD pill into your mouth and down a glass of water. A headache is followed by nausea and vomiting. You have overdosed.':
'你把 LSD 塞进嘴里,然后喝下一杯水。头痛之后是恶心和呕吐。你用药过量了。', '你把 LSD 塞进嘴里,然后喝下一杯水。头痛之后是恶心和呕吐。你用药过量了(OD)。',
'Your application to join the company': '加入公司 ', 'Your application to join the company': '加入公司 ',
'has been declined': ' 的申请已被拒绝。', 'has been declined': ' 的申请已被拒绝。',
'has been accepted': ' 的申请已被通过。', 'has been accepted': ' 的申请已被通过。',
@ -722,6 +723,8 @@
'MAN': '体力 (MAN)', 'MAN': '体力 (MAN)',
'END': '耐心 (END)', 'END': '耐心 (END)',
'INT': '智力 (INT)', 'INT': '智力 (INT)',
'You took some Xanax and downed a glass of water. A headache was followed by nausea and vomiting. You overdosed.':
'你吃了一些 Xanax喝了一杯水。头痛之后是恶心和呕吐。你用药过量了(OD)。',
}; };
const chatDict = { const chatDict = {
'Global': '世界', 'Global': '世界',
@ -1091,18 +1094,107 @@
'ENEMY': '敌人', 'ENEMY': '敌人',
'FRIEND': '朋友', 'FRIEND': '朋友',
'Cancel': '取消', 'Cancel': '取消',
'You are currently traveling': '目前你还在飞行中',
'You are not in Torn': '你不在城内',
'You don\'t own a Laptop!': '你没有笔记本电脑',
'View {$}\'s display cabinet': '查看 {$} 的展示柜',
}; };
const sendCashDict = { const sendCashDict = {
'Some players may be out to part you from your money, using any means necessary. Use the secure trade feature if you want to protect an exchange and check the contents very carefully.': 'Some players may be out to part you from your money, using any means necessary. Use the secure trade feature if you want to protect an exchange and check the contents very carefully.':
'有些玩家可能会利用任何必要的手段来骗走你的钱。如果你想保护交易,请使用更安全的“交易”功能,并仔细检查交易的内容。', '有些玩家可能会利用任何必要的手段来骗走你的钱。如果你想保护交易,请使用更安全的“交易”功能,并仔细检查交易的内容。',
'Do not fall for scams!':'切勿上当受骗!', 'Do not fall for scams!': '切勿上当受骗!',
'For more info please visit here.':'欲了解更多信息,请点击访问。', 'For more info please visit here.': '欲了解更多信息,请点击访问。',
'SEND':'发送', 'SEND': '发送',
'Cancel':'取消', 'Cancel': '取消',
'Message (optional, up to 200 characters)':'附带信息 (可选最多200字符)', 'Message (optional, up to 200 characters)': '附带信息 (可选最多200字符)',
'Click here to add the maximum amount, or use shortcuts like <br /> 5k, 1.5m, max, half, quarter, 1/2, 1/3, 1/4, 25%': 'Click here to add the maximum amount, or use shortcuts like <br /> 5k, 1.5m, max, half, quarter, 1/2, 1/3, 1/4, 25%':
'点此添加最大额度,或输入快捷选项如 <br /> 5k, 1.5m, max, half, quarter, 1/2, 1/3, 1/4, 25%', '点此添加最大额度,或输入快捷选项如 <br /> 5k, 1.5m, max, half, quarter, 1/2, 1/3, 1/4, 25%',
}; };
const stockDict = {
'Stock': '股票',
'Name': '名称',
'Price': '单价',
'1h': '1时',
'24h': '24时',
'7d': '7天',
'1m': '1月',
'1y': '1年',
'Live': '实时',
'live': '实时',
'Last hour': '过去一小时',
'Last day': '过去一天',
'Last week': '过去一周',
'Last month': '过去一个月',
'Last year': '过去一年',
'Owned': '持有',
'Dividend': '分红',
'West Side University': '西城大学',
'Insured On Us': '',
'Torn City Investments': 'Torn City 投资',
'Torn & Shanghai Banking': 'Torn 和上海银行',
'Symbiotic Ltd.': '共生公司',
'Crude & Co': '原油公司',
'Feathery Hotels Group': '飞亚达酒店集团',
'Mc Smoogle Corp': '麦斯莫格公司',
'Wind Lines Travel': '风线旅行',
'Performance Ribaldry': '',
'Syscore MFG': '',
'Evil Ducks Candy Corp': '邪恶鸭糖果公司',
'Munster Beverage Corp.': '明斯特饮料公司',
'Torn City Clothing': 'Torn City 服饰',
'Lucky Shots Casino': '幸运赌场',
'TC Media Productions': '',
'International School TC': '',
'Big Al\'s Gun Shop': '',
'Torn City Health Service': '',
'Alcoholics Synonymous': '',
'Torn City Motors': '',
'Legal Authorities Group': '',
'The Torn City Times': '',
'Grain': '谷物',
'Eaglewood Mercenary': '',
'Home Retail Group': '',
'Empty Lunchbox Traders': '',
'Messaging Inc.': '',
'TC Music Industries': '',
'I Industries Ltd.': '',
'Tell Group Plc.': '',
'Yazoo': '',
'10% Bank Interest Bonus': '10% 银行利润增益',
'Inactive': '未激活',
// '$50,000,000': '',
// '1x Drug Pack': '',
// '$80,000,000': '',
// '1x Feathery Hotel Coupon': '',
'100 Energy': '100 能量E',
'Private Jet Access': '解锁私人飞机',
// '1x Erotic DVD': '',
'1000 Happiness': '1000 快乐',
'Advanced Firewall': '高级防火墙',
// '1x Six Pack of Energy Drink': '',
// '1x Clothing Cache': '',
'Company Sales Boost': '提升公司销售',
// '1x Lottery Voucher': '',
'Free Education Courses': '免费教育课程',
// '1x Ammunition Pack': '',
// '1x Box of Medical Supplies': '',
// '1x Six Pack of Alcohol': '',
'10% Racing Skill Boost': '提升 10% 赛车技能增长',
// '1x Lawyer Business Card': '',
// '$1,000,000': '',
// '$4,000,000': '',
// '1x Box of Grenades': '',
'1x Random Property': '1 个随机房产',
'10% Home Upgrade Discount': '10% 房屋设施费用折扣',
'Free Classified Advertising': '免费分类广告',
// '$25,000,000': '',
// '$12,000,000': '',
'50% Coding Time Reduction': '缩减 50% 变成时间',
'Company Advertising Boost': '',
'10% Course Time Reduction': '缩减 10% 教育时间',
'Benefit active': '已激活分红',
'Free Banner Advertising': '免费横幅广告',
};
// 默认开启通知翻译 // 默认开启通知翻译
if (!localStorage.getItem('wh_trans_event')) { if (!localStorage.getItem('wh_trans_event')) {
@ -1742,6 +1834,54 @@
return; return;
} }
/**
* 股票
*/
if (window.location.href.contains(/page\.php\?sid=stocks/)) {
const stockOB = new MutationObserver(() => {
stockOB.disconnect();
titleTrans();
contentTitleLinksTrans();
stockTrans();
stockOB.observe($('.content-wrapper').get(0), {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
});
const stockTrans = function stockTrans() {
// 表头
$('ul.title-black').find('*').contents().each((i, e) => {
if (e.nodeType === 3 && stockDict[e.nodeValue.trim()]) {
e.nodeValue = stockDict[e.nodeValue.trim()];
}
});
// 名称
$('div[class^="nameContainer"]').each((i, e) => {
if (e.childNodes[0].nodeValue && stockDict[e.childNodes[0].nodeValue.trim()]) {
e.childNodes[0].nodeValue = stockDict[e.childNodes[0].nodeValue.trim()];
}
});
// 右侧bb名
let i=0;
$('div[class^="dividendInfo"] p').each((i,e)=>{
if (stockDict[$(e).text().trim()]) {
$(e).text(stockDict[$(e).text().trim()]);
console.log(++i)
}
});
};
stockTrans();
stockOB.observe($('.content-wrapper').get(0), {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
return;
}
/** /**
* 教育页面 * 教育页面
*/ */
@ -1849,7 +1989,12 @@
titleTrans(); titleTrans();
contentTitleLinksTrans(); contentTitleLinksTrans();
profileTrans(); profileTrans();
profileOB.observe($('.content-wrapper').get(0), {characterData:true,attributes: true, subtree: true, childList: true}); profileOB.observe($('.content-wrapper').get(0), {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
}); });
const profileTrans = function profileTrans() { const profileTrans = function profileTrans() {
const playerName = document.title.trim().split("'s ").length === 2 const playerName = document.title.trim().split("'s ").length === 2
@ -1864,11 +2009,12 @@
$('.content-wrapper .title-black').each((i, e) => { $('.content-wrapper .title-black').each((i, e) => {
if (i === 1) { if (i === 1) {
if (profileDict[e.firstChild.nodeValue.trim().replace(playerName, '{$}')]) { if (profileDict[e.firstChild.nodeValue.trim().replace(playerName, '{$}')]) {
e.firstChild.nodeValue=( e.firstChild.nodeValue = (
profileDict[$(e).text().trim().replace(playerName, '{$}')] profileDict[$(e).text().trim().replace(playerName, '{$}')]
.replace('{$}', playerName) .replace('{$}', playerName)
); );
} }
return;
} }
if (profileDict[$(e).text().trim()]) { if (profileDict[$(e).text().trim()]) {
$(e).text(profileDict[$(e).text().trim()]); $(e).text(profileDict[$(e).text().trim()]);
@ -1921,14 +2067,14 @@
} }
// 添加敌人或朋友的界面 // 添加敌人或朋友的界面
$('.add-user .reason-wrapper').find('*').contents().each((i,e)=>{ $('.add-user .reason-wrapper').find('*').contents().each((i, e) => {
if (e.nodeType === 3) { if (e.nodeType === 3) {
if (profileDict[e.nodeValue.trim()]) { if (profileDict[e.nodeValue.trim()]) {
e.nodeValue = profileDict[e.nodeValue.trim()]; e.nodeValue = profileDict[e.nodeValue.trim()];
} else if (/\b[1-4]?[0-9]\b/.test(e.nodeValue.trim().slice(0,2))) { } else if (/\b[1-4]?[0-9]\b/.test(e.nodeValue.trim().slice(0, 2))) {
const left = e.nodeValue.trim().slice(0,2); const left = e.nodeValue.trim().slice(0, 2);
if (profileDict['{$} characters left']) { if (profileDict['{$} characters left']) {
e.nodeValue = profileDict['{$} characters left'].replace('{$}',left); e.nodeValue = profileDict['{$} characters left'].replace('{$}', left);
} }
} }
} }
@ -1937,7 +2083,12 @@
sendCashTrans(); sendCashTrans();
}; };
profileTrans('.content-wrapper'); profileTrans('.content-wrapper');
profileOB.observe($('.content-wrapper').get(0), {characterData:true,attributes: true, subtree: true, childList: true}); profileOB.observe($('.content-wrapper').get(0), {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
return; return;
} }
@ -1945,7 +2096,7 @@
* 报纸 * 报纸
*/ */
if (window.location.href.contains(/(newspaper|joblist|freebies|newspaper_class|personals|bounties|comics)\.php/)) { if (window.location.href.contains(/(newspaper|joblist|freebies|newspaper_class|personals|bounties|comics)\.php/)) {
const newspaperOB = new MutationObserver(()=>{ const newspaperOB = new MutationObserver(() => {
newspaperOB.disconnect(); newspaperOB.disconnect();
newspaperTrans(); newspaperTrans();
newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true});
@ -2826,10 +2977,10 @@
if (spl.length > 7) return; // todo 多人运动暂时跳过 if (spl.length > 7) return; // todo 多人运动暂时跳过
const money = spl[spl.length - 2]; const money = spl[spl.length - 2];
if (spl[0] === 'Someone') { // 被匿名mug if (spl[0] === 'Someone') { // 被匿名mug
e.firstChild.nodeValue = '有人打劫 ' + money + ' ['; e.firstChild.nodeValue = '有人打劫你并抢走了 ' + money + ' [';
e.childNodes[1].firstChild.nodeValue = '查看'; e.childNodes[1].firstChild.nodeValue = '查看';
} else { } else {
e.childNodes[1].nodeValue = ' 打劫 ' + money + ' ['; e.childNodes[1].nodeValue = ' 打劫你并抢走了 ' + money + ' [';
e.childNodes[2].firstChild.nodeValue = '查看'; e.childNodes[2].firstChild.nodeValue = '查看';
} }
return; return;
@ -3341,14 +3492,20 @@
* 页标题按钮content-title-links * 页标题按钮content-title-links
*/ */
function contentTitleLinksTrans() { function contentTitleLinksTrans() {
// $('div.content-title-links a span:nth-child(2)').each((i, e) => { const $links = $('div.content-title span:nth-child(2)').length === 0
$('div.content-title span:nth-child(2)').each((i, e) => { ? $('div[class^="topSection"] span[class*="Title"]')
if (titleLinksDict[$(e).text()]) : $('div.content-title span:nth-child(2)');
$links.each((i, e) => {
if (titleLinksDict[$(e).text()]) {
$(e).text(titleLinksDict[$(e).text()]); $(e).text(titleLinksDict[$(e).text()]);
else if ($(e).attr('id') === 'events') } else if ($(e).attr('id') === 'events') {
if (titleLinksDict[$(e).text().split(' ')[0]]) if (titleLinksDict[$(e).text().split(' ')[0]])
$(e).text($(e).text() $(e).text($(e).text()
.replace($(e).text().split(' ')[0], titleLinksDict[$(e).text().split(' ')[0]])); .replace(
$(e).text().split(' ')[0],
titleLinksDict[$(e).text().split(' ')[0]]
));
}
}); });
} }
@ -3356,10 +3513,10 @@
* 页标题翻译 * 页标题翻译
*/ */
function titleTrans() { function titleTrans() {
const title = titleDict[$('h4#skip-to-content').text().trim()]; const $title = $('h4#skip-to-content').length === 0 ? $('h4[class^="title"]') : $('h4#skip-to-content');
//if ($('h4#skip-to-content').length === 1) const title = titleDict[$title.text().trim()];
if (title && $('h4#skip-to-content').css('display') !== 'none') if (title && $title.css('display') !== 'none')
$('h4#skip-to-content').css('display', 'none').after(`<span style='float:left'><h4>` + title + `</h4></span>`); $title.after($title.clone().text(title)).css('display', 'none');
} }
/** /**
@ -3384,10 +3541,10 @@ ${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10">
/** /**
* 发钱翻译 * 发钱翻译
*/ */
function sendCashTrans(domPath='') { function sendCashTrans(domPath = '') {
const sc = $(domPath+' .send-cash'); const sc = $(domPath + ' .send-cash');
if (sc.length === 0) return; if (sc.length === 0) return;
sc.find('*').contents().each((i,e)=>{ sc.find('*').contents().each((i, e) => {
if (e.nodeType === 1) { if (e.nodeType === 1) {
if (sendCashDict[$(e).attr('placeholder')]) { if (sendCashDict[$(e).attr('placeholder')]) {
$(e).attr('placeholder', sendCashDict[$(e).attr('placeholder')]); $(e).attr('placeholder', sendCashDict[$(e).attr('placeholder')]);