This commit is contained in:
Liwanyi 2022-09-15 12:02:26 +08:00
parent 26c9227461
commit e7bece004f
11 changed files with 354 additions and 344 deletions

2
global.d.ts vendored
View File

@ -28,6 +28,8 @@ declare interface Window {
initMiniProf(selector: string): void; initMiniProf(selector: string): void;
renderMiniProfile(node: Element, props: any);
/* PDA自带 */ /* PDA自带 */
PDA_httpGet(url: URL | string): Promise<PDA_Response>; PDA_httpGet(url: URL | string): Promise<PDA_Response>;

View File

@ -0,0 +1,139 @@
import elementReady from "../utils/elementReady";
import COFetch from "../utils/COFetch";
import addStyle from "../utils/addStyle";
import toThousands from "../utils/toThousands";
import log from "../utils/log";
export default function cityFinder(): void {
addStyle(`
.wh-city-finds .leaflet-marker-pane img[src*="torn.com/images/items/"]{
display: block !important;
box-sizing: border-box;
width: 40px !important;
height: 40px !important;
left: -20px !important;
top: -20px !important;
padding: 10px 0;
border: none;
border-radius: 100%;
background-color:#d2d2d28c;
box-shadow:0 0 10px 5px #000;
z-index: 999 !important;
}
.wh-city-finds .leaflet-marker-pane.leaflet-marker-icon.user-item-pinpoint.leaflet-clickable{display: none !important;}
#wh-city-finder{
box-shadow: 0 0 3px 0px #696969;
border-radius: 4px;
}
#wh-city-finder-header{
background-color: #3f51b5;
color: white;
padding: 8px;
font-size: 15px;
border-radius: 4px 4px 0 0;
text-shadow: 0 0 2px black;
background-image: linear-gradient(90deg,transparent 50%,rgba(0,0,0,.07) 0);
background-size: 4px;
}
#wh-city-finder-cont{
background: #616161;
padding: 8px;
color: #c7c7c7;
border-radius: 0 0 4px 4px;
font-size: 13px;
}
#wh-city-finder-cont span{
margin:2px 4px 2px 0;
padding:2px;
border-radius:2px;
background:green;
color:white;
display:inline-block;
}
`);
// 物品名与价格
let items = null;
const base = document.createElement('div');
base.id = 'wh-city-finder';
const container = document.createElement('div');
container.id = 'wh-city-finder-cont';
const header = document.createElement('div');
header.id = 'wh-city-finder-header';
header.innerHTML = '捡垃圾助手';
const info = document.createElement('div');
info.innerHTML = '已找到物品:';
container.append(info);
base.append(header);
base.append(container);
COFetch('https://jjins.github.io/item_price_raw.json')
.then(r => items = JSON.parse(r))
.catch(err => {
log.info(err)
items = undefined
});
elementReady('div.leaflet-marker-pane').then(elem => {
document.querySelector('#map').classList.add('wh-city-finds');
document.querySelector('.content-wrapper').prepend(base);
// 发现的物品id与map img node
const founds = [];
elem.querySelectorAll('img.map-user-item-icon').forEach(node => {
const item_id = node.src.split('/')[5];
const finder_item = document.createElement('span');
finder_item.id = 'wh-city-finder-item' + item_id;
finder_item.innerHTML = item_id;
founds.push({ 'id': item_id, 'node': finder_item, 'map_item': node });
container.append(finder_item);
});
// 未发现物品 返回
if (founds.length === 0) {
// header.innerHTML = '捡垃圾助手';
info.innerHTML = '空空如也,请大佬明天再来';
return;
}
// 将id显示为物品名与价格的函数
const displayNamePrice = () => {
// 总价
let total = 0;
founds.forEach(el => {
const value = items[el.id]['price'];
el.node.innerHTML = `<img src="${ el.map_item.src }" alt="" />${ items[el.id]['name'] } ($${ toThousands(value) })`;
// 灰色 100k以下
if (value < 100000) el.node.style.backgroundColor = '#9e9e9e';
// 绿色 1m以下
else if (value < 1000000) el.node.style.backgroundColor = '#4caf50';
// 蓝色 25m以下
else if (value < 25000000) el.node.style.backgroundColor = '#03a9f4';
// 橙色 500m以下
else if (value < 500000000) el.node.style.backgroundColor = '#ffc107';
// 红色 >500m
else if (value >= 500000000) el.node.style.backgroundColor = '#f44336';
total += items[el.id]['price'];
});
header.innerHTML = `捡垃圾助手 - ${ founds.length } 个物品,总价值 $${ toThousands(total) }`;
};
// 未取到数据时添加循环来调用函数
if (items === null) {
// 15s超时
let timeout = 30;
const interval = window.setInterval(() => {
timeout--;
if (items !== null) {
displayNamePrice();
clearInterval(interval);
}
if (0 === timeout) {
log.info('获取物品名称与价格信息超时')
clearInterval(interval)
}
}, 500);
}
// 无法跨域获取数据时
else if (items === undefined) {
info.innerHTML += '(当前平台暂不支持查询价格)';
}
// 调用函数
else {
displayNamePrice();
}
})
}

View File

@ -3,10 +3,11 @@ import { missionDict } from "../../dictionary/translation";
/** /**
* *
*/ */
function getTaskHint(task_name): string { export default function getTaskHint(task_name): string {
task_name = task_name task_name = task_name
.toLowerCase() .toLowerCase()
.replaceAll(' ', '_') .replaceAll(' ', '_')
.replaceAll('!', '')
.replaceAll('-', '_') .replaceAll('-', '_')
.replaceAll(',', ''); .replaceAll(',', '');
if (!missionDict._taskHint[task_name]) return '暂无,请联系开发者'; if (!missionDict._taskHint[task_name]) return '暂无,请联系开发者';

View File

@ -1,6 +1,7 @@
// mini profile 翻译
import playerStatusTrans from "./playerStatusTrans"; import playerStatusTrans from "./playerStatusTrans";
import sendCashTrans from "./sendCashTrans";
// mini profile 翻译
function miniprofTrans() { function miniprofTrans() {
// 迷你资料卡状态 // 迷你资料卡状态
playerStatusTrans($('div.profile-mini-root div.description span')); playerStatusTrans($('div.profile-mini-root div.description span'));

View File

@ -3,7 +3,7 @@ import { sendCashDict } from "../../dictionary/translation";
/** /**
* *
*/ */
function sendCashTrans(domPath = '', buttonClass = '.send-cash') { export default function sendCashTrans(domPath = '', buttonClass = '.send-cash') {
const sc = $(`${ domPath } ${ buttonClass } *`); const sc = $(`${ domPath } ${ buttonClass } *`);
if (sc.length === 0) return; if (sc.length === 0) return;
sc.contents().each((i, e) => { sc.contents().each((i, e) => {
@ -21,6 +21,4 @@ function sendCashTrans(domPath = '', buttonClass = '.send-cash') {
} }
} }
}); });
} }
export default sendCashDict

View File

@ -1,5 +1,5 @@
// 插件的配置 getter // 插件的配置 getter
export default function getWhSettingObj (): WHSettings { export default function getWhSettingObj(): WHSettings {
return JSON.parse(localStorage.getItem('wh_trans_settings')) || {} return JSON.parse(localStorage.getItem('wh_trans_settings')) || {}
} }

View File

@ -0,0 +1,130 @@
// 引入torn miniprofile
function initMiniProf(selector) {
let profileMini = {
timeout: 0,
clickable: false,
rootElement: null,
targetElement: null,
rootId: 'profile-mini-root',
rootSelector: '#profile-mini-root',
userNameSelector: "a[href*='profiles.php?XID=']",
// contentWrapper: '#wh-trans-icon',
contentWrapper: selector,
setClickable: function (value) {
this.clickable = value
},
setRootElement: function () {
if (!document.getElementById(this.rootId)) {
this.rootElement = document.createElement('div');
this.rootElement.classList.add(this.rootId);
this.rootElement.id = this.rootId;
$('body').append(this.rootElement);
} else {
window.ReactDOM.unmountComponentAtNode($(this.rootSelector).get(0));
this.rootElement = document.getElementById(this.rootId);
}
},
subscribeForHideListeners: function () {
const that = this;
let width = $(window).width();
function handleResize(e) {
if ($(this).width() !== width) {
width = $(this).width();
hideMiniProfile.call(that, e);
}
}
function handleScroll(e) {
if (!document.activeElement.classList.contains('send-cash-input')) {
hideMiniProfile.call(that, e);
}
}
function hideMiniProfile(e) {
if ($(e.target).closest(this.rootSelector).length === 0 || ['resize', 'scroll'].includes(e.type)) {
that.targetElement = null
window.ReactDOM.unmountComponentAtNode($(this.rootSelector).get(0));
$(this.userNameSelector).off('click', this.handleUserNameClick);
$(this.userNameSelector).unbind('contextmenu');
$(document).off('click', hideMiniProfile);
$(window).off('hashchange', hideMiniProfile);
$(window).off('resize', handleResize);
$(window).off('scroll', handleScroll);
}
}
$(document).on('click', hideMiniProfile.bind(this));
$(window).on('hashchange', hideMiniProfile.bind(this));
$(window).on('resize', handleResize);
if (that.targetElement.closest('#chatRoot')) {
$(window).on('scroll', handleScroll);
}
},
subscribeForUserNameClick: function () {
$(this.userNameSelector).click(this.handleUserNameClick.bind(this))
},
handleUserNameClick: function () {
if (!this.clickable) {
this.setClickable(true);
return false;
}
},
subscribeForContextMenu: function (element) {
$(element).on('contextmenu', function (e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return false;
})
},
handleMouseDown: function () {
const that = this;
$(this.contentWrapper).on('mousedown touchstart', this.userNameSelector, function (e) {
if (e.which !== 1 && e.type !== 'touchstart') {
return false;
}
that.targetElement = e.currentTarget;
that.subscribeForContextMenu(that.targetElement);
that.handleFocusLost(e.currentTarget);
that.timeout = setTimeout(function () {
if (e.type !== 'touchstart') {
that.setClickable(false);
that.subscribeForUserNameClick();
} else {
$(e.currentTarget).off('touchmove mouseleave');
}
that.subscribeForHideListeners();
that.setRootElement();
const userID = e.currentTarget.search.slice('?XID='.length);
const props = {
userID: userID,
event: e.originalEvent
};
window.renderMiniProfile(that.rootElement, props);
}, 500);
if (e.type !== 'touchstart') {
return false;
}
})
},
handleMouseUp: function () {
const that = this;
$(this.contentWrapper).on('mouseup touchend', this.userNameSelector, function () {
that.timeout && clearTimeout(that.timeout);
})
},
handleFocusLost: function (element) {
const that = this;
$(element).on('touchmove mouseleave', function unsubscribe() {
that.timeout && clearTimeout(that.timeout);
$(this).off('touchmove mouseleave', unsubscribe)
})
},
init: function () {
this.handleMouseDown();
this.handleMouseUp();
}
};
profileMini.init();
}

View File

@ -1,4 +1,3 @@
// console.log改写
import getWhSettingObj from "./getWhSettingObj"; import getWhSettingObj from "./getWhSettingObj";
function debug() { function debug() {
@ -10,10 +9,10 @@ function debug() {
} }
} }
const log = (...o) => (debug()) && (console.log('[WH]', ...o)) const log = {
error: (...o) => (debug()) && (console.error('[WH]', ...o)),
log.error = (...o) => (debug()) && (console.error('[WH]', ...o)) info: (...o) => (debug()) && (console.log('[WH]', ...o)),
log.info = (...o) => (debug()) && (console.log('[WH]', ...o)) debug,
log.debug = debug; }
export default log export default log

View File

@ -1,9 +1,9 @@
import userscript from "./userscript";
import zhongIcon from "./zhongIcon"; import zhongIcon from "./zhongIcon";
import init from "./init"; import init from "./init";
import getWhSettingObj from "./func/utils/getWhSettingObj"; import getWhSettingObj from "./func/utils/getWhSettingObj";
import translateMain from "./func/translate/translateMain"; import translateMain from "./func/translate/translateMain";
import WHNext from "./WHNext"; import common from "./common";
import urlMatch from "./urlMatch";
(function main() { (function main() {
let started = new Date().getTime(); let started = new Date().getTime();
@ -16,11 +16,11 @@ import WHNext from "./WHNext";
if (getWhSettingObj()['transEnable']) translateMain(glob.href); if (getWhSettingObj()['transEnable']) translateMain(glob.href);
WHNext(glob); common(glob);
userscript(); urlMatch(glob).then();
let runTime = new Date().getTime() - started; let runTime = new Date().getTime() - started;
glob.$zhongNode.initTimer.innerHTML = `助手加载时间 ${ runTime }ms`; glob.$zhongNode.initTimer.innerHTML = `助手加载时间 ${ runTime }ms`;
}) })
(); ();

View File

@ -1,152 +1,23 @@
import { import Global from "./interface/GlobalVars";
cityDict, import getWhSettingObj from "./func/utils/getWhSettingObj";
eventsDict, import cityFinder from "./func/module/cityFinder";
gymList, import WHNotify from "./func/utils/WHNotify";
missionDict, import elementReady from "./func/utils/elementReady";
ocList, import setWhSetting from "./func/utils/setWhSetting";
titleDict, import log from "./func/utils/log";
titleLinksDict, import { missionDict } from "./dictionary/translation";
} from './dictionary/translation'; import getTaskHint from "./func/translate/getTaskHint";
import Device from "./enum/Device";
import getPlayerInfo from "./func/utils/getPlayerInfo"; import getPlayerInfo from "./func/utils/getPlayerInfo";
import Device from "./enum/Device";
import getSidebarData from "./func/utils/getSidebarData";
import getDeviceType from "./func/utils/getDeviceType";
import addStyle from "./func/utils/addStyle";
export default function userscript(): void { export default async function urlMatch(glob: Global) {
let { version, isIframe, PDA_APIKey, isPDA, player_info, fstock, notifies } = window.WHPARAMS; let { href, beer, isIframe } = glob;
// 捡垃圾助手 // 捡垃圾助手
if (getWhSettingObj()['cityFinder'] && href.includes('city.php')) { if (href.includes('city.php') && getWhSettingObj()['cityFinder']) {
addStyle(` cityFinder();
.wh-city-finds .leaflet-marker-pane img[src*="torn.com/images/items/"]{
display: block !important;
box-sizing: border-box;
width: 40px !important;
height: 40px !important;
left: -20px !important;
top: -20px !important;
padding: 10px 0;
border: none;
border-radius: 100%;
background-color:#d2d2d28c;
box-shadow:0 0 10px 5px #000;
z-index: 999 !important;
}
.wh-city-finds .leaflet-marker-pane.leaflet-marker-icon.user-item-pinpoint.leaflet-clickable{display: none !important;}
#wh-city-finder{
box-shadow: 0 0 3px 0px #696969;
border-radius: 4px;
}
#wh-city-finder-header{
background-color: #3f51b5;
color: white;
padding: 8px;
font-size: 15px;
border-radius: 4px 4px 0 0;
text-shadow: 0 0 2px black;
background-image: linear-gradient(90deg,transparent 50%,rgba(0,0,0,.07) 0);
background-size: 4px;
}
#wh-city-finder-cont{
background: #616161;
padding: 8px;
color: #c7c7c7;
border-radius: 0 0 4px 4px;
font-size: 13px;
}
#wh-city-finder-cont span{
margin:2px 4px 2px 0;
padding:2px;
border-radius:2px;
background:green;
color:white;
display:inline-block;
}
`);
// 物品名与价格
let items = null;
const base = document.createElement('div');
base.id = 'wh-city-finder';
const container = document.createElement('div');
container.id = 'wh-city-finder-cont';
const header = document.createElement('div');
header.id = 'wh-city-finder-header';
header.innerHTML = '捡垃圾助手';
const info = document.createElement('div');
info.innerHTML = '已找到物品:';
container.append(info);
base.append(header);
base.append(container);
COFetch('https://jjins.github.io/item_price_raw.json')
.catch(err => {
log(err)
items = undefined
})
.then(r => items = JSON.parse(r));
elementReady('div.leaflet-marker-pane').then(elem => {
document.querySelector('#map').classList.add('wh-city-finds');
document.querySelector('.content-wrapper').prepend(base);
// 发现的物品id与map img node
const founds = [];
elem.querySelectorAll('img.map-user-item-icon').forEach(node => {
const item_id = node.src.split('/')[5];
const finder_item = document.createElement('span');
finder_item.id = 'wh-city-finder-item' + item_id;
finder_item.innerHTML = item_id;
founds.push({ 'id': item_id, 'node': finder_item, 'map_item': node });
container.append(finder_item);
});
// 未发现物品 返回
if (founds.length === 0) {
// header.innerHTML = '捡垃圾助手';
info.innerHTML = '空空如也,请大佬明天再来';
return;
}
// 将id显示为物品名与价格的函数
const displayNamePrice = () => {
// 总价
let total = 0;
founds.forEach(el => {
const value = items[el.id]['price'];
el.node.innerHTML = `<img src="${ el.map_item.src }" alt="" />${ items[el.id]['name'] } ($${ toThousands(value) })`;
// 灰色 100k以下
if (value < 100000) el.node.style.backgroundColor = '#9e9e9e';
// 绿色 1m以下
else if (value < 1000000) el.node.style.backgroundColor = '#4caf50';
// 蓝色 25m以下
else if (value < 25000000) el.node.style.backgroundColor = '#03a9f4';
// 橙色 500m以下
else if (value < 500000000) el.node.style.backgroundColor = '#ffc107';
// 红色 >500m
else if (value >= 500000000) el.node.style.backgroundColor = '#f44336';
total += items[el.id]['price'];
});
header.innerHTML = `捡垃圾助手 - ${ founds.length } 个物品,总价值 $${ toThousands(total) }`;
};
// 未取到数据时添加循环来调用函数
if (items === null) {
// 15s超时
let timeout = 30;
const interval = window.setInterval(() => {
timeout--;
if (items !== null) {
displayNamePrice();
clearInterval(interval);
}
if (0 === timeout) {
log('获取物品名称与价格信息超时')
clearInterval(interval)
}
}, 500);
}
// 无法跨域获取数据时
else if (items === undefined) {
info.innerHTML += '(当前平台暂不支持查询价格)';
}
// 调用函数
else {
displayNamePrice();
}
})
} }
// pt一键购买 // pt一键购买
@ -167,9 +38,10 @@ display:inline-block;
} }
new MutationObserver(e => { new MutationObserver(e => {
for (const t of e) { for (const t of e) {
for (const e of t.addedNodes) { // for (const e of t.addedNodes) {
'LI' === e.tagName && rmv_cfm(e) // 'LI' === e.tagName && rmv_cfm(e)
} // }
t.addedNodes.forEach(e => 'LI' === (e as HTMLElement).tagName && rmv_cfm(e))
} }
}).observe(points_sales, { childList: true }); }).observe(points_sales, { childList: true });
} }
@ -181,8 +53,9 @@ display:inline-block;
switch_node.innerHTML = `<label><input type="checkbox" ${ getWhSettingObj()['SEProtect'] ? 'checked' : '' }/> 叠E保护</label>`; switch_node.innerHTML = `<label><input type="checkbox" ${ getWhSettingObj()['SEProtect'] ? 'checked' : '' }/> 叠E保护</label>`;
switch_node.id = 'wh-gym-info-cont'; switch_node.id = 'wh-gym-info-cont';
switch_node.querySelector('input').onchange = e => { switch_node.querySelector('input').onchange = e => {
let target = e.target as HTMLInputElement;
cont.classList.toggle('wh-display-none'); cont.classList.toggle('wh-display-none');
setWhSetting('SEProtect', e.target.checked); setWhSetting('SEProtect', target.checked);
}; };
elementReady('#gymroot').then(node => { elementReady('#gymroot').then(node => {
cont = node; cont = node;
@ -277,14 +150,14 @@ $<span class="total">1,000</span>
</div>`; </div>`;
if (clear_node) clear_node.before(beer); if (clear_node) clear_node.before(beer);
else node.append(beer); else node.append(beer);
e.target.remove(); (<MyHTMLElement>e.target).remove();
msg_node.innerHTML = '添加成功'; msg_node.innerHTML = '添加成功';
}); });
document.querySelector('.content-wrapper').prepend(add_btn_node); document.querySelector('.content-wrapper').prepend(add_btn_node);
}); });
// 监听啤酒购买 // 监听啤酒购买
$(document).ajaxComplete((_, xhr, settings) => { $(document).ajaxComplete((_, xhr, settings) => {
log({ xhr, settings }); log.info({ xhr, settings });
let { data } = settings, { responseText } = xhr; let { data } = settings, { responseText } = xhr;
let response = JSON.parse(responseText); let response = JSON.parse(responseText);
if (data.includes('step=buyShopItem') && data.includes('ID=180') && response['success']) { if (data.includes('step=buyShopItem') && data.includes('ID=180') && response['success']) {
@ -294,7 +167,7 @@ $<span class="total">1,000</span>
}); });
} }
// 快速crime // 快速crime TODO 重构、与翻译解藕
if (href.contains(/crimes\.php/) && getWhSettingObj()['quickCrime']) { if (href.contains(/crimes\.php/) && getWhSettingObj()['quickCrime']) {
if (isIframe) { if (isIframe) {
const isValidate = document.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate'); const isValidate = document.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate');
@ -312,8 +185,8 @@ $<span class="total">1,000</span>
const $$ = document.querySelector('.content-wrapper'); const $$ = document.querySelector('.content-wrapper');
const OB = new MutationObserver(() => { const OB = new MutationObserver(() => {
OB.disconnect(); OB.disconnect();
titleTrans(); // titleTrans();
contentTitleLinksTrans(); // contentTitleLinksTrans();
trans(); trans();
OB.observe($$, { OB.observe($$, {
characterData: true, characterData: true,
@ -385,13 +258,13 @@ $<span class="total">1,000</span>
}); });
} }
// 任务助手 // 任务助手 TODO 重构、与翻译解藕
if (href.contains(/loader\.php\?sid=missions/) && getWhSettingObj()['missionHint']) { if (href.contains(/loader\.php\?sid=missions/) && getWhSettingObj()['missionHint']) {
const $$ = $('.content-wrapper'); const $$ = $('.content-wrapper');
const OB = new MutationObserver(() => { const OB = new MutationObserver(() => {
OB.disconnect(); OB.disconnect();
titleTrans(); // titleTrans();
contentTitleLinksTrans(); // contentTitleLinksTrans();
trans(); trans();
OB.observe($$.get(0), { OB.observe($$.get(0), {
characterData: true, characterData: true,
@ -431,7 +304,6 @@ $<span class="total">1,000</span>
childList: true childList: true
}); });
} }
// 圣诞小镇 // 圣诞小镇
if (href.contains(/christmas_town\.php/)) { if (href.contains(/christmas_town\.php/)) {
let $root = document.querySelector('#christmastownroot'); let $root = document.querySelector('#christmastownroot');
@ -810,40 +682,42 @@ margin: 0 0 3px;
} }
</style>`; </style>`;
$($ct_wrap).before(insert_html); $($ct_wrap).before(insert_html);
const $wh_loot_container = $root.querySelector('#wh-loot-container'); const $wh_loot_container = $root.querySelector('#wh-loot-container') as HTMLElement;
const $btn = $wh_loot_container.querySelector('#wh-loot-btn button'); const $btn = $wh_loot_container.querySelector('#wh-loot-btn button') as HTMLButtonElement;
const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button'); const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button') as HTMLButtonElement;
const $ex = $wh_loot_container.querySelector('#wh-loot-container-ex'); const $ex = $wh_loot_container.querySelector('#wh-loot-container-ex');
const $tbody = $wh_loot_container.querySelector('tbody'); const $tbody = $wh_loot_container.querySelector('tbody');
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink'); const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink') as HTMLInputElement;
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound'); const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound') as HTMLInputElement;
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest'); const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest') as HTMLInputElement;
const $audio = $wh_loot_container.querySelector('audio'); const $audio = $wh_loot_container.querySelector('audio');
$btn.onclick = e => { $btn.onclick = e => {
e.target.innerText = e.target.innerText === '设置' ? '收起' : '设置'; let target = e.target as HTMLButtonElement;
target.innerText = target.innerText === '设置' ? '收起' : '设置';
$($ex).toggleClass('wh-hide'); $($ex).toggleClass('wh-hide');
e.target.blur(); target.blur();
}; };
$clear_btn.onclick = e => { $clear_btn.onclick = e => {
e.target.blur(); let target = e.target as HTMLButtonElement;
target.blur();
dropHist = {}; dropHist = {};
$tbody.innerHTML = ''; $tbody.innerHTML = '';
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist)); localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
}; };
$blink.onchange = e => { $blink.onchange = e => {
if (e.target.checked) { if ((<HTMLInputElement>e.target).checked) {
alertSettings.blink = 'y'; alertSettings.blink = 'y';
if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') { if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') {
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; (<HTMLElement>$wh_loot_container.querySelector('#wh-loot-container-main')).style.animation = 'lootFoundAlert 2s infinite';
} }
} else { } else {
alertSettings.blink = 'n'; alertSettings.blink = 'n';
$wh_loot_container.querySelector('#wh-loot-container-main').style.animation = ''; (<HTMLElement>$wh_loot_container.querySelector('#wh-loot-container-main')).style.animation = '';
} }
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
}; };
$sound.onchange = e => { $sound.onchange = e => {
if (e.target.checked) { if ((<HTMLInputElement>e.target).checked) {
alertSettings.sound = 'y'; alertSettings.sound = 'y';
if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') { if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') {
soundLoopFlag = true; soundLoopFlag = true;
@ -855,7 +729,7 @@ margin: 0 0 3px;
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
}; };
$chest.onchange = e => { $chest.onchange = e => {
alertSettings.chest = e.target.checked ? 'y' : 'n'; alertSettings.chest = (<HTMLInputElement>e.target).checked ? 'y' : 'n';
localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings));
}; };
const soundIntervalID = window.setInterval(() => { const soundIntervalID = window.setInterval(() => {
@ -880,26 +754,29 @@ margin: 0 0 3px;
return; return;
} }
const $pos_spl = $pos.innerText.trim().split(','); const $pos_spl = $pos.innerText.trim().split(',');
const player_position = {}; const player_position = {
player_position.x = parseInt($pos_spl[0]); x: parseInt($pos_spl[0]),
player_position.y = parseInt($pos_spl[1]); y: parseInt($pos_spl[1]),
};
// player_position.x = parseInt($pos_spl[0]);
// player_position.y = parseInt($pos_spl[1]);
const $wh_loot_container = $root.querySelector('#wh-loot-container'); const $wh_loot_container = $root.querySelector('#wh-loot-container');
if (!$wh_loot_container) { if (!$wh_loot_container) {
console.error('掉落助手未找到DOM容器'); console.error('掉落助手未找到DOM容器');
ob.observe($root, { childList: true, subtree: true }); ob.observe($root, { childList: true, subtree: true });
return; return;
} }
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink'); const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink') as HTMLInputElement;
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound'); const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound') as HTMLInputElement;
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest'); const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest') as HTMLInputElement;
const $tbody = $wh_loot_container.querySelector('tbody'); const $tbody = $wh_loot_container.querySelector('tbody');
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');
// 附近的所有物品 // 附近的所有物品
items.forEach(el => { items.forEach(el => {
const item_props = { x: 0, y: 0, name: '', type: '', url: '', }; const item_props = { x: 0, y: 0, name: '', type: '', url: '', };
item_props.x = parseInt(el.style.left.replaceAll('px', '')) / 30; item_props.x = parseInt((<HTMLElement>el).style.left.replaceAll('px', '')) / 30;
item_props.y = -parseInt(el.style.top.replaceAll('px', '')) / 30; item_props.y = -parseInt((<HTMLElement>el).style.top.replaceAll('px', '')) / 30;
item_props.url = el.firstElementChild.src; item_props.url = el.firstElementChild.src;
const srcSpl = item_props.url.trim().split('/'); const srcSpl = item_props.url.trim().split('/');
item_props.name = srcSpl[6]; item_props.name = srcSpl[6];
@ -956,10 +833,10 @@ margin: 0 0 3px;
$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 = ''; (<HTMLElement>$wh_loot_container.querySelector('#wh-loot-container-main')).style.animation = '';
soundLoopFlag = false; soundLoopFlag = false;
} else { } else {
if ($blink.checked) $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; if ($blink.checked) (<HTMLElement>$wh_loot_container.querySelector('#wh-loot-container-main')).style.animation = 'lootFoundAlert 2s infinite';
if ($sound.checked) soundLoopFlag = true; 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 })`;
@ -1040,158 +917,21 @@ margin: 0 0 3px;
await rw_raider(); await rw_raider();
} }
// 特定代码块
if (getPlayerInfo()['userID'] === 2687093 && getDeviceType() === Device.PC) { if (getPlayerInfo()['userID'] === 2687093 && getDeviceType() === Device.PC) {
await getSidebarData(); await getSidebarData();
let item = document.getElementById('nav-items'); let item = document.getElementById('nav-items');
if (item) { if (item) {
let copy = item.cloneNode(true); let copy = item.cloneNode(true);
copy.firstChild.style.backgroundColor = '#ff5722'; // TODO 待验证
let a = copy.firstChild.firstChild; (<HTMLElement>copy.firstChild).style.backgroundColor = '#ff5722';
// copy.firstChild.style.backgroundColor = '#ff5722';
let a = copy.firstChild.firstChild as HTMLAnchorElement;
a.href = '/item.php?temp=1'; a.href = '/item.php?temp=1';
let span = a.lastChild; let span = a.lastChild as HTMLElement;
span.innerHTML = '物品'; span.innerHTML = '物品';
span.style.color = 'white'; span.style.color = 'white';
item.after(copy); item.after(copy);
} }
} }
// mini profile 翻译
function miniprofTrans() {
// 迷你资料卡状态
playerStatusTrans($('div.profile-mini-root div.description span'));
// 转钱
sendCashTrans('div.profile-mini-root');
}
// 引入torn miniprofile
function initMiniProf(selector) {
let profileMini = {
timeout: 0,
clickable: false,
rootElement: null,
targetElement: null,
rootId: 'profile-mini-root',
rootSelector: '#profile-mini-root',
userNameSelector: "a[href*='profiles.php?XID=']",
// contentWrapper: '#wh-trans-icon',
contentWrapper: selector,
setClickable: function (value) {
this.clickable = value
},
setRootElement: function () {
if (!document.getElementById(this.rootId)) {
this.rootElement = document.createElement('div');
this.rootElement.classList.add(this.rootId);
this.rootElement.id = this.rootId;
$('body').append(this.rootElement);
} else {
ReactDOM.unmountComponentAtNode($(this.rootSelector).get(0));
this.rootElement = document.getElementById(this.rootId);
}
},
subscribeForHideListeners: function () {
const that = this;
let width = $(window).width();
function handleResize(e) {
if ($(this).width() !== width) {
width = $(this).width();
hideMiniProfile.call(that, e);
}
}
function handleScroll(e) {
if (!document.activeElement.classList.contains('send-cash-input')) {
hideMiniProfile.call(that, e);
}
}
function hideMiniProfile(e) {
if ($(e.target).closest(this.rootSelector).length === 0 || ['resize', 'scroll'].includes(e.type)) {
that.targetElement = null
ReactDOM.unmountComponentAtNode($(this.rootSelector).get(0));
$(this.userNameSelector).off('click', this.handleUserNameClick);
$(this.userNameSelector).unbind('contextmenu');
$(document).off('click', hideMiniProfile);
$(window).off('hashchange', hideMiniProfile);
$(window).off('resize', handleResize);
$(window).off('scroll', handleScroll);
}
}
$(document).on('click', hideMiniProfile.bind(this));
$(window).on('hashchange', hideMiniProfile.bind(this));
$(window).on('resize', handleResize);
if (that.targetElement.closest('#chatRoot')) {
$(window).on('scroll', handleScroll);
}
},
subscribeForUserNameClick: function () {
$(this.userNameSelector).click(this.handleUserNameClick.bind(this))
},
handleUserNameClick: function () {
if (!this.clickable) {
this.setClickable(true);
return false;
}
},
subscribeForContextMenu: function (element) {
$(element).on('contextmenu', function (e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return false;
})
},
handleMouseDown: function () {
const that = this;
$(this.contentWrapper).on('mousedown touchstart', this.userNameSelector, function (e) {
if (e.which !== 1 && e.type !== 'touchstart') {
return false;
}
that.targetElement = e.currentTarget;
that.subscribeForContextMenu(that.targetElement);
that.handleFocusLost(e.currentTarget);
that.timeout = setTimeout(function () {
if (e.type !== 'touchstart') {
that.setClickable(false);
that.subscribeForUserNameClick();
} else {
$(e.currentTarget).off('touchmove mouseleave');
}
that.subscribeForHideListeners();
that.setRootElement();
const userID = e.currentTarget.search.slice('?XID='.length);
const props = {
userID: userID,
event: e.originalEvent
};
window.renderMiniProfile(that.rootElement, props);
}, 500);
if (e.type !== 'touchstart') {
return false;
}
})
},
handleMouseUp: function () {
const that = this;
$(this.contentWrapper).on('mouseup touchend', this.userNameSelector, function () {
that.timeout && clearTimeout(that.timeout);
})
},
handleFocusLost: function (element) {
const that = this;
$(element).on('touchmove mouseleave', function unsubscribe() {
that.timeout && clearTimeout(that.timeout);
$(this).off('touchmove mouseleave', unsubscribe)
})
},
init: function () {
this.handleMouseDown();
this.handleMouseUp();
}
};
profileMini.init();
}
} }