小镇提示逻辑改写
This commit is contained in:
parent
57894c2a42
commit
a4b91dcc96
@ -1,8 +1,8 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @lastmodified 202112241544
|
// @lastmodified 202112241711
|
||||||
// @name Torn翻译
|
// @name Torn翻译
|
||||||
// @namespace WOOH
|
// @namespace WOOH
|
||||||
// @version 0.1.1224a
|
// @version 0.1.1224b
|
||||||
// @description Torn UI翻译
|
// @description Torn UI翻译
|
||||||
// @author Woohoo-[2687093] sabrina_devil[2696209]
|
// @author Woohoo-[2687093] sabrina_devil[2696209]
|
||||||
// @match https://www.torn.com/*
|
// @match https://www.torn.com/*
|
||||||
@ -23,6 +23,11 @@
|
|||||||
todo: true,
|
todo: true,
|
||||||
cont: `baza npc商店 imarket及imarket搜索结果`,
|
cont: `baza npc商店 imarket及imarket搜索结果`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ver: '0.1.1224b',
|
||||||
|
date: '20211224',
|
||||||
|
cont: `小镇提示逻辑改写`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ver: '0.1.1224a',
|
ver: '0.1.1224a',
|
||||||
date: '20211224',
|
date: '20211224',
|
||||||
@ -5485,24 +5490,11 @@ margin: 0 0 3px;
|
|||||||
? JSON.parse(localStorage.getItem('wh-loot-setting'))
|
? JSON.parse(localStorage.getItem('wh-loot-setting'))
|
||||||
: {blink: 'y', sound: 'y', chest: 'y'};
|
: {blink: 'y', sound: 'y', chest: 'y'};
|
||||||
let $ct_wrap;
|
let $ct_wrap;
|
||||||
|
let soundLoopFlag = false;
|
||||||
const getDOMOb = new MutationObserver(() => {
|
const getDOMOb = new MutationObserver(() => {
|
||||||
$ct_wrap = $root.querySelector('#ct-wrap');
|
$ct_wrap = $root.querySelector('#ct-wrap');
|
||||||
if ($ct_wrap) {
|
if ($ct_wrap) {
|
||||||
getDOMOb.disconnect();
|
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 = {};
|
|
||||||
player_position.x = parseInt($pos_spl[0]);
|
|
||||||
player_position.y = parseInt($pos_spl[1]);
|
|
||||||
let $wh_loot_container = $root.querySelector('#wh-loot-container');
|
|
||||||
if (!$wh_loot_container) {
|
|
||||||
const insert_html = `<div id="wh-loot-container" class="m-bottom10">
|
const insert_html = `<div id="wh-loot-container" class="m-bottom10">
|
||||||
<audio src="https://www.torn.com/js/chat/sounds/Chirp_3.mp3" style="display:none"></audio>
|
<audio src="https://www.torn.com/js/chat/sounds/Chirp_3.mp3" style="display:none"></audio>
|
||||||
<div class="title-black"><span>附近物品</span></div>
|
<div class="title-black"><span>附近物品</span></div>
|
||||||
@ -5554,29 +5546,76 @@ margin: 0 0 3px;
|
|||||||
}
|
}
|
||||||
</style>`;
|
</style>`;
|
||||||
$($ct_wrap).before(insert_html);
|
$($ct_wrap).before(insert_html);
|
||||||
$wh_loot_container = $root.querySelector('#wh-loot-container');
|
const $wh_loot_container = $root.querySelector('#wh-loot-container');
|
||||||
|
const $btn = $wh_loot_container.querySelector('#wh-loot-btn button');
|
||||||
|
const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button');
|
||||||
|
const $ex = $wh_loot_container.querySelector('#wh-loot-container-ex');
|
||||||
|
const $tbody = $wh_loot_container.querySelector('tbody');
|
||||||
|
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
|
||||||
|
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound');
|
||||||
|
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest');
|
||||||
|
const $audio = $wh_loot_container.querySelector('audio');
|
||||||
|
$btn.onclick = e => {
|
||||||
|
e.target.innerText = e.target.innerText === '设置' ? '收起' : '设置';
|
||||||
|
$($ex).toggleClass('wh-hide');
|
||||||
|
e.target.blur();
|
||||||
|
};
|
||||||
|
$clear_btn.onclick = e => {
|
||||||
|
dropHist = {};
|
||||||
|
$tbody.innerHTML = '';
|
||||||
|
e.target.blur();
|
||||||
|
};
|
||||||
|
$blink.onchange = e => {
|
||||||
|
if (e.target.checked) {
|
||||||
|
alertSettings.blink = 'y';
|
||||||
|
if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') {
|
||||||
|
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alertSettings.blink = 'n';
|
||||||
|
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = '';
|
||||||
|
}
|
||||||
|
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
|
||||||
|
};
|
||||||
|
$sound.onchange = e => {
|
||||||
|
if (e.target.checked) {
|
||||||
|
alertSettings.sound = 'y';
|
||||||
|
if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') {
|
||||||
|
soundLoopFlag = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alertSettings.sound = 'n';
|
||||||
|
soundLoopFlag = false;
|
||||||
|
}
|
||||||
|
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
|
||||||
|
};
|
||||||
|
$chest.onchange = e => {
|
||||||
|
alertSettings.chest = e.target.checked ? 'y' : 'n';
|
||||||
|
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
|
||||||
|
};
|
||||||
|
const soundIntervalID = window.setInterval(() => {
|
||||||
|
if (soundLoopFlag) $audio.play().then();
|
||||||
|
}, 1200);
|
||||||
|
ob.observe($ct_wrap, {childList: true, subtree: true});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const ob = new MutationObserver(() => {
|
||||||
|
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 = {};
|
||||||
|
player_position.x = parseInt($pos_spl[0]);
|
||||||
|
player_position.y = parseInt($pos_spl[1]);
|
||||||
|
const $wh_loot_container = $root.querySelector('#wh-loot-container');
|
||||||
|
if (!$wh_loot_container) {
|
||||||
|
console.error('掉落助手未找到DOM容器');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const $audio = $wh_loot_container.querySelector('audio');
|
|
||||||
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
|
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
|
||||||
alertSettings.blink = $blink.checked ? 'y' : 'n';
|
|
||||||
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound');
|
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');
|
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');
|
const $tbody = $wh_loot_container.querySelector('tbody');
|
||||||
if ($btn.onclick === null) $btn.onclick = (e) => {
|
|
||||||
e.target.innerText = e.target.innerText === '设置' ? '收起' : '设置';
|
|
||||||
$($ex).toggleClass('wh-hide');
|
|
||||||
e.target.blur();
|
|
||||||
};
|
|
||||||
if ($clear_btn.onclick === null) $clear_btn.onclick = (e) => {
|
|
||||||
dropHist = {};
|
|
||||||
$tbody.innerHTML = '';
|
|
||||||
e.target.blur();
|
|
||||||
};
|
|
||||||
const nearby_arr = [];
|
const nearby_arr = [];
|
||||||
const items = $root.querySelectorAll('div.grid-layer div.items-layer div.ct-item');
|
const items = $root.querySelectorAll('div.grid-layer div.items-layer div.ct-item');
|
||||||
// 附近的所有物品
|
// 附近的所有物品
|
||||||
@ -5605,11 +5644,9 @@ 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 = '↘';
|
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;
|
let item_name;
|
||||||
if (nearby_item.name === 'chests') {
|
if (nearby_item.name === 'chests') {
|
||||||
chest_count++;
|
chest_count++;
|
||||||
isChest = true;
|
|
||||||
item_name = chestTypeDict[nearby_item.type] + lootTypeDict[nearby_item.name];
|
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>`
|
$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 {
|
} else {
|
||||||
@ -5626,8 +5663,7 @@ margin: 0 0 3px;
|
|||||||
el.isPassed = true;
|
el.isPassed = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// (() => {
|
if (!(nearby_item.name === 'chests' && $chest.checked)) {
|
||||||
if (!(isChest && $chest.checked)) {
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
dropHist[hist_key] = {
|
dropHist[hist_key] = {
|
||||||
pos: `[${nearby_item.x},${nearby_item.y}]`,
|
pos: `[${nearby_item.x},${nearby_item.y}]`,
|
||||||
@ -5637,35 +5673,29 @@ margin: 0 0 3px;
|
|||||||
id: Object.keys(dropHist).length,
|
id: Object.keys(dropHist).length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// })();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`;
|
$wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`;
|
||||||
if (item_count === 0) {
|
if (item_count === 0) {
|
||||||
$wh_loot_container_items.innerText = `暂无`;
|
$wh_loot_container_items.innerText = '暂无';
|
||||||
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = '';
|
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = '';
|
||||||
|
soundLoopFlag = false;
|
||||||
} else {
|
} else {
|
||||||
if ($blink.checked) $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite';
|
if ($blink.checked) $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite';
|
||||||
if ($sound.checked) $audio.play().then();
|
if ($sound.checked) soundLoopFlag = true;
|
||||||
}
|
}
|
||||||
$wh_loot_container.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`;
|
$wh_loot_container.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`;
|
||||||
if (chest_count === 0) $wh_loot_container_chests.innerText = `暂无`;
|
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);
|
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 => {
|
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>`;
|
table_html += `<tr><td>${e.pos}</td><td>${e.map}</td><td>${e.name}</td><td>${e.last}</td><td>${e.isPassed ? '已取得' : '不确定'}</td></tr>`;
|
||||||
});
|
});
|
||||||
$tbody.innerHTML = table_html;
|
$tbody.innerHTML = table_html;
|
||||||
|
|
||||||
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
|
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
|
||||||
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
|
|
||||||
});
|
});
|
||||||
getDOMOb.observe($root, {childList: true, subtree: true})
|
getDOMOb.observe($root, {childList: true, subtree: true});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,18 +23,19 @@
|
|||||||
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
|
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
|
||||||
const lootTypeDict = {'chests': '钥匙箱', 'gifts': '礼物', 'combinationChest': '密码箱', 'keys': '钥匙',};
|
const lootTypeDict = {'chests': '钥匙箱', 'gifts': '礼物', 'combinationChest': '密码箱', 'keys': '钥匙',};
|
||||||
const keyTypeDict = {'b': '铜', 's': '银', 'g': '金',};
|
const keyTypeDict = {'b': '铜', 's': '银', 'g': '金',};
|
||||||
const intervalID = window.setInterval(() => {
|
let dropHist = localStorage.getItem('wh-loot-store')
|
||||||
const $city_wrapper = $root.querySelector('#ct-wrap');
|
? JSON.parse(localStorage.getItem('wh-loot-store'))
|
||||||
if ($city_wrapper) {
|
: {};
|
||||||
const $pos = $city_wrapper.querySelector('.map-title span[class^="position___"]') || $city_wrapper.querySelector('.status-title span[class^="position___"]');
|
const alertSettings = localStorage.getItem('wh-loot-setting')
|
||||||
if (!$pos) return;
|
? JSON.parse(localStorage.getItem('wh-loot-setting'))
|
||||||
const $pos_spl = $pos.innerText.trim().split(',');
|
: {blink: 'y', sound: 'y', chest: 'y'};
|
||||||
const player_position = {};
|
let $ct_wrap;
|
||||||
player_position.x = parseInt($pos_spl[0]);
|
let soundLoopFlag = false;
|
||||||
player_position.y = parseInt($pos_spl[1]);
|
const getDOMOb = new MutationObserver(() => {
|
||||||
let $wh_loot_container = $root.querySelector('#wh-loot-container');
|
$ct_wrap = $root.querySelector('#ct-wrap');
|
||||||
if (!$wh_loot_container) {
|
if ($ct_wrap) {
|
||||||
const insert_html = `<div id="wh-loot-container" class="m-bottom10">
|
getDOMOb.disconnect();
|
||||||
|
const insert_html = `<div id="wh-loot-container" class="m-bottom10">
|
||||||
<audio src="https://www.torn.com/js/chat/sounds/Chirp_3.mp3" style="display:none"></audio>
|
<audio src="https://www.torn.com/js/chat/sounds/Chirp_3.mp3" style="display:none"></audio>
|
||||||
<div class="title-black"><span>附近物品</span></div>
|
<div class="title-black"><span>附近物品</span></div>
|
||||||
<div id="wh-loot-container-main" class="cont-gray">
|
<div id="wh-loot-container-main" class="cont-gray">
|
||||||
@ -43,70 +44,198 @@
|
|||||||
<b>箱子</b><span id="wh-loot-chest-count"></span>
|
<b>箱子</b><span id="wh-loot-chest-count"></span>
|
||||||
<div id="wh-loot-container-chests"></div>
|
<div id="wh-loot-container-chests"></div>
|
||||||
</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 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>
|
||||||
</div>
|
</div>
|
||||||
<style>
|
<style>
|
||||||
#wh-loot-container-main{padding: 0.5em;}
|
#wh-loot-container-main{padding: 0.5em;}
|
||||||
#wh-loot-container-main div{overflow-x: auto;overflow-y: hidden;white-space: nowrap;min-height: 4em;}
|
#wh-loot-container-main div{overflow-x: auto;overflow-y: hidden;white-space: nowrap;min-height: 4em;}
|
||||||
#wh-loot-container-main div span{display: inline-block;background-color: #2e8b57;color: white;margin: 0 1em 0 0;border-radius: 4px;padding: 0.5em;}
|
#wh-loot-container-main div span{display: inline-block;background-color: #2e8b57;color: white;margin: 0 1em 0 0;border-radius: 4px;padding: 0.5em;}
|
||||||
#wh-loot-container-main div span img{height: 1em; width: 1em;}
|
#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 table {margin-top: 0.5em;}
|
||||||
|
#wh-loot-container-ex table, #wh-loot-container-ex th, #wh-loot-container-ex td {
|
||||||
|
padding: 5px;
|
||||||
|
border: 1px solid black;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
#wh-loot-container-ex th:nth-child(1) {min-width: 5em;}
|
||||||
|
#wh-loot-container-ex th:nth-child(2) {min-width: 8em;}
|
||||||
|
#wh-loot-container-ex th:nth-child(3) {min-width: 4em;}
|
||||||
|
#wh-loot-container-ex th:nth-child(4) {min-width: 9em;}
|
||||||
|
#wh-loot-container-ex th:nth-child(5) {min-width: 3em;}
|
||||||
|
#wh-loot-container-ex thead {
|
||||||
|
background-color: #2e8b57;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
@keyframes lootFoundAlert {
|
@keyframes lootFoundAlert {
|
||||||
0% {background: #f2f2f2}
|
0% {background: #f2f2f2}
|
||||||
50% {background: #2e8b57}
|
50% {background: #2e8b57}
|
||||||
100% {background: #f2f2f2}
|
100% {background: #f2f2f2}
|
||||||
}
|
}
|
||||||
</style>`;
|
</style>`;
|
||||||
$($city_wrapper).before(insert_html);
|
$($ct_wrap).before(insert_html);
|
||||||
$wh_loot_container = $root.querySelector('#wh-loot-container');
|
const $wh_loot_container = $root.querySelector('#wh-loot-container');
|
||||||
}
|
const $btn = $wh_loot_container.querySelector('#wh-loot-btn button');
|
||||||
|
const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button');
|
||||||
|
const $ex = $wh_loot_container.querySelector('#wh-loot-container-ex');
|
||||||
|
const $tbody = $wh_loot_container.querySelector('tbody');
|
||||||
|
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
|
||||||
|
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound');
|
||||||
|
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest');
|
||||||
const $audio = $wh_loot_container.querySelector('audio');
|
const $audio = $wh_loot_container.querySelector('audio');
|
||||||
const nearby_arr = [];
|
$btn.onclick = e => {
|
||||||
const items = $root.querySelectorAll('div.grid-layer div.items-layer div.ct-item');
|
e.target.innerText = e.target.innerText === '设置' ? '收起' : '设置';
|
||||||
// 附近的所有物品
|
$($ex).toggleClass('wh-hide');
|
||||||
items.forEach(el => {
|
e.target.blur();
|
||||||
const item_props = {x: 0, y: 0, name: '', type: '', url: '',};
|
};
|
||||||
item_props.x = parseInt(el.style.left.replaceAll('px', '')) / 30;
|
$clear_btn.onclick = e => {
|
||||||
item_props.y = -parseInt(el.style.top.replaceAll('px', '')) / 30;
|
dropHist = {};
|
||||||
item_props.url = el.firstElementChild.src;
|
$tbody.innerHTML = '';
|
||||||
const srcSpl = item_props.url.trim().split('/');
|
e.target.blur();
|
||||||
item_props.name = srcSpl[6];
|
};
|
||||||
item_props.type = srcSpl[8].slice(0, 1);
|
$blink.onchange = e => {
|
||||||
nearby_arr.push(item_props);
|
if (e.target.checked) {
|
||||||
});
|
alertSettings.blink = 'y';
|
||||||
const $wh_loot_container_items = $wh_loot_container.querySelector('#wh-loot-container-items');
|
if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') {
|
||||||
const $wh_loot_container_chests = $wh_loot_container.querySelector('#wh-loot-container-chests');
|
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite';
|
||||||
let item_count = 0, chest_count = 0;
|
}
|
||||||
$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 = '↙';
|
|
||||||
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 = '↑';
|
|
||||||
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 = '↘';
|
|
||||||
else if (nearby_item.x === player_position.x && nearby_item.y < player_position.y) path = '↓';
|
|
||||||
if (nearby_item.name === 'chests') {
|
|
||||||
chest_count++;
|
|
||||||
$wh_loot_container_chests.innerHTML += `<span style="background-color: ${chestTypeColorDict[nearby_item.type] || 'silver'};">${path}[${nearby_item.x},${nearby_item.y}] ${chestTypeDict[nearby_item.type]}${lootTypeDict[nearby_item.name]}<img src="${nearby_item.url}" /></span>`
|
|
||||||
} else {
|
} else {
|
||||||
item_count++;
|
alertSettings.blink = 'n';
|
||||||
$wh_loot_container_items.innerHTML += `<span>${path}[${nearby_item.x},${nearby_item.y}] ${nearby_item.name === 'keys' ? keyTypeDict[nearby_item.type] || '' : ''}${lootTypeDict[nearby_item.name] || nearby_item.name}<img src="${nearby_item.url}" /></span>`
|
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = '';
|
||||||
}
|
}
|
||||||
});
|
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
|
||||||
$wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`;
|
};
|
||||||
if (item_count === 0) {
|
$sound.onchange = e => {
|
||||||
$wh_loot_container_items.innerText = `暂无`;
|
if (e.target.checked) {
|
||||||
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = '';
|
alertSettings.sound = 'y';
|
||||||
} else {
|
if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') {
|
||||||
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite';
|
soundLoopFlag = true;
|
||||||
$audio.play().then();
|
}
|
||||||
}
|
} else {
|
||||||
$wh_loot_container.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`;
|
alertSettings.sound = 'n';
|
||||||
if (chest_count === 0) $wh_loot_container_chests.innerText = `暂无`;
|
soundLoopFlag = false;
|
||||||
|
}
|
||||||
|
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
|
||||||
|
};
|
||||||
|
$chest.onchange = e => {
|
||||||
|
alertSettings.chest = e.target.checked ? 'y' : 'n';
|
||||||
|
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
|
||||||
|
};
|
||||||
|
const soundIntervalID = window.setInterval(() => {
|
||||||
|
if (soundLoopFlag) $audio.play().then();
|
||||||
|
}, 1200);
|
||||||
|
ob.observe($ct_wrap, {childList: true, subtree: true});
|
||||||
}
|
}
|
||||||
}, 1200);
|
});
|
||||||
|
const ob = new MutationObserver(() => {
|
||||||
|
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 = {};
|
||||||
|
player_position.x = parseInt($pos_spl[0]);
|
||||||
|
player_position.y = parseInt($pos_spl[1]);
|
||||||
|
const $wh_loot_container = $root.querySelector('#wh-loot-container');
|
||||||
|
if (!$wh_loot_container) {
|
||||||
|
console.error('掉落助手未找到DOM容器');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
|
||||||
|
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound');
|
||||||
|
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest');
|
||||||
|
const $tbody = $wh_loot_container.querySelector('tbody');
|
||||||
|
const nearby_arr = [];
|
||||||
|
const items = $root.querySelectorAll('div.grid-layer div.items-layer div.ct-item');
|
||||||
|
// 附近的所有物品
|
||||||
|
items.forEach(el => {
|
||||||
|
const item_props = {x: 0, y: 0, name: '', type: '', url: '',};
|
||||||
|
item_props.x = parseInt(el.style.left.replaceAll('px', '')) / 30;
|
||||||
|
item_props.y = -parseInt(el.style.top.replaceAll('px', '')) / 30;
|
||||||
|
item_props.url = el.firstElementChild.src;
|
||||||
|
const srcSpl = item_props.url.trim().split('/');
|
||||||
|
item_props.name = srcSpl[6];
|
||||||
|
item_props.type = srcSpl[8].slice(0, 1);
|
||||||
|
nearby_arr.push(item_props);
|
||||||
|
});
|
||||||
|
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 = '';
|
||||||
|
nearby_arr.forEach(nearby_item => {
|
||||||
|
let path = '=';
|
||||||
|
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 = '↖';
|
||||||
|
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 = '→';
|
||||||
|
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 item_name;
|
||||||
|
if (nearby_item.name === 'chests') {
|
||||||
|
chest_count++;
|
||||||
|
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 {
|
||||||
|
item_count++;
|
||||||
|
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 hist_key = `[${nearby_item.x},${nearby_item.y}]"${$ct_title.firstChild.nodeValue.trim()}"${item_name}`;
|
||||||
|
const el = dropHist[hist_key];
|
||||||
|
if (el) {
|
||||||
|
if (path === '=' && (nearby_item.name === 'keys' || nearby_item.name === 'gifts')) {
|
||||||
|
el.isPassed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!(nearby_item.name === 'chests' && $chest.checked)) {
|
||||||
|
const now = new Date();
|
||||||
|
dropHist[hist_key] = {
|
||||||
|
pos: `[${nearby_item.x},${nearby_item.y}]`,
|
||||||
|
map: $ct_title.firstChild.nodeValue.trim(),
|
||||||
|
last: `${now.getFullYear()}-${now.getMonth()}-${now.getDay()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`,
|
||||||
|
name: item_name,
|
||||||
|
id: Object.keys(dropHist).length,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`;
|
||||||
|
if (item_count === 0) {
|
||||||
|
$wh_loot_container_items.innerText = '暂无';
|
||||||
|
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = '';
|
||||||
|
soundLoopFlag = false;
|
||||||
|
} else {
|
||||||
|
if ($blink.checked) $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite';
|
||||||
|
if ($sound.checked) soundLoopFlag = true;
|
||||||
|
}
|
||||||
|
$wh_loot_container.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`;
|
||||||
|
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 = '';
|
||||||
|
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>`;
|
||||||
|
});
|
||||||
|
$tbody.innerHTML = table_html;
|
||||||
|
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
|
||||||
|
});
|
||||||
|
getDOMOb.observe($root, {childList: true, subtree: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user