修改物品页面翻译逻辑

This commit is contained in:
woohoo 2021-12-02 20:39:25 +08:00
parent 70ce199f4f
commit 3082449508

View File

@ -1,7 +1,8 @@
// ==UserScript==
// @lastmodified 202112022039
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1201a
// @version 0.1.1202a
// @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/*
@ -405,7 +406,7 @@
"Sweet Shop": "糖果店",
"Msg Inc": "广告公司",
"Donator House": "捐赠者中心",
"Big Al's Gun Shop": "Big Al的枪店",
"Big Al's Gun Shop": "大艾尔枪械",
"Cyber Force": "赛博军团",
"Church": "教堂",
"Education": "教育",
@ -419,7 +420,7 @@
"Pawn Shop": "PT 当铺",
"Post Office": "邮局",
"Super Store": "电器商店",
"TC Clothing": "TC服装店",
"TC Clothing": "TC 服装店",
"Token Shop": "Token 商店",
"Casino": "赌场",
"Dump": "垃圾场",
@ -445,7 +446,8 @@
'REAL ESTATE': '房地产',
'Real Estate': '房地产',
'SHOPPING': '购物',
'Nikeh Sports': '',
'Shopping': '购物',
'Nikeh Sports': '耐克哈运动专卖',
"Bits 'n' Bobs": '胖鲍勃的杂货店',
// '':'',
};
@ -928,7 +930,7 @@
'Education Length': '教育时长',
'Awareness': '感知能力',
'Bank Interest': '银行利润',
'Masterful Looting': '大师掠夺',
'Masterful Looting': '掠夺大师',
'Stealth': '隐身',
'Hospitalizing': '送医时长',
'Addiction Mitigation': '毒瘾缓解',
@ -937,17 +939,17 @@
'Protection': '保护',
'Sharpness': '敏锐',
'Evasion': '回避',
'Heavy Artillery Mastery': '重炮精通 (Heavy Artillery)',
'Machine Gun Mastery': '机枪精通 (Machine Gun)',
'Heavy Artillery Mastery': '重炮精通',
'Machine Gun Mastery': '机枪精通',
'Rifle Mastery': '步枪精通',
'SMG Mastery': '冲锋枪精通',
'Shotgun Mastery': '霰弹枪精通',
'Pistol Mastery': '手枪精通',
'Club Mastery': '冲击武器精通 (Clubbing)',
'Piercing Mastery': '穿刺武器精通',
'Slashing Mastery': '切割武器精通',
'Club Mastery': '冲击武器精通(Clubbing)',
'Piercing Mastery': '穿刺武器精通(Piercing)',
'Slashing Mastery': '切割武器精通(Slashing)',
'Mechanical Mastery': '机械武器精通',
'Temporary Mastery': '临时武器精通',
'Temporary Mastery': '投掷物精通',
'Increases maximum nerve bar by 1 point': '增加 1 点犯罪N上限',
'Increases critical hit rate by 0.5%': '提高 0.5% 暴击率',
'Increases maximum life by 5%': '提高 5% 血量上限',
@ -974,7 +976,7 @@
'Increases proficiency with piercing weapons': '提高穿刺武器精通',
'Increases proficiency with slashing weapons': '提高切割武器精通',
'Increases proficiency with mechanical devices': '提高切割武器精通',
'Increases proficiency with temporary weapons': '提高临时武器精通',
'Increases proficiency with temporary weapons': '提高投掷物精通',
'Increases damage and accuracy of heavy artillery weapons': '提高重炮伤害与命中',
'Increases damage and accuracy of machine gun weapons': '提高机枪伤害与命中',
'Increases damage and accuracy of rifle weapons': '提高步枪伤害与命中',
@ -1322,33 +1324,65 @@
'low:': '最低:',
};
const itemPageDict = {
'Primary': '',
'Secondary': '',
'Melee': '',
'Temporary': '',
'Defensive': '',
'Clothing': '',
'Jewelry': '',
'Your items -': '',
'All': '',
'Medical': '',
'Drugs': '',
'Energy Drink': '',
'Alcohol': '',
'Candy': '',
'Boosters': '',
'Primary': '主手',
'Secondary': '副手',
'Melee': '近战',
'Temporary': '投掷',
'Defensive': '防御',
'Armor': '防御',
'Clothing': '衣物',
'Jewelry': '珠宝',
'Your items -': '你的物品 - ',
'All': '全部',
'Medical': '医疗',
'Drugs': '药物',
'Energy Drink': '能量饮料',
'Alcohol': '酒类',
'Candy': '糖果',
'Boosters': '增益道具',
'Enhancer': '增幅器',
'Supply Packs': '',
'Electronics': '',
'Flowers': '',
'Plushies': '',
'Cars': '',
'Viruses': '',
'Miscellaneous': '',
'Artifacts': '',
'Books': '',
'Special': '',
'Collectibles': '',
'Supply Packs': '补给包',
'Electronics': '电器',
'Flowers': '花',
'Plushies': '玩偶',
'Cars': '车辆',
'Viruses': '病毒',
'Miscellaneous': '杂项',
'Artifacts': '文物',
'Books': '书',
'Special': '特殊',
'Collectibles': '可收集物',
'Donate': '捐献',
'Drink': '喝下',
'Eat': '吃下',
'Enlist': '车辆注册',
'Equip': '装备',
'Listen': '',
'Open': '打开',
'Propose': '求婚',
'Return': '退还',
'Sell': '卖出',
'Send': '发送',
'Take': '使用',
'Trash': '丢弃',
'Turn on': '开启',
'Unequip': '脱下',
'Use': '使用',
'Donate this Item': '捐献该物品',
'Equip this Item': '装备该物品',
'Sell this Item': '卖出该物品',
'Send this Item': '发送该物品',
'Trash this Item': '丢弃该物品',
'Unequip this Item': '脱下该物品',
'Return to Faction': '退还帮派',
'Buy:': '买价:',
'Sell:': '卖价:',
'Value:': '价值:',
'Accuracy:': '命中:',
'Damage:': '伤害:',
'Circ:': '流通:',
'Quality:': '品质:',
'Stealth:': '隐匿:',
};
const itemNameDict = {
"Ammunition Pack": '弹药包',
@ -2197,9 +2231,39 @@
'Effect: Increases happiness by 75 and booster cooldown by 30 minutes.': '',
// 能饮
'Effect: Increases energy by 10 and booster cooldown by 2 hours.': '',
// 手雷
"Effect: Opponent becomes Maced, decreasing Dexterity to 1/5th for 15-20 seconds.":
'效果对手被梅斯毒气影响闪避降低至1/5持续15-20s。',
"Effect: Opponent becomes Blinded, decreasing Speed to 1/5th for 15-20 seconds.":
'效果对手被致盲速度降低至1/5持续15-20s。',
"Effect: Opponent becomes Gassed, decreasing Dexterity to 1/3rd for 120-180 seconds.":
'效果对手变得疲惫闪避降低至1/3持续120-180s。',
"Effect: Opponent receives Severe Burning damage over 3 turns.":
'效果对手在3个回合内受到严重的燃烧伤害。',
"Effect: Opponent becomes Smoked, decreasing Speed to 1/3rd for 120-180 seconds.":
'效果对手被烟雾影响速度降低至1/3持续120-180s。',
"Effect: User becomes Hastened, increasing Speed by 500% for 120 seconds.":
'效果使用者急促起来速度提高500%持续120s。',
"Effect: User becomes Sharpened, increasing Dexterity by 500% for 120 seconds.":
'效果使用者变得更加敏锐闪避增加500%持续120s。',
"Effect: User becomes Strengthened, increasing Strength by 500% for 120 seconds.":
'效果使用者变得更强壮力量增加500%持续120秒。',
"Effect: User becomes Hardened, increasing Defense by 300% for 120 seconds and replenishing life by 25%.":
'效果使用者变得坚硬在120秒内增加300%的防御并补充25%的生命。',
"Effect: Opponent becomes Concussed, decreasing Dexterity to 1/5th for 15-20 seconds.":
'效果对手脑部震荡闪避下降到1/5持续15-20秒。',
};
const itemTypeDict = {
'is a Machine Gun Weapon.': '',
'is a Machine Gun Weapon.': '是一种机枪。',
'is a SMG Weapon.': '是一种冲锋枪。',
'is a Shotgun Weapon.': '是一种霰弹枪。',
'is a Rifle Weapon.': '是一种步枪。',
'is a Heavy Artillery Weapon.': '是一种重炮。',
'is a Pistol Weapon.': '是一种手枪。',
'is a Piercing Weapon.': '是一种穿刺武器(piercing)。',
'is a Clubbing Weapon.': '是一种冲击武器(Clubbing)。',
'is a Slashing Weapon.': '是一种切割武器(slashing)。',
'is a Mechanical Weapon.': '是一种机械武器。',
'is a Temporary Weapon.': '是一种投掷武器。',
'is a Clothing Item.': '是一种服装物品。',
'is a Medical Item.': '是一种医疗物品。',
@ -2870,7 +2934,7 @@
/**
* 搜索玩家的4个分类按钮
*/
function playerSearchBoxTrans() {
const playerSearchBoxTrans = function playerSearchBoxTrans() {
const psbtOB = new MutationObserver(_ => {
if ($('div.ac-wrapper').length === 0) return;
psbtOB.disconnect();
@ -2882,7 +2946,6 @@
});
psbtOB.observe(document, {childList: false, subtree: true, attributes: true});
}
playerSearchBoxTrans();
/**
@ -3089,8 +3152,10 @@
$(e).text('你的' + propertyDict[$(e).text().trim().slice(5)]);
}
} else if ($(e).prev().attr('class') === 'cql-gym') {
if (gymList[$(e).text()]) {
if (gymList[$(e).text().trim()]) {
$(e).text(gymList[$(e).text()]);
} else if (gymList[$(e).text().trim().split(' ').slice(0, 2).join(' ')]) {
$(e).text(gymList[$(e).text().trim().split(' ').slice(0, 2).join(' ')]);
}
}
});
@ -3249,7 +3314,7 @@
});
});
const trans = () => {
if ($('.wh-translate').length === 0) {
if ($('.wh-translate').length === 0 && $('div#tab-menu.captcha').length === 0) {
$('div.content-title').before(
`<div class="wh-translate title-black" style="border-radius: 5px"><span>快捷操作:</span>
<form id="wh-translate-quick" action="crimes.php?step=docrime4" method="post" style="display: inline-block;margin: 0 5px">
@ -3284,38 +3349,35 @@
* 物品页面
*/
if (window.location.href.contains(/item\.php/)) {
const $$ = $('.content-wrapper');
// 手机选项按钮 物品名 物品详情
const options = {
characterData: true,
attributes: false,
attributes: true,
subtree: true,
childList: true,
attributeFilter: ["aria-hidden",]
};
// let isAllItemTrans = false;
const translated = {cat: '', count: -1};
const OB = new MutationObserver(() => {
OB.disconnect();
titleTrans();
contentTitleLinksTrans();
trans();
OB.observe($$.get(0), options);
const translatedOnce = {item_opt: -1, opt_icon_count: -1};
initOB($(`div#category-wrap`).get(0), options, () => {
// 手机操作选项
const $item_opt = $(`ul.itemsList span.opt-name`);
if (translatedOnce.item_opt !== $item_opt.length - 1) {
let count = -1;
$item_opt.each((i, e) => {
if (itemPageDict[e.firstChild.nodeValue.trim()]) {
e.firstChild.nodeValue = itemPageDict[e.firstChild.nodeValue.trim()];
}
count = i;
});
const trans = () => {
// 套装预览中间的文字
$('div[class^="itemReview___"] div[class^="type___"]').each((i, e) => {
if (itemPageDict[e.innerText.trim()]) e.innerText = itemPageDict[e.innerText.trim()];
});
// 黑框 分类标题
const $your_items = $('div.title-black span.m-hide');
if (itemPageDict[$your_items.text().trim()]) $your_items.text(itemPageDict[$your_items.text().trim()]);
const $cat = $('div.title-black span.items-name');
if (itemPageDict[$cat.text().trim()]) $cat.text(itemPageDict[$cat.text().trim()]);
// 物品名翻译
const $active_item_list = $('ul.itemsList[aria-expanded="true"] span.name');
const $active_tab = $('ul.itemsList[aria-expanded="true"]');
translatedOnce.item_opt = count !== -1 ? count : -1;
}
// 物品名
const expanded_dom = `ul.itemsList[aria-expanded="true"]`;
const $active_item_list = $(`${expanded_dom} span.name`);
const $active_tab = $(`${expanded_dom}`);
const itemCat = $active_tab.attr('id');
if ($active_item_list.length - 1 !== translated.count || itemCat !== translated.cat) {
let count = -1;
// 物品名
$active_item_list.each((i, e) => {
if (!$(e).hasClass('wh-translated')) {
if (itemNameDict[$(e).text().trim()]) {
@ -3325,15 +3387,14 @@
}
count = i;
});
if (count !== -1) {
translated.cat = itemCat;
translated.count = count;
}
} else {
//console.log('已翻译过了')
}
// 物品详情
const $item_info = $('li.show-item-info div.item-cont span.info-msg');
const $item_info = $(`${expanded_dom} li.show-item-info span.info-msg`);
$item_info.each((i, e) => {
// torntools 插件
const isTTModified = $(e).hasClass('tt-modified');
@ -3360,9 +3421,52 @@
itemReq.innerText = itemReqDict[itemReq.innerText.trim()];
}
});
};
trans();
OB.observe($$.get(0), options);
const $item_info_key = $(' li.item-info-active').next().find('li div:first-child');
$item_info_key.each((i, e) => {
if (itemPageDict[e.innerText.trim()]) e.innerText = itemPageDict[e.innerText.trim()];
});
// 物品右操作按钮
const $opt_icon_tooltip = $('ul.actions-wrap span.icon-h');
if (translatedOnce.opt_icon_count !== $opt_icon_tooltip.length - 1) {
let count = -1
$opt_icon_tooltip.each((i, e) => {
if (itemPageDict[e.attributes.title.nodeValue]) {
e.attributes.title.nodeValue = itemPageDict[e.attributes.title.nodeValue];
}
count = i;
});
if (count !== -1) {
translatedOnce.opt_icon_count = count;
}
}
});
// 标题和右边的链接
initOB($('.content-title').get(0), {childList: true},
() => {
titleTrans();
contentTitleLinksTrans();
});
// 套装预览中间的文字
initOB(document.querySelector('#loadoutsRoot'), {subtree: true, attributes: true}, () => {
$('div[class^="itemReview___"] div[class^="type___"]').each((i, e) => {
if (itemPageDict[e.innerText.trim()]) e.innerText = itemPageDict[e.innerText.trim()];
});
})
// 黑框
const $your_items = $('div.title-black span.m-hide');
if (itemPageDict[$your_items.text().trim()]) $your_items.text(itemPageDict[$your_items.text().trim()]);
// 黑框分类标题
initOB($('div.title-black span.items-name').get(0), {childList: true}, () => {
const $cat = $('div.title-black span.items-name');
if (itemPageDict[$cat.text().trim()]) $cat.text(itemPageDict[$cat.text().trim()]);
})
// 分类浮动文字
const $data_type = $('li#categoriesItem a');
$data_type.each((i, e) => {
if (itemPageDict[$(e).attr('title')]) {
$(e).attr('title', itemPageDict[$(e).attr('title')]);
}
});
return;
}
@ -3383,10 +3487,11 @@
childList: true
});
});
const taskList = [];
let isCapTaskList = false;
// const taskList = [];
const taskList = {};
// let isCapTaskList = false;
const trans = () => {
if (!isCapTaskList) {
// if (!isCapTaskList) {
$('ul#giver-tabs a.ui-tabs-anchor').each((i, e) => {
if ($(e).children().hasClass('mission-complete-icon')) {
taskList[i] = e.innerText.trim();
@ -3394,8 +3499,8 @@
taskList[i] = $(e).clone().children().remove().end().text().trim();
}
});
isCapTaskList = true;
}
// isCapTaskList = true;
// }
// 助手注入
$('div.max-height-fix.info').each((i, e) => {
if ($(e).find('.wh-translated').length !== 0) return;
@ -5578,4 +5683,28 @@ ${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10">
return itemNameDict[str] || str;
}
/*
ob
*/
function initOB(dom = document, opt = {}, func = () => {
}, record = false) {
if (record) {
const mo = new MutationObserver((mutation) => {
console.log(mutation)
mo.disconnect();
func();
mo.observe(dom, opt)
});
func();
mo.observe(dom, opt);
} else {
const mo = new MutationObserver(() => {
mo.disconnect();
func();
mo.observe(dom, opt)
});
func();
mo.observe(dom, opt);
}
}
}());