修复小镇提示的错误

This commit is contained in:
woohoo 2021-12-29 16:22:55 +08:00
parent e79f094fce
commit b98663abb9
2 changed files with 48 additions and 23 deletions

View File

@ -1,8 +1,8 @@
// ==UserScript==
// @lastmodified 202112290010
// @lastmodified 202112291622
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1229a
// @version 0.1.1229b
// @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.1229b',
date: '20211229',
cont: `修复小镇提示的错误`,
},
{
ver: '0.1.1229a',
date: '20211229',
@ -2887,7 +2892,6 @@
quichAttIndex: 2,
isDev: false,
};
// const quickAttArr = ['pri', 'sec', 'wea', 'gre', 'fis', 'kic'];
initIcon();
addStyle(`#wh-trans-icon{
display: inline-block;
@ -5371,7 +5375,7 @@ padding:16px !important;
圣诞小镇
*/
if (window.location.href.contains(/christmas_town\.php/)) {
const $root = document.querySelector('#christmastownroot');
let $root = document.querySelector('#christmastownroot');
if (wh_trans_settings.transEnable) {
const $title_wrapper = $root.querySelector('div[class^="appHeaderWrapper___"]');
// 标题和右边的链接
@ -5712,12 +5716,12 @@ margin: 0 0 3px;
<div id="wh-loot-container-chests"></div>
</div>
<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><label><input type="checkbox" id="wh-loot-setting-blink" ${alertSettings.blink === 'y' ? 'checked' : ''} /> 闪烁提示</label></div>
<div><label><input type="checkbox" id="wh-loot-setting-sound" ${alertSettings.sound === 'y' ? 'checked' : ''} /> 声音提示 <del>(iOS)</del></label></div>
<div><label><input type="checkbox" id="wh-loot-setting-chest" ${alertSettings.chest === 'y' ? 'checked' : ''} /> 不记录需要钥匙的宝箱</label></div>
<div id="wh-hist">
<div id="wh-hist-clear">
<p><button>清空数据</button>- bug</p>
<p><button>清空数据</button>- </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>
@ -5806,15 +5810,22 @@ margin: 0 0 3px;
const soundIntervalID = window.setInterval(() => {
if (soundLoopFlag) $audio.play().then();
}, 1200);
ob.observe($ct_wrap, {childList: true, subtree: true});
ob.observe($root, {childList: true, subtree: true});
}
});
const ob = new MutationObserver(() => {
ob.disconnect();
// 页面刷新重新获取dom
$root = document.querySelector('#christmastownroot');
$ct_wrap = $root.querySelector('#ct-wrap');
if (!$ct_wrap) {
ob.observe($root, {childList: true, subtree: true});
return;
}
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) {
ob.observe($ct_wrap, {childList: true, subtree: true});
ob.observe($root, {childList: true, subtree: true});
return;
}
const $pos_spl = $pos.innerText.trim().split(',');
@ -5824,7 +5835,7 @@ margin: 0 0 3px;
const $wh_loot_container = $root.querySelector('#wh-loot-container');
if (!$wh_loot_container) {
console.error('掉落助手未找到DOM容器');
ob.observe($ct_wrap, {childList: true, subtree: true});
ob.observe($root, {childList: true, subtree: true});
return;
}
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
@ -5909,7 +5920,7 @@ margin: 0 0 3px;
});
$tbody.innerHTML = table_html;
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
ob.observe($ct_wrap, {childList: true, subtree: true});
ob.observe($root, {childList: true, subtree: true});
});
getDOMOb.observe($root, {childList: true, subtree: true});
}

View File

@ -18,7 +18,7 @@
const $ = ___window___.jQuery;
if (/christmas_town\.php/.test(window.location.href)) {
const $root = document.querySelector('#christmastownroot');
let $root = document.querySelector('#christmastownroot');
const chestTypeDict = {'1': '金', '2': '银', '3': '铜',};
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
const lootTypeDict = {'chests': '钥匙箱', 'gifts': '礼物', 'combinationChest': '密码箱', 'keys': '钥匙',};
@ -45,15 +45,15 @@
<div id="wh-loot-container-chests"></div>
</div>
<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>
<div><label><input type="checkbox" id="wh-loot-setting-blink" ${alertSettings.blink === 'y' ? 'checked' : ''} /> 闪烁提示</label></div>
<div><label><input type="checkbox" id="wh-loot-setting-sound" ${alertSettings.sound === 'y' ? 'checked' : ''} /> 声音提示 <del>(iOS)</del></label></div>
<div><label><input type="checkbox" id="wh-loot-setting-chest" ${alertSettings.chest === 'y' ? 'checked' : ''} /> 不记录需要钥匙的宝箱</label></div>
<div id="wh-hist">
<div id="wh-hist-clear">
<p><button>清空数据</button>- bug</p>
<p><button>清空数据</button>- </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>
<div id="wh-loot-btn" class="cont-gray"><button>设置</button></div>
</div>
@ -64,7 +64,9 @@
#wh-loot-container-main div span img{height: 1em; width: 1em;}
#wh-loot-container-ex{padding: 0.5em;}
#wh-loot-container-ex.wh-hide{display: none;}
#wh-loot-container-ex #wh-hist{overflow-x: auto;}
#wh-loot-container-ex table {margin-top: 0.5em;}
#wh-loot-container-ex tbody {background-color: antiquewhite;}
#wh-loot-container-ex table, #wh-loot-container-ex th, #wh-loot-container-ex td {
padding: 5px;
border: 1px solid black;
@ -137,13 +139,24 @@
const soundIntervalID = window.setInterval(() => {
if (soundLoopFlag) $audio.play().then();
}, 1200);
ob.observe($ct_wrap, {childList: true, subtree: true});
ob.observe($root, {childList: true, subtree: true});
}
});
const ob = new MutationObserver(() => {
ob.disconnect();
// 页面刷新重新获取dom
$root = document.querySelector('#christmastownroot');
$ct_wrap = $root.querySelector('#ct-wrap');
if (!$ct_wrap) {
ob.observe($root, {childList: true, subtree: true});
return;
}
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;
if (!$pos) {
ob.observe($root, {childList: true, subtree: true});
return;
}
const $pos_spl = $pos.innerText.trim().split(',');
const player_position = {};
player_position.x = parseInt($pos_spl[0]);
@ -151,6 +164,7 @@
const $wh_loot_container = $root.querySelector('#wh-loot-container');
if (!$wh_loot_container) {
console.error('掉落助手未找到DOM容器');
ob.observe($root, {childList: true, subtree: true});
return;
}
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
@ -209,7 +223,7 @@
dropHist[hist_key] = {
pos: `[${nearby_item.x},${nearby_item.y}]`,
map: $ct_title.firstChild.nodeValue.trim(),
last: `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`,
last: `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`,
name: item_name,
id: Object.keys(dropHist).length,
};
@ -235,8 +249,8 @@
});
$tbody.innerHTML = table_html;
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
ob.observe($root, {childList: true, subtree: true});
});
getDOMOb.observe($root, {childList: true, subtree: true});
}
}());