wuhu-torn-helper/torn-wh-show-loot-pos.user.js

67 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name Torn圣诞小镇掉落物品坐标显示
// @namespace WH
// @version 0.1
// @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) 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 lootTypeDict = {'chests': '宝箱', 'gifts': '礼物箱',}
window.setInterval(() => {
const $city_wrapper = $root.querySelector('#ct-wrap');
if ($city_wrapper) {
const $wh_loot_container = $root.querySelector('#wh-loot-container');
if (!$wh_loot_container) {
const insert_html = `<div id="wh-loot-container" class="m-bottom10">
<div class="title-black"><span>附近物品</span></div>
<div id="wh-loot-container-main" class="cont-gray" style="padding: 0.5em">
<b>物品</b>
<div id="wh-loot-container-items"></div>
<b>箱子</b>
<div id="wh-loot-container-chests"></div>
</div>
</div>`;
$($city_wrapper).before(insert_html);
}
}
const items = $root.querySelectorAll('div.grid-layer div.items-layer div.ct-item');
let item_list = [];
items.forEach(e => {
const item_props = {x: 0, y: 0, name: '', type: ''};
item_props.x = parseInt(e.style.left.replaceAll('px', '')) / 30;
item_props.y = -parseInt(e.style.top.replaceAll('px', '')) / 30;
const srcSpl = e.firstElementChild.src.trim().split('/');
item_props.name = srcSpl[6];
item_props.type = srcSpl[8].slice(0, 1);
item_list[item_list.length] = item_props;
});
const $wh_loot_container_items = $root.querySelector('#wh-loot-container-items');
const $wh_loot_container_chests = $root.querySelector('#wh-loot-container-chests');
$wh_loot_container_items.innerHTML = ``;
$wh_loot_container_chests.innerHTML = ``;
item_list.forEach(e => {
if (e.name === 'chests') {
$wh_loot_container_chests.innerHTML += `<span>[${e.x},${e.y}] - ${chestTypeDict[e.type]}${lootTypeDict[e.name]}</span><br/>`
} else {
$wh_loot_container_items.innerHTML += `<span>[${e.x},${e.y}] - ${lootTypeDict[e.name] || '?钥匙'}</span><br/>`
}
});
}, 1200);
}
}());