From 8e2c250b1d86ded5844d192055f86fdaf664c5a1 Mon Sep 17 00:00:00 2001 From: woohoo Date: Wed, 22 Dec 2021 14:56:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=9C=A3=E8=AF=9E?= =?UTF-8?q?=E5=B0=8F=E9=95=87=E6=9C=89=E6=8E=89=E8=90=BD=E7=89=A9=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=A3=B0=E9=9F=B3=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 90 ++++++++++++++++++++--------------- torn-wh-show-loot-pos.user.js | 90 +++++++++++++++++++++-------------- 2 files changed, 107 insertions(+), 73 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 7bd22ae..6db269d 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -1,8 +1,8 @@ // ==UserScript== -// @lastmodified 202112220130 +// @lastmodified 202112221455 // @name Torn翻译 // @namespace WOOH -// @version 0.1.1222a +// @version 0.1.1222b // @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.1222b', + date: '20211222', + cont: `添加了圣诞小镇有掉落物时的声音效果`, + }, { ver: '0.1.1222a', date: '20211222', @@ -5472,69 +5477,78 @@ margin: 0 0 3px; 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'); + let $wh_loot_container = $root.querySelector('#wh-loot-container'); if (!$wh_loot_container) { const insert_html = `
+
附近物品
-
-物品 -
-箱子 -
+
+ 物品 +
+ 箱子 +
-`; +} +`; $($city_wrapper).before(insert_html); + $wh_loot_container = $root.querySelector('#wh-loot-container'); } - let item_list = []; + 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(e => { + items.forEach(el => { const item_props = {x: 0, y: 0, name: '', type: '', url: '',}; - 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.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); - item_props.url = e.firstElementChild.src; - item_list[item_list.length] = item_props; + nearby_arr.push(item_props); }); - const $wh_loot_container_items = $root.querySelector('#wh-loot-container-items'); - const $wh_loot_container_chests = $root.querySelector('#wh-loot-container-chests'); + 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; - if ($wh_loot_container_items) $wh_loot_container_items.innerHTML = ``; - if ($wh_loot_container_chests) $wh_loot_container_chests.innerHTML = ``; - item_list.forEach(e => { - let path = '·'; - if (e.x < player_position.x && e.y < player_position.y) path = '↙'; - else if (e.x < player_position.x && e.y === player_position.y) path = '←'; - else if (e.x < player_position.x && e.y > player_position.y) path = '↖'; - else if (e.x === player_position.x && e.y > player_position.y) path = '↑'; - else if (e.x > player_position.x && e.y > player_position.y) path = '↗'; - else if (e.x > player_position.x && e.y === player_position.y) path = '→'; - else if (e.x > player_position.x && e.y < player_position.y) path = '↘'; - else if (e.x === player_position.x && e.y < player_position.y) path = '↓'; - if (e.name === 'chests') { + $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 += `${path}[${e.x},${e.y}] - ${chestTypeDict[e.type]}${lootTypeDict[e.name]}` + $wh_loot_container_chests.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${chestTypeDict[nearby_item.type]}${lootTypeDict[nearby_item.name]}` } else { item_count++; - $wh_loot_container_items.innerHTML += `${path}[${e.x},${e.y}] - ${e.name === 'keys' ? keyTypeDict[e.type] || '' : ''}${lootTypeDict[e.name] || e.name}` + $wh_loot_container_items.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${nearby_item.name === 'keys' ? keyTypeDict[nearby_item.type] || '' : ''}${lootTypeDict[nearby_item.name] || nearby_item.name}` } }); - $root.querySelector('#wh-loot-item-count').innerText = `(${item_count})`; + $wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`; if (item_count === 0) { $wh_loot_container_items.innerText = `暂无`; - $root.querySelector('#wh-loot-container-main').style.animation =''; + $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = ''; } else { - $root.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; + $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; + $audio.play().then(); } - $root.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 = `暂无`; } }, 1200); diff --git a/torn-wh-show-loot-pos.user.js b/torn-wh-show-loot-pos.user.js index d17854d..896c507 100644 --- a/torn-wh-show-loot-pos.user.js +++ b/torn-wh-show-loot-pos.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Torn圣诞小镇掉落物品坐标显示 // @namespace WH -// @version 0.2.1 +// @version 0.2.2 // @description 在地图界面上方显示附近的宝箱、物品、钥匙坐标,兼容手机APP Torn PDA及Alook // @author Woohoo[2687093] // @match https://www.torn.com/* @@ -32,58 +32,78 @@ 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'); + let $wh_loot_container = $root.querySelector('#wh-loot-container'); if (!$wh_loot_container) { const insert_html = `
+
附近物品
-
-物品 -
-箱子 -
+
+ 物品 +
+ 箱子 +
-
`; +
+`; $($city_wrapper).before(insert_html); + $wh_loot_container = $root.querySelector('#wh-loot-container'); } - let item_list = []; + 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(e => { + items.forEach(el => { const item_props = {x: 0, y: 0, name: '', type: '', url: '',}; - 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.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); - item_props.url = e.firstElementChild.src; - item_list[item_list.length] = item_props; + nearby_arr.push(item_props); }); - const $wh_loot_container_items = $root.querySelector('#wh-loot-container-items'); - const $wh_loot_container_chests = $root.querySelector('#wh-loot-container-chests'); + 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; - if ($wh_loot_container_items) $wh_loot_container_items.innerHTML = ``; - if ($wh_loot_container_chests) $wh_loot_container_chests.innerHTML = ``; - item_list.forEach(e => { - let path = '·'; - if (e.x < player_position.x && e.y < player_position.y) path = '↙'; - else if (e.x < player_position.x && e.y === player_position.y) path = '←'; - else if (e.x < player_position.x && e.y > player_position.y) path = '↖'; - else if (e.x === player_position.x && e.y > player_position.y) path = '↑'; - else if (e.x > player_position.x && e.y > player_position.y) path = '↗'; - else if (e.x > player_position.x && e.y === player_position.y) path = '→'; - else if (e.x > player_position.x && e.y < player_position.y) path = '↘'; - else if (e.x === player_position.x && e.y < player_position.y) path = '↓'; - if (e.name === 'chests') { + $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 += `${path}[${e.x},${e.y}] - ${chestTypeDict[e.type]}${lootTypeDict[e.name]}` + $wh_loot_container_chests.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${chestTypeDict[nearby_item.type]}${lootTypeDict[nearby_item.name]}` } else { item_count++; - $wh_loot_container_items.innerHTML += `${path}[${e.x},${e.y}] - ${e.name === 'keys' ? keyTypeDict[e.type] || '' : ''}${lootTypeDict[e.name] || e.name}` + $wh_loot_container_items.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${nearby_item.name === 'keys' ? keyTypeDict[nearby_item.type] || '' : ''}${lootTypeDict[nearby_item.name] || nearby_item.name}` } }); - $root.querySelector('#wh-loot-item-count').innerText = `(${item_count})`; - if (item_count === 0) $wh_loot_container_items.innerText = `暂无`; - $root.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`; + $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);