修改物品页面翻译逻辑
This commit is contained in:
parent
54437b3129
commit
70ce199f4f
@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Torn翻译
|
||||
// @namespace WOOH
|
||||
// @version 0.1.1130b
|
||||
// @version 0.1.1201a
|
||||
// @description Torn UI翻译
|
||||
// @author Woohoo-[2687093] sabrina_devil[2696209]
|
||||
// @match https://www.torn.com/*
|
||||
@ -2182,6 +2182,9 @@
|
||||
const itemDescDict = {
|
||||
'A lottery voucher which can be traded in for 100 lottery tickets for the weekly draw, courtesy of the Lucky Shot Casino.':
|
||||
'',
|
||||
"Increases one's energy.": '提高能量。',
|
||||
"Temporarily passively increases all statistics while attacking or defending by 25%.":
|
||||
'在攻击或防守时暂时地获得25%战斗属性增益。',
|
||||
};
|
||||
const itemEffectDict = {
|
||||
// 彩票
|
||||
@ -2221,6 +2224,7 @@
|
||||
'is a Book Item.': '是一本书。',
|
||||
'is a Special Item.': '是一种特殊物品。',
|
||||
};
|
||||
const itemReqDict = {};
|
||||
const tornSettingsDict = {
|
||||
'API Keys': 'API 密钥',
|
||||
'General settings': '通用设置',
|
||||
@ -3008,7 +3012,7 @@
|
||||
const [hours, minutes] = spl.length === 5
|
||||
? [parseInt(spl[0]), parseInt(spl[3])]
|
||||
: [0, parseInt(spl[0])];
|
||||
if (fullEnergyTime < (hours * 60 + minutes)*2) {
|
||||
if (fullEnergyTime < (hours * 60 + minutes) * 2) {
|
||||
if (!$(e).parent().hasClass('wh-translated')) {
|
||||
$(e).parent()
|
||||
.prepend(`<div style="color: red">警告:该次飞行往返时间大于体力回复时间,将会爆体!</div>`)
|
||||
@ -3280,14 +3284,15 @@
|
||||
* 物品页面
|
||||
*/
|
||||
if (window.location.href.contains(/item\.php/)) {
|
||||
// let count = 0;
|
||||
const $$ = $('.content-wrapper');
|
||||
const options = {
|
||||
characterData: false,
|
||||
characterData: true,
|
||||
attributes: false,
|
||||
subtree: true,
|
||||
childList: true,
|
||||
};
|
||||
// let isAllItemTrans = false;
|
||||
const translated = {cat: '', count: -1};
|
||||
const OB = new MutationObserver(() => {
|
||||
OB.disconnect();
|
||||
titleTrans();
|
||||
@ -3306,39 +3311,54 @@
|
||||
const $cat = $('div.title-black span.items-name');
|
||||
if (itemPageDict[$cat.text().trim()]) $cat.text(itemPageDict[$cat.text().trim()]);
|
||||
// 物品名翻译
|
||||
const $item_name = $('ul.current-cont').length === 0
|
||||
? $('ul#items-search-tab').children().length === 0
|
||||
? $('ul#all-items span.name')
|
||||
: $('ul#items-search-tab span.name')
|
||||
: $('ul.current-cont span.name');
|
||||
$item_name.each((i, e) => {
|
||||
const $active_item_list = $('ul.itemsList[aria-expanded="true"] span.name');
|
||||
const $active_tab = $('ul.itemsList[aria-expanded="true"]');
|
||||
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()]) {
|
||||
$(e).addClass('wh-translated')
|
||||
.after(`<span class="wh-translate" style="margin: 0 0 0 1em">${itemNameDict[$(e).text().trim()]}</span>`);
|
||||
}
|
||||
}
|
||||
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');
|
||||
$item_info.contents().each((i, e) => {
|
||||
// 物品描述
|
||||
if (e.nodeType !== 3) return;
|
||||
if (itemDescDict[e.nodeValue.trim()]) e.nodeValue = itemDescDict[e.nodeValue.trim()];
|
||||
});
|
||||
$item_info.find('*').contents().each((i, e) => {
|
||||
// the+物品名 物品种类 效果
|
||||
if (e.nodeType !== 3) return;
|
||||
if (e.nodeValue.trim() === '') return;
|
||||
if (i === 3) {
|
||||
if (itemNameDict[e.nodeValue.trim().slice(4)]) {
|
||||
e.nodeValue = itemNameDict[e.nodeValue.trim().slice(4)];
|
||||
$item_info.each((i, e) => {
|
||||
// torntools 插件
|
||||
const isTTModified = $(e).hasClass('tt-modified');
|
||||
if (isTTModified) {
|
||||
}
|
||||
return;
|
||||
const itemName = e.children[0].children[0]; //<span class="bold">大麻1</span>
|
||||
const itemType = e.children[0].childNodes[2]; //itemType.nodeValue
|
||||
const itemDesc = e.childNodes[2]; //itemDesc.nodeValue
|
||||
const itemEffect = $(e).children('div.t-green.item-effect').get(0) || null;
|
||||
const itemReq = $(e).children('div.t-red.item-effect').get(0) || null;
|
||||
if (itemNameDict[itemName.innerText.trim().slice(4)]) {
|
||||
itemName.innerText = itemNameDict[itemName.innerText.trim().slice(4)];
|
||||
}
|
||||
if (itemTypeDict[itemType.nodeValue.trim()]) {
|
||||
itemType.nodeValue = itemTypeDict[itemType.nodeValue.trim()];
|
||||
}
|
||||
if (itemDescDict[itemDesc.nodeValue.trim()]) {
|
||||
itemDesc.nodeValue = itemDescDict[itemDesc.nodeValue.trim()];
|
||||
}
|
||||
if (itemEffect && itemEffectDict[itemEffect.innerText.trim()]) {
|
||||
itemEffect.innerText = itemEffectDict[itemEffect.innerText.trim()];
|
||||
}
|
||||
if (itemReq && itemReqDict[itemReq.innerText.trim()]) {
|
||||
itemReq.innerText = itemReqDict[itemReq.innerText.trim()];
|
||||
}
|
||||
//console.log(e.nodeValue.trim())
|
||||
if (itemTypeDict[e.nodeValue.trim()]) e.nodeValue = itemTypeDict[e.nodeValue.trim()];
|
||||
else if (itemEffectDict[e.nodeValue.trim()]) e.nodeValue = itemEffectDict[e.nodeValue.trim()];
|
||||
});
|
||||
};
|
||||
trans();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user