修复了小镇提示的部分bug

This commit is contained in:
woohoo 2021-12-24 15:45:21 +08:00
parent dcefc6b164
commit 57894c2a42

View File

@ -1,8 +1,8 @@
// ==UserScript==
// @lastmodified 202112232309
// @lastmodified 202112241544
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1223a
// @version 0.1.1224a
// @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/*
@ -23,6 +23,11 @@
todo: true,
cont: `baza npc商店 imarket及imarket搜索结果`,
},
{
ver: '0.1.1224a',
date: '20211224',
cont: `修复了小镇提示的部分bug`,
},
{
ver: '0.1.1223a',
date: '20211223',
@ -5473,19 +5478,24 @@ margin: 0 0 3px;
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
const lootTypeDict = {'chests': '钥匙箱', 'gifts': '礼物', 'combinationChest': '密码箱', 'keys': '钥匙',};
const keyTypeDict = {'b': '铜', 's': '银', 'g': '金',};
const dropHist = localStorage.getItem('wh-loot-store')
let dropHist = localStorage.getItem('wh-loot-store')
? JSON.parse(localStorage.getItem('wh-loot-store'))
: {};
const alertSettings = localStorage.getItem('wh-loot-setting')
? JSON.parse(localStorage.getItem('wh-loot-setting'))
: {blink: 'y', sound: 'y'};
let onClickBind = false;
const intervalID = window.setInterval(() => {
const $city_wrapper = $root.querySelector('#ct-wrap');
if ($city_wrapper) {
const $ct_title = $city_wrapper.querySelector('.status-title');
const $pos = $city_wrapper.querySelector('.map-title span[class^="position___"]') || $city_wrapper.querySelector('.status-title span[class^="position___"]');
: {blink: 'y', sound: 'y', chest: 'y'};
let $ct_wrap;
const getDOMOb = new MutationObserver(() => {
$ct_wrap = $root.querySelector('#ct-wrap');
if ($ct_wrap) {
getDOMOb.disconnect();
ob.observe($ct_wrap, {childList: true, subtree: true});
}
});
const ob = new MutationObserver(() => {
// if ($ct_wrap) {
const $ct_title = $ct_wrap.querySelector('.status-title');
const $pos = $ct_wrap.querySelector('.map-title span[class^="position___"]') || $ct_wrap.querySelector('.status-title span[class^="position___"]');
if (!$pos) return;
const $pos_spl = $pos.innerText.trim().split(',');
const player_position = {};
@ -5505,8 +5515,12 @@ margin: 0 0 3px;
<div id="wh-loot-container-ex" class="cont-gray wh-hide">
<div><input type="checkbox" id="wh-loot-setting-blink" ${alertSettings.blink === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-blink">闪烁提示</label></div>
<div><input type="checkbox" id="wh-loot-setting-sound" ${alertSettings.sound === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-sound">声音提示(不支持iOS)</label></div>
<div><input type="checkbox" id="wh-loot-setting-chest" ${alertSettings.chest === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-chest">不记录需要钥匙的宝箱</label></div>
<div>
<table><thead><tr><th colspan="5">历史记录</th></tr><tr><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody></tbody></table>
<div id="wh-hist-clear">
<p><button>清空数据</button>- bug</p>
</div>
<table><thead><tr><th colspan="5">历史记录</th></tr><tr><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody></tbody></table>
</div>
</div>
<div id="wh-loot-btn" class="cont-gray"><button>设置</button></div>
@ -5539,7 +5553,7 @@ margin: 0 0 3px;
100% {background: #f2f2f2}
}
</style>`;
$($city_wrapper).before(insert_html);
$($ct_wrap).before(insert_html);
$wh_loot_container = $root.querySelector('#wh-loot-container');
}
const $audio = $wh_loot_container.querySelector('audio');
@ -5547,13 +5561,20 @@ margin: 0 0 3px;
alertSettings.blink = $blink.checked ? 'y' : 'n';
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound');
alertSettings.sound = $sound.checked ? 'y' : 'n';
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest');
alertSettings.chest = $chest.checked ? 'y' : 'n';
const $ex = $wh_loot_container.querySelector('#wh-loot-container-ex');
const $btn = $wh_loot_container.querySelector('#wh-loot-btn button');
const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button');
const $tbody = $wh_loot_container.querySelector('tbody');
if (!onClickBind) $btn.onclick = (e) => {
if ($btn.onclick === null) $btn.onclick = (e) => {
e.target.innerText = e.target.innerText === '设置' ? '收起' : '设置';
$($ex).toggleClass('wh-hide');
onClickBind = true;
e.target.blur();
};
if ($clear_btn.onclick === null) $clear_btn.onclick = (e) => {
dropHist = {};
$tbody.innerHTML = '';
e.target.blur();
};
const nearby_arr = [];
@ -5572,8 +5593,8 @@ margin: 0 0 3px;
const $wh_loot_container_items = $wh_loot_container.querySelector('#wh-loot-container-items');
const $wh_loot_container_chests = $wh_loot_container.querySelector('#wh-loot-container-chests');
let item_count = 0, chest_count = 0;
$wh_loot_container_items.innerHTML = ``;
$wh_loot_container_chests.innerHTML = ``;
$wh_loot_container_items.innerHTML = '';
$wh_loot_container_chests.innerHTML = '';
nearby_arr.forEach(nearby_item => {
let path = '=';
if (nearby_item.x < player_position.x && nearby_item.y < player_position.y) path = '↙';
@ -5584,9 +5605,11 @@ margin: 0 0 3px;
else if (nearby_item.x > player_position.x && nearby_item.y === player_position.y) path = '→';
else if (nearby_item.x > player_position.x && nearby_item.y < player_position.y) path = '↘';
else if (nearby_item.x === player_position.x && nearby_item.y < player_position.y) path = '↓';
let isChest = false;
let item_name;
if (nearby_item.name === 'chests') {
chest_count++;
isChest = true;
item_name = chestTypeDict[nearby_item.type] + lootTypeDict[nearby_item.name];
$wh_loot_container_chests.innerHTML += `<span style="background-color: ${chestTypeColorDict[nearby_item.type] || 'silver'};">${path}[${nearby_item.x},${nearby_item.y}] ${item_name}<img src="${nearby_item.url}" /></span>`
} else {
@ -5594,16 +5617,18 @@ margin: 0 0 3px;
item_name = (nearby_item.name === 'keys' ? keyTypeDict[nearby_item.type] || '' : '') + lootTypeDict[nearby_item.name] || nearby_item.name;
$wh_loot_container_items.innerHTML += `<span>${path}[${nearby_item.x},${nearby_item.y}] ${item_name}<img src="${nearby_item.url}" /></span>`
}
// 确认地图坐标存在
if ($ct_title) {
const now = new Date();
const hist_key = `[${nearby_item.x},${nearby_item.y}]"${$ct_title.firstChild.nodeValue.trim()}"`;
const hist_key = `[${nearby_item.x},${nearby_item.y}]"${$ct_title.firstChild.nodeValue.trim()}"${item_name}`;
const el = dropHist[hist_key];
if (el) {
if (nearby_item.x === player_position.x && nearby_item.y === player_position.y && nearby_item.name !== ('chests' || 'combinationChest')) {
if (path === '=' && (nearby_item.name === 'keys' || nearby_item.name === 'gifts')) {
el.isPassed = true;
}
el.last = `${now.getFullYear()}-${now.getMonth()}-${now.getDay()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
} else {
// (() => {
if (!(isChest && $chest.checked)) {
const now = new Date();
dropHist[hist_key] = {
pos: `[${nearby_item.x},${nearby_item.y}]`,
map: $ct_title.firstChild.nodeValue.trim(),
@ -5612,6 +5637,11 @@ margin: 0 0 3px;
id: Object.keys(dropHist).length,
};
}
// else {
// return;
// }
// })();
}
}
});
$wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`;
@ -5626,7 +5656,7 @@ margin: 0 0 3px;
if (chest_count === 0) $wh_loot_container_chests.innerText = `暂无`;
const history = Object.keys(dropHist).map(key => dropHist[key]).sort((a, b) => a.id - b.id);
let table_html = ``;
let table_html = '';
history.forEach(e => {
table_html += `<tr><td>${e.pos}</td><td>${e.map}</td><td>${e.name}</td><td>${e.last}</td><td>${e.isPassed ? '已取得' : '不确定'}</td></tr>`;
});
@ -5634,8 +5664,8 @@ margin: 0 0 3px;
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
}
}, 1200);
});
getDOMOb.observe($root, {childList: true, subtree: true})
return;
}