113 lines
6.6 KiB
JavaScript
113 lines
6.6 KiB
JavaScript
// ==UserScript==
|
||
// @name Torn圣诞小镇掉落物品坐标显示
|
||
// @namespace WH
|
||
// @version 0.2.2
|
||
// @description 在地图界面上方显示附近的宝箱、物品、钥匙坐标,兼容手机APP Torn PDA及Alook
|
||
// @author Woohoo[2687093]
|
||
// @match https://www.torn.com/*
|
||
// @grant none
|
||
// ==/UserScript==
|
||
|
||
|
||
(function () {
|
||
'use strict';
|
||
const ___window___ = window || window.unsafeWindow;
|
||
if (___window___.WHLOOTPOS||___window___.WHTRANS) return;
|
||
___window___.WHLOOTPOS = true;
|
||
|
||
const $ = ___window___.jQuery;
|
||
|
||
if (/christmas_town\.php/.test(window.location.href)) {
|
||
const $root = document.querySelector('#christmastownroot');
|
||
const chestTypeDict = {'1': '金', '2': '银', '3': '铜',};
|
||
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
|
||
const lootTypeDict = {'chests': '钥匙箱', 'gifts': '礼物', 'combinationChest': '密码箱', 'keys': '钥匙',};
|
||
const keyTypeDict = {'b': '铜', 's': '银', 'g': '金',};
|
||
const intervalID = window.setInterval(() => {
|
||
const $city_wrapper = $root.querySelector('#ct-wrap');
|
||
if ($city_wrapper) {
|
||
const $pos = $city_wrapper.querySelector('.map-title span[class^="position___"]') || $city_wrapper.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">
|
||
<audio src="https://www.torn.com/js/chat/sounds/Chirp_3.mp3" style="display:none"></audio>
|
||
<div class="title-black"><span>附近物品</span></div>
|
||
<div id="wh-loot-container-main" class="cont-gray">
|
||
<b>物品</b><span id="wh-loot-item-count"></span>
|
||
<div id="wh-loot-container-items"></div>
|
||
<b>箱子</b><span id="wh-loot-chest-count"></span>
|
||
<div id="wh-loot-container-chests"></div>
|
||
</div>
|
||
</div>
|
||
<style>
|
||
#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 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;}
|
||
@keyframes lootFoundAlert {
|
||
0% {background: #f2f2f2}
|
||
50% {background: #2e8b57}
|
||
100% {background: #f2f2f2}
|
||
}
|
||
</style>`;
|
||
$($city_wrapper).before(insert_html);
|
||
$wh_loot_container = $root.querySelector('#wh-loot-container');
|
||
}
|
||
const $audio = $wh_loot_container.querySelector('audio');
|
||
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 = '↓';
|
||
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 {
|
||
item_count++;
|
||
$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-item-count').innerText = `(${item_count})`;
|
||
if (item_count === 0) {
|
||
$wh_loot_container_items.innerText = `暂无`;
|
||
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = '';
|
||
} else {
|
||
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite';
|
||
$audio.play().then();
|
||
}
|
||
$wh_loot_container.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`;
|
||
if (chest_count === 0) $wh_loot_container_chests.innerText = `暂无`;
|
||
}
|
||
}, 1200);
|
||
}
|
||
|
||
}());
|