优化物品页面
This commit is contained in:
parent
582b044b16
commit
56bcda1938
96
index.html
Normal file
96
index.html
Normal file
@ -0,0 +1,96 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=0"/>
|
||||
<script type="text/javascript">
|
||||
window.onload = () => {
|
||||
const giteeRaw = 'https://gitee.com/wanyi007/torncity-zhcn-translate/raw/dev/torn-trans-zhcn.user.js';
|
||||
const jsdelivr = 'https://cdn.jsdelivr.net/gh/JJins/torncity-zhcn-translate/torn-trans-zhcn.user.js';
|
||||
const $textarea = document.querySelector('textarea');
|
||||
const $text = document.getElementById('text');
|
||||
const $btn = document.querySelector('button');
|
||||
const $refresh = document.getElementById('refresh');
|
||||
|
||||
fetch(jsdelivr, {
|
||||
cache: 'no-cache'
|
||||
}).catch(e => console.error(e)).then(data => data.text()).then(text => {
|
||||
$textarea.value = text;
|
||||
const iStart = 37;
|
||||
const dtimeStr = text.slice(iStart, iStart + 12);
|
||||
const last = {
|
||||
year: dtimeStr.slice(0, 4),
|
||||
month: dtimeStr.slice(4, 6),
|
||||
day: dtimeStr.slice(6, 8),
|
||||
h: dtimeStr.slice(8, 10),
|
||||
m: dtimeStr.slice(10)
|
||||
};
|
||||
$text.innerText = `加载完成,更新时间${last.year}年${last.month}月${last.day}日${last.h}:${last.m}`;
|
||||
$btn.removeAttribute("disabled");
|
||||
});
|
||||
|
||||
$btn.onclick = () => {
|
||||
$textarea.select();
|
||||
document.execCommand('Copy');
|
||||
$text.innerText = "已复制,可粘贴";
|
||||
$textarea.blur();
|
||||
};
|
||||
|
||||
$refresh.onclick = () => {
|
||||
location.reload();
|
||||
};
|
||||
|
||||
};
|
||||
</script>
|
||||
<style>html, body, p {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
padding: 2em 0;
|
||||
}
|
||||
|
||||
textarea {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
opacity: 0;
|
||||
z-index: -10;
|
||||
}
|
||||
|
||||
button {
|
||||
-webkit-appearance: none;
|
||||
display: block;
|
||||
border-radius: 0;
|
||||
border: 0;
|
||||
width: 100%;
|
||||
padding: 2em 0;
|
||||
margin: 0;
|
||||
background-color: #32CD32;
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button[disabled] {
|
||||
background-color: grey;
|
||||
}
|
||||
|
||||
a {
|
||||
display: block;
|
||||
padding: 1.5em 0;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<title>翻译助手快捷复制</title>
|
||||
</head>
|
||||
<body>
|
||||
<p id="text">请稍后,正在加载...</p>
|
||||
<textarea></textarea>
|
||||
<button disabled="">点击复制</button>
|
||||
<a>备用链接</a>
|
||||
<a id="refresh">刷新页面</a>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,8 +1,8 @@
|
||||
// ==UserScript==
|
||||
// @lastmodified 202112052222
|
||||
// @lastmodified 202112081730
|
||||
// @name Torn翻译
|
||||
// @namespace WOOH
|
||||
// @version 0.1.1205c
|
||||
// @version 0.1.1208a
|
||||
// @description Torn UI翻译
|
||||
// @author Woohoo-[2687093] sabrina_devil[2696209]
|
||||
// @match https://www.torn.com/*
|
||||
@ -1394,6 +1394,16 @@
|
||||
'Ammo:': '弹药:',
|
||||
'Bonus:': '额外:',
|
||||
'Masked:': '面具:',
|
||||
'Coverage:': '覆盖率:',
|
||||
'Armor:': '护甲:',
|
||||
'Top Speed:': '最高速度:',
|
||||
'Dirt:': '泥路:',
|
||||
'Tarmac:': '柏油路:',
|
||||
'Acceleration:': '加速:',
|
||||
'Safety:': '安全:',
|
||||
'Braking:': '制动:',
|
||||
'Handling:': '操控:',
|
||||
'Rate of Fire:': '开火率:',
|
||||
};
|
||||
const itemNameDict = {
|
||||
"Ammunition Pack": '弹药包',
|
||||
@ -1738,12 +1748,12 @@
|
||||
"Banana Orchid": '香蕉兰花',
|
||||
"Orchid": '兰花',
|
||||
"Edelweiss": '雪绒花',
|
||||
"Ceibo Flower": '鸡冠刺桐花',
|
||||
"Heather": '石南花',
|
||||
"Ceibo Flower": '木棉花',
|
||||
"Heather": '帚石楠',
|
||||
"African Violet": '非洲紫罗兰',
|
||||
"Cherry Blossom": '樱花',
|
||||
"Peony": '牡丹',
|
||||
"Tribulus Omanense": '蒺藜',
|
||||
"Peony": '牡丹花',
|
||||
"Tribulus Omanense": '蒺藜花',
|
||||
// 补给箱
|
||||
"Box of Medical Supplies": '医疗补给包',
|
||||
"Lottery Voucher": '彩票券',
|
||||
@ -2265,6 +2275,8 @@
|
||||
'效果:对手脑部震荡,闪避下降到1/5,持续15-20秒。',
|
||||
};
|
||||
const itemTypeDict = {
|
||||
'is a Defensive Armor.': '是一种防御性盔甲。',
|
||||
'are a Defensive Armor.': '是一种防御性盔甲。',
|
||||
'is a Machine Gun Weapon.': '是一种机枪。',
|
||||
'is a SMG Weapon.': '是一种冲锋枪。',
|
||||
'is a Shotgun Weapon.': '是一种霰弹枪。',
|
||||
@ -3374,6 +3386,21 @@
|
||||
* 物品页面
|
||||
*/
|
||||
if (window.location.href.contains(/item\.php/)) {
|
||||
// 标题和右边的链接
|
||||
initOB(document.querySelector('.content-title'), {childList: true},
|
||||
() => {
|
||||
titleTrans();
|
||||
contentTitleLinksTrans();
|
||||
});
|
||||
// 套装预览中间的文字
|
||||
const $loadouts_root = document.getElementById('loadoutsRoot');
|
||||
if ($loadouts_root) {
|
||||
initOB($loadouts_root, {subtree: true, attributes: true}, () => {
|
||||
$loadouts_root.querySelectorAll('div[class^="itemReview___"] div[class^="type___"]').forEach((e) => {
|
||||
if (itemPageDict[e.innerText.trim()]) e.innerText = itemPageDict[e.innerText.trim()];
|
||||
});
|
||||
});
|
||||
}
|
||||
// 手机选项按钮 物品名 物品详情
|
||||
const options = {
|
||||
attributes: true,
|
||||
@ -3396,18 +3423,24 @@
|
||||
translatedOnce.item_opt = count !== -1 ? count : -1;
|
||||
}
|
||||
// 物品名
|
||||
const expanded_dom = `ul.itemsList[aria-expanded="true"]`;
|
||||
const $active_tab = $(`${expanded_dom}`);
|
||||
const $active_item_list = $active_tab.find(`span.name`);
|
||||
const itemCat = $active_tab.attr('id');
|
||||
// const expanded_dom = `ul.itemsList[aria-expanded="true"]`;
|
||||
// const $active_tab = $(`${expanded_dom}`);
|
||||
const $active_tab = document.querySelector('ul.itemsList[aria-expanded="true"]');
|
||||
const $active_item_list = $active_tab.querySelectorAll('span.name');
|
||||
const itemCat = $active_tab.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>`);
|
||||
$active_item_list.forEach((e, i) => {
|
||||
if (!e.classList.contains('wh-translated')) {
|
||||
if (itemNameDict[e.innerText.trim()]) {
|
||||
e.classList.add('wh-translated');
|
||||
const trans_dom = document.createElement('span');
|
||||
trans_dom.classList.add('wh-translate');
|
||||
trans_dom.setAttribute('style', 'margin: 0 0 0 1em');
|
||||
trans_dom.append(itemNameDict[e.innerText.trim()]);
|
||||
e.after(trans_dom);
|
||||
// .after(`<span class="wh-translate" style="margin: 0 0 0 1em">${itemNameDict[$(e).text().trim()]}</span>`);
|
||||
}
|
||||
}
|
||||
count = i;
|
||||
@ -3419,37 +3452,54 @@
|
||||
}
|
||||
}
|
||||
// 物品详情
|
||||
const $item_info = $active_tab.find(`li.show-item-info span.info-msg`);
|
||||
$item_info.each((i, e) => {
|
||||
const $show_item_info = $active_tab.querySelector('li.show-item-info');
|
||||
if ($show_item_info){
|
||||
const $item_info = $show_item_info.querySelector('span.info-msg');
|
||||
if ($item_info) {
|
||||
// torntools 插件
|
||||
const isTTModified = e.classList.contains('tt-modified');
|
||||
const isTTModified = $item_info.classList.contains('tt-modified');
|
||||
if (isTTModified) {
|
||||
}
|
||||
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)];
|
||||
// 物品名
|
||||
const itemName = $item_info.children[0].children[0]; //<span class="bold">大麻1</span>
|
||||
// 去除the
|
||||
const the_removed = itemName.innerText.trim().slice(4);
|
||||
if (itemNameDict[the_removed]) {
|
||||
itemName.innerText = `${itemNameDict[the_removed]}(${the_removed})`;
|
||||
}
|
||||
// 类型文字
|
||||
const itemType = $item_info.children[0].childNodes[2]; //itemType.nodeValue
|
||||
if (itemTypeDict[itemType.nodeValue.trim()]) {
|
||||
itemType.nodeValue = itemTypeDict[itemType.nodeValue.trim()];
|
||||
}
|
||||
// 描述
|
||||
const itemDesc = $item_info.childNodes[2]; //itemDesc.nodeValue
|
||||
if (itemDescDict[itemDesc.nodeValue.trim()]) {
|
||||
itemDesc.nodeValue = itemDescDict[itemDesc.nodeValue.trim()];
|
||||
}
|
||||
// 效果
|
||||
const itemEffect = $item_info.querySelector('div.t-green.item-effect');
|
||||
if (itemEffect && itemEffectDict[itemEffect.innerText.trim()]) {
|
||||
itemEffect.innerText = itemEffectDict[itemEffect.innerText.trim()];
|
||||
}
|
||||
// 使用需求
|
||||
const itemReq = $item_info.querySelector('div.t-red.item-effect');
|
||||
if (itemReq && itemReqDict[itemReq.innerText.trim()]) {
|
||||
itemReq.innerText = itemReqDict[itemReq.innerText.trim()];
|
||||
}
|
||||
}
|
||||
// 下方的表格
|
||||
const $info_table_title = $show_item_info.querySelectorAll('div.title');
|
||||
if ($info_table_title) $info_table_title.forEach((e) => {
|
||||
if (itemPageDict[e.innerText.trim()]) {
|
||||
e.innerText = itemPageDict[e.innerText.trim()];
|
||||
}
|
||||
});
|
||||
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 $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) {
|
||||
@ -3465,19 +3515,8 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
// 标题和右边的链接
|
||||
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 $title_black = document.querySelector('div.title-black');
|
||||
const $your_items = $('div.title-black span.m-hide');
|
||||
if (itemPageDict[$your_items.text().trim()]) $your_items.text(itemPageDict[$your_items.text().trim()]);
|
||||
// 黑框分类标题
|
||||
@ -4604,8 +4643,6 @@
|
||||
const $item_type = $item_name.nextSibling;
|
||||
// 绿字 物品效果
|
||||
const $item_effect = $show_item_info.querySelector('div.item-effect');
|
||||
// 下方的表格
|
||||
const $info_table_title = $show_item_info.querySelectorAll('div.title');
|
||||
if (itemNameDict[the_removed]) {
|
||||
$item_name.innerText = `${itemNameDict[the_removed]}(${the_removed})`;
|
||||
}
|
||||
@ -4615,6 +4652,8 @@
|
||||
if ($item_effect && itemEffectDict[$item_effect.innerText.trim()]) {
|
||||
$item_effect.innerText = itemEffectDict[$item_effect.innerText.trim()];
|
||||
}
|
||||
// 下方的表格
|
||||
const $info_table_title = $show_item_info.querySelectorAll('div.title');
|
||||
$info_table_title.forEach((e) => {
|
||||
if (itemPageDict[e.innerText.trim()]) {
|
||||
e.innerText = itemPageDict[e.innerText.trim()];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user