添加展柜、更新crime快速操作

This commit is contained in:
woohoo 2021-12-07 18:15:29 +08:00
parent 70ca63d8b2
commit 582b044b16
2 changed files with 121 additions and 44 deletions

View File

@ -46,6 +46,7 @@
'Spouse\'s Properties': '配偶的房产', 'Spouse\'s Properties': '配偶的房产',
'Items': '物品仓库', 'Items': '物品仓库',
'Travel Agency': '旅行社', 'Travel Agency': '旅行社',
'Display Cabinet': '展示柜',
}; };
const titleLinksDict = { const titleLinksDict = {
'Personal stats': '个人统计信息', 'Personal stats': '个人统计信息',
@ -1181,6 +1182,12 @@
'Real name': '真实姓名', 'Real name': '真实姓名',
'Country': '国家', 'Country': '国家',
'City': '城市', 'City': '城市',
'Grocer': '杂货',
'Education': '教育',
'Casino': '赌场',
'Medical': '医疗',
'Army': '军队',
'Law': '法律',
'There is no active competition': '现在没有活动', 'There is no active competition': '现在没有活动',
"doesn't wish to share": '不希望公开', "doesn't wish to share": '不希望公开',
}; };
@ -1386,6 +1393,7 @@
'Caliber:': '口径:', 'Caliber:': '口径:',
'Ammo:': '弹药:', 'Ammo:': '弹药:',
'Bonus:': '额外:', 'Bonus:': '额外:',
'Masked:': '面具:',
}; };
const itemNameDict = { const itemNameDict = {
"Ammunition Pack": '弹药包', "Ammunition Pack": '弹药包',
@ -3313,13 +3321,13 @@
* crime * crime
*/ */
if (window.location.href.contains(/crimes\.php/)) { if (window.location.href.contains(/crimes\.php/)) {
const $$ = $('.content-wrapper'); const $$ = document.querySelector('.content-wrapper');
const OB = new MutationObserver(() => { const OB = new MutationObserver(() => {
OB.disconnect(); OB.disconnect();
titleTrans(); titleTrans();
contentTitleLinksTrans(); contentTitleLinksTrans();
trans(); trans();
OB.observe($$.get(0), { OB.observe($$, {
characterData: true, characterData: true,
attributes: true, attributes: true,
subtree: true, subtree: true,
@ -3327,28 +3335,33 @@
}); });
}); });
const trans = () => { const trans = () => {
if ($('.wh-translate').length === 0 && $('div#tab-menu.captcha').length === 0) { const dom = `<div class="wh-translate"><div class="title-black" style="border-radius: 5px 5px 0 0;"><span>快捷操作:</span></div><div class="cont-gray" style="padding: 6px 0;border-radius: 0 0 5px 5px;">
$('div.content-title').before(
`<div class="wh-translate"><div class="title-black" style="border-radius: 5px 5px 0 0;"><span>快捷操作:</span></div><div class="cont-gray" style="padding: 6px 0;border-radius: 0 0 5px 5px;">
<form id="wh-translate-quick" action="crimes.php?step=docrime4" method="post" style="display: inline-block;margin: 0 5px"> <form id="wh-translate-quick" action="crimes.php?step=docrime4" method="post" style="display: inline-block;margin: 0 5px">
<input name="nervetake" type="hidden" value="18"> <input name="nervetake" type="hidden" value="18">
<input name="crime" type="hidden" value="hackbank"> <input name="crime" type="hidden" value="hackbank">
<input style="-webkit-appearance:none;padding: 4px;background: #e91e63;border-radius: 5px;color: white;" type="submit" value="18-1" style="padding: 0 2px" /> <input style="-webkit-appearance:none;padding: 4px;background: #e91e63;border-radius: 5px;color: white;" type="submit" value="18-1" />
</form> </form>
<form id="wh-translate-quick" action="crimes.php?step=docrime4" method="post" style="display: inline-block;margin: 0 5px"> <form id="wh-translate-quick" action="crimes.php?step=docrime4" method="post" style="display: inline-block;margin: 0 5px">
<input name="nervetake" type="hidden" value="11"> <input name="nervetake" type="hidden" value="11">
<input name="crime" type="hidden" value="warehouse"> <input name="crime" type="hidden" value="warehouse">
<input style="-webkit-appearance:none;padding: 4px;background: #2196f3;border-radius: 5px;color: white;" type="submit" value="烧仓库" style="padding: 0 2px" /> <input style="-webkit-appearance:none;padding: 4px;background: #2196f3;border-radius: 5px;color: white;" type="submit" value="烧仓库" />
</form> </form>
<form id="wh-translate-quick" action="crimes.php?step=docrime4" method="post" style="display: inline-block;margin: 0 5px"> <form id="wh-translate-quick" action="crimes.php?step=docrime4" method="post" style="display: inline-block;margin: 0 5px">
<input name="nervetake" type="hidden" value="4"> <input name="nervetake" type="hidden" value="4">
<input name="crime" type="hidden" value="jacket"> <input name="crime" type="hidden" value="jacket">
<input style="-webkit-appearance:none;padding: 4px;background: #009688;border-radius: 5px;color: white;" type="submit" value="偷夹克" style="padding: 0 2px" /> <input style="-webkit-appearance:none;padding: 4px;background: #009688;border-radius: 5px;color: white;" type="submit" value="偷夹克" />
</form></div><hr class="page-head-delimiter m-top10 m-bottom10 r1854"></div>`); </form></div><hr class="page-head-delimiter m-top10 m-bottom10 r1854"></div>`
const is_wh_translate = $$.querySelector('.wh-translate') !== null;
const is_captcha = $$.querySelector('div#tab-menu.captcha') !== null;
const $title = $('div.content-title');
const $info = $('.info-msg-cont');
if (!is_wh_translate && !is_captcha) {
if ($title.length > 0) $title.before(dom);
else if ($info.length > 0) $info.before(dom);
} }
}; };
trans(); trans();
OB.observe($$.get(0), { OB.observe($$, {
characterData: true, characterData: true,
attributes: true, attributes: true,
subtree: true, subtree: true,
@ -3369,12 +3382,12 @@
}; };
const translated = {cat: '', count: -1}; const translated = {cat: '', count: -1};
const translatedOnce = {item_opt: -1, opt_icon_count: -1}; const translatedOnce = {item_opt: -1, opt_icon_count: -1};
initOB($(`div#category-wrap`).get(0), options, () => { initOB(document.getElementById('category-wrap'), options, () => {
// 手机操作选项 // 手机操作选项
const $item_opt = $(`ul.itemsList span.opt-name`); const $item_opt = document.querySelectorAll(`ul.itemsList span.opt-name`);
if (translatedOnce.item_opt !== $item_opt.length - 1) { if (translatedOnce.item_opt !== $item_opt.length - 1) {
let count = -1; let count = -1;
$item_opt.each((i, e) => { $item_opt.forEach((e, i) => {
if (itemPageDict[e.firstChild.nodeValue.trim()]) { if (itemPageDict[e.firstChild.nodeValue.trim()]) {
e.firstChild.nodeValue = itemPageDict[e.firstChild.nodeValue.trim()]; e.firstChild.nodeValue = itemPageDict[e.firstChild.nodeValue.trim()];
} }
@ -3384,8 +3397,8 @@
} }
// 物品名 // 物品名
const expanded_dom = `ul.itemsList[aria-expanded="true"]`; const expanded_dom = `ul.itemsList[aria-expanded="true"]`;
const $active_item_list = $(`${expanded_dom} span.name`);
const $active_tab = $(`${expanded_dom}`); const $active_tab = $(`${expanded_dom}`);
const $active_item_list = $active_tab.find(`span.name`);
const itemCat = $active_tab.attr('id'); const itemCat = $active_tab.attr('id');
if ($active_item_list.length - 1 !== translated.count || itemCat !== translated.cat) { if ($active_item_list.length - 1 !== translated.count || itemCat !== translated.cat) {
let count = -1; let count = -1;
@ -3406,10 +3419,10 @@
} }
} }
// 物品详情 // 物品详情
const $item_info = $(`${expanded_dom} li.show-item-info span.info-msg`); const $item_info = $active_tab.find(`li.show-item-info span.info-msg`);
$item_info.each((i, e) => { $item_info.each((i, e) => {
// torntools 插件 // torntools 插件
const isTTModified = $(e).hasClass('tt-modified'); const isTTModified = e.classList.contains('tt-modified');
if (isTTModified) { if (isTTModified) {
} }
const itemName = e.children[0].children[0]; //<span class="bold">大麻1</span> const itemName = e.children[0].children[0]; //<span class="bold">大麻1</span>
@ -3752,12 +3765,13 @@
* profile 玩家资料页面 * profile 玩家资料页面
*/ */
if (window.location.href.contains(/profiles\.php\?XID=[0-9]+/)) { if (window.location.href.contains(/profiles\.php\?XID=[0-9]+/)) {
const $wrapper = document.querySelector('.content-wrapper');
const profileOB = new MutationObserver(() => { const profileOB = new MutationObserver(() => {
profileOB.disconnect(); profileOB.disconnect();
titleTrans(); titleTrans();
contentTitleLinksTrans(); contentTitleLinksTrans();
profileTrans(); profileTrans();
profileOB.observe($('.content-wrapper').get(0), { profileOB.observe($wrapper, {
characterData: true, characterData: true,
attributes: true, attributes: true,
subtree: true, subtree: true,
@ -3769,7 +3783,7 @@
? document.title.trim().split(/('s |s' )/)[0] ? document.title.trim().split(/('s |s' )/)[0]
: null; : null;
if (!playerName) { if (!playerName) {
console.error('错误:获取用户名失败。'); console.error('翻译助手错误:获取用户名失败。');
try { try {
profileOB.disconnect() profileOB.disconnect()
} catch { } catch {
@ -3961,7 +3975,7 @@
sendCashTrans('.content-wrapper'); sendCashTrans('.content-wrapper');
}; };
profileTrans(); profileTrans();
profileOB.observe($('.content-wrapper').get(0), { profileOB.observe($wrapper, {
characterData: true, characterData: true,
attributes: true, attributes: true,
subtree: true, subtree: true,
@ -4544,6 +4558,74 @@
return; return;
} }
/*
展柜
*/
if (window.location.href.contains(/displaycase\.php/)) {
const $page_wrapper = document.querySelector('#display-page-wrap');
initOB($page_wrapper, {
subtree: true,
attributes: true,
childList: true
},
() => {
// 标题和右边的链接
titleTrans();
// 右上角返回按钮
const $back_to_profile = $page_wrapper.querySelector('#back');
if ($back_to_profile) {
const spl = $back_to_profile.innerText.split(/('s |s' )/);
if (spl.length === 3 && spl[2] === 'Profile') {
$back_to_profile.innerText = `${spl[0]}的个人资料`;
}
}
const $display_cabinet = $page_wrapper.querySelector('.display-cabinet');
if ($display_cabinet) {
// 物品名
const $item_name = $display_cabinet.querySelectorAll('div.b-item-name span:nth-of-type(2)');
$item_name.forEach((e) => {
if (itemNameDict[e.innerText]) {
e.innerText = itemNameDict[e.innerText];
}
});
// 展开详细框
const $show_item_info = $display_cabinet.querySelector('.show-item-info');
if ($show_item_info) {
// tt插件
const is_tt_modified = !!$show_item_info.querySelector('.tt-modified');
if (is_tt_modified) {
console.warn(is_tt_modified)
}
// 物品名
const $item_name = $show_item_info.querySelector('span.bold');
// 去除物品名的the
const the_removed = $item_name.innerText.trim().slice(4);
// 物品的类别
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})`;
}
if (itemTypeDict[$item_type.nodeValue.trim()]) {
$item_type.nodeValue = itemTypeDict[$item_type.nodeValue.trim()];
}
if ($item_effect && itemEffectDict[$item_effect.innerText.trim()]) {
$item_effect.innerText = itemEffectDict[$item_effect.innerText.trim()];
}
$info_table_title.forEach((e) => {
if (itemPageDict[e.innerText.trim()]) {
e.innerText = itemPageDict[e.innerText.trim()];
}
});
}
}
});
return;
}
/** /**
* 升级页面 * 升级页面
*/ */
@ -5581,9 +5663,10 @@
* 页标题右侧按钮 * 页标题右侧按钮
*/ */
function contentTitleLinksTrans() { function contentTitleLinksTrans() {
const $links = $('div.content-title span:nth-child(2)').length === 0 const $links_default = $('div.content-title span:nth-child(2)');
const $links = $links_default.length === 0
? $('div[class^="topSection"] span[class*="Title"]') ? $('div[class^="topSection"] span[class*="Title"]')
: $('div.content-title span:nth-child(2)'); : $links_default;
$links.each((i, e) => { $links.each((i, e) => {
if (titleLinksDict[$(e).text()]) { if (titleLinksDict[$(e).text()]) {
$(e).text(titleLinksDict[$(e).text()]); $(e).text(titleLinksDict[$(e).text()]);
@ -5699,24 +5782,29 @@ ${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10">
ob ob
*/ */
function initOB(dom = document, opt = {}, func = () => { function initOB(dom = document, opt = {}, func = () => {
}, record = false) { }, dev = false, once = false) {
if (record) { //let count = -1;
if (dev) {
const mo = new MutationObserver((mutation) => { const mo = new MutationObserver((mutation) => {
//count++;
console.log(mutation) console.log(mutation)
mo.disconnect(); mo.disconnect();
func(); func();
mo.observe(dom, opt) if (!once) {
mo.observe(dom, opt)
}
}); });
func(); func();
mo.observe(dom, opt); mo.observe(dom, opt);
} else { } else {
//count++;
const mo = new MutationObserver(() => { const mo = new MutationObserver(() => {
mo.disconnect(); mo.disconnect();
func(); func();
mo.observe(dom, opt) if (!once) mo.observe(dom, opt)
}); });
func(); func();
mo.observe(dom, opt); mo.observe(dom, opt)
} }
} }
}()); }());

25
tpl.js
View File

@ -1,23 +1,12 @@
function template() { function template() {
if (window.location.href.contains(/[]/)) { if (window.location.href.contains(/[]/)) {
const $$ = $('.content-wrapper'); // 标题和右边的链接
const opt = { const $cont_title = document.querySelector('.content-title');
characterData: true, initOB($cont_title, {childList: true, subtree: true},
attributes: true, () => {
subtree: true, titleTrans();
childList: true contentTitleLinksTrans();
}; });
const OB = new MutationObserver(() => {
OB.disconnect();
titleTrans();
contentTitleLinksTrans();
trans();
OB.observe($$.get(0), opt);
});
const trans = () => {
};
trans();
OB.observe($$.get(0), opt);
return; return;
} }
} }