import getWhSettingObj from "./func/utils/getWhSettingObj";
import cityFinder from "./func/module/cityFinder";
import elementReady from "./func/utils/elementReady";
import { missionDict } from "./dictionary/translation";
import getTaskHint from "./func/translate/getTaskHint";
import Device from "./enum/Device";
import WuhuBase from "./class/WuhuBase";
import Utils from "./class/utils/Utils";
import Log from "./class/Log";
import WuhuConfig from "./class/WuhuConfig";
import Alert from "./class/utils/Alert";
import InfoUtils from "./class/utils/InfoUtils";
export default class UrlPattern extends WuhuBase {
constructor() {
super();
}
static resolve() {
let { href, beer } = UrlPattern.glob;
// 捡垃圾助手
if (href.includes('city.php') && getWhSettingObj()['cityFinder']) {
cityFinder();
}
// pt一键购买
if (WuhuConfig.get('ptQuickBuy') && href.includes('pmarket.php')) {
new Alert('一键购买已开启');
// ns脚本
const rmv_cfm = (e) => {
let el = e.firstElementChild;
el.className += ' yes';
let old_href = el.getAttribute('href');
let new_href = old_href.replace(/=buy/, '=buy1').replace(/&points=\d{1,9}$/, '');
el.setAttribute('href', new_href);
};
let points_sales = document.querySelector('.users-point-sell');
for (const index in points_sales.children) {
'LI' === points_sales.children[index].tagName && rmv_cfm(points_sales.children[index])
}
new MutationObserver(e => {
for (const t of e) {
// for (const e of t.addedNodes) {
// 'LI' === e.tagName && rmv_cfm(e)
// }
t.addedNodes.forEach(e => 'LI' === (e as HTMLElement).tagName && rmv_cfm(e))
}
}).observe(points_sales, { childList: true });
}
// 叠e助手
if (href.includes('gym.php')) {
let cont = null;
const switch_node = document.createElement('div');
switch_node.innerHTML = ``;
switch_node.id = 'wh-gym-info-cont';
switch_node.querySelector('input').onchange = e => {
let target = e.target as HTMLInputElement;
cont.classList.toggle('wh-display-none');
WuhuConfig.set('SEProtect', target.checked, true);
};
Utils.elementReady('#gymroot').then(node => {
cont = node;
if (getWhSettingObj()['SEProtect']) node.classList.add('wh-display-none');
node.before(switch_node);
});
}
// 啤酒店
if (href.includes('shops.php?step=bitsnbobs')) {
// 加入啤酒
elementReady('ul.items-list').then(node => {
const add_btn_node = document.createElement('div');
add_btn_node.id = 'wh-gym-info-cont';
add_btn_node.innerHTML = `
如果当前商店没有啤酒这个商品可以提前显示以省去刷新步骤,增加抢酒成功率。
`;
add_btn_node.querySelector('button').addEventListener('click', e => {
const msg_node = add_btn_node.querySelector('#wh-msg');
if (node.querySelector('span[id="180-name"]')) {
msg_node.innerHTML = '❌ 页面已经有啤酒了';
return;
}
const clear_node = node.querySelector('li.clear');
const beer = document.createElement('li');
beer.classList.add('torn-divider', 'divider-vertical');
beer.style.backgroundColor = '#c8c8c8';
beer.innerHTML = `
啤酒
$10
酒 (1100存货)
点击确定购买
100
瓶啤酒
$1,000
确定
不
`;
if (clear_node) clear_node.before(beer);
else node.append(beer);
(e.target).remove();
msg_node.innerHTML = '添加成功';
});
document.querySelector('.content-wrapper').prepend(add_btn_node);
});
// 监听啤酒购买
$(document).ajaxComplete((_, xhr, settings) => {
Log.info({ xhr, settings });
let { data } = settings, { responseText } = xhr;
let response = JSON.parse(responseText);
if (data.includes('step=buyShopItem') && data.includes('ID=180') && response['success']) {
new Alert('已检测成功购买啤酒')
beer.skip_today();
}
});
}
// 快速crime TODO 重构、与翻译解藕
if (href.contains(/crimes\.php/) && getWhSettingObj()['quickCrime']) {
if (self !== top) {
const isValidate = document.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate');
elementReady('#header-root').then(e => e.style.display = 'none');
elementReady('#sidebarroot').then(e => e.style.display = 'none');
elementReady('#chatRoot').then(e => e.style.display = 'none');
if (!isValidate) document.body.style.overflow = 'hidden';
elementReady('.content-wrapper').then(e => {
e.style.margin = '0px';
e.style.position = 'absolute';
e.style.top = '-35px';
});
elementReady('#go-to-top-btn button').then(e => e.style.display = 'none');
}
const $$ = document.querySelector('.content-wrapper');
const OB = new MutationObserver(() => {
OB.disconnect();
// titleTrans();
// contentTitleLinksTrans();
trans();
OB.observe($$, {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
});
const trans = () => {
const dom = ``;
const is_wh_translate = $$.querySelector('.wh-translate') !== null;
const is_captcha = $$.querySelector('div#tab-menu.captcha') !== null;
const $title = $('div.content-title');
const $info = $('.info-msg-cont');
if (!is_wh_translate && !is_captcha) {
if ($title.length > 0) $title.before(dom);
else if ($info.length > 0) $info.before(dom);
}
};
trans();
OB.observe($$, {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
}
// 任务助手 TODO 重构、与翻译解藕
if (href.contains(/loader\.php\?sid=missions/) && getWhSettingObj()['missionHint']) {
const $$ = $('.content-wrapper');
const OB = new MutationObserver(() => {
OB.disconnect();
// titleTrans();
// contentTitleLinksTrans();
trans();
OB.observe($$.get(0), {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
});
const taskList = {};
const trans = () => {
$('ul#giver-tabs a.ui-tabs-anchor').each((i, e) => {
if ($(e).children().hasClass('mission-complete-icon')) {
taskList[i] = e.innerText.trim();
} else {
taskList[i] = $(e).clone().children().remove().end().text().trim();
}
});
// 助手注入
$('div.max-height-fix.info').each((i, e) => {
if ($(e).find('.wh-translated').length !== 0) return;
$(e).append(`任务助手
${ getTaskHint(taskList[i]) }
`);
});
// 任务目标
$('ul.tasks-list span.title-wrap').contents().each((i, e) => {
if (e.nodeType === 3) {
if (missionDict[e.nodeValue.trim()]) {
e.nodeValue = missionDict[e.nodeValue.trim()];
}
}
});
};
trans();
OB.observe($$.get(0), {
characterData: true,
attributes: true,
subtree: true,
childList: true
});
}
// 圣诞小镇
if (href.contains(/christmas_town\.php/)) {
let $root = document.querySelector('#christmastownroot');
const { xmasTownWT, xmasTownNotify } = getWhSettingObj()
// 解密攻略
if (xmasTownWT) {
const insert_html = `
水晶球解密地图攻略
来源:Torn City公众号,图文详情请查看公众号文章
`;
const wt_dict = {
"None": { title: '', wt: ``, },
"Christmas Town": {
title: '圣诞小镇', wt: `
- 旧攻略提到的驯鹿车已被移除,只能手动找一条蓝色的小路[94,3]
- 向南走,然后上木桥,沿着它向西走到达冰湖
- 在冰湖[55,7][61,64]附近找Labyrinth传送门进入迷宫
- 迷宫的出口在中间的方向[395,397]一个冰湖,走进冰湖传送
- 走到企鹅
`,
},
"Maltese Snow Globe": {
title: 'Maltese Snow Globe', wt: `
- 1.想办法进入前几层的楼梯口
- 2.出来之后往南走, 在码头找到天鹅船
- 3.按着数字1-12走过乐高博物馆
- 4.跟着大路走到天鹅船。
- 5.走到901,486的银行
- 6.最左上的楼梯
- 7.B-D-C-E-F-G-C-A
- 8.右,右,右,北,北,右,右
- 9.走到右上角铁路
- 10.小游戏:
- 移动1到最右,移动2到中间,移动1到2上面,移动3到最右,移动1到最左,移动2到3.上面,移动1到2上面。
- 11.往上走出铁丝网,往左绕一个大圈走到300,476
- 12.走到363,406的隧道,走到361,400的隧道 ,往南走。
- 13.走到352,334的迷宫,好像有好几条路,我说我的走法,往左下走,走倒最下了往右走,走到1个不一样的绿色的时候,往上走。
- 14.走到迷宫中间的小人,后面就只有一条路走了,完成。
`,
},
"Long way from home": {
title: 'Long way from home', wt: `
- 1.随便动一下
- 2.左边的管道口
- 3.右走到十字路口,往上,往右,从偏左的那个管道往上。
- 3.出小门,往右到底,往上到底,往右,进上面房间,右上角的电脑,电脑显示的是下面房间的走法,任意移动退出
- 4.去下面房间,右边橙色电力符号,进入解密。下,右下,右下,右上,右上,右,右下,右下,下,左下,左下,
- 左,左,左下,左下,进圈。
- 5.进入新的房间按钮
- 6.一直左走,走到有两个怪兽把手的桥那,进上面的房间,左上角的机器,*是重输密码
- 作者随时改密码,建议看纸条上的提示自己去数
- 7.桥上怪兽消失, 往左走到底,按钮
- 8.右走,走到雪地走大路,按钮开铁门,上darkforest的蓝车
- 9.右走十几步,传送
- 10.右下走,看到铁丝网,顺着铁丝网右走,有个缺口,进去。
- 11.右走,直到看见三颗倒下的圣诞树(记住这里),顺着血迹和脚印走,进山洞。
- 12.顺着山洞走到一滩血,原路出山洞。
- 13.原路回到三颗倒下的圣诞树,正上方有个红色仓库,进入。
- 14.上,上,上,右,上,左,上,路就通了,去拿到右上角的锯子,原路出仓库。
- 15.出来就在车下面,上车,再上车。
- 16.左边的小橘人,完成
`,
},
"Chedburn Towers": {
title: 'Chedburn Towers', wt: `
- 进入地图后,使用附近的FAST的T下方的厕所传送到Chedburn Towers
- 进入大厅,"之"字形上楼,每层都是如此。
- 最终会进入问答题区域,通过在相应的数字上穿过来回答问题
- 答案是:3 9 5 4 9 2 6 8
- 答题后,进入Ched的办公室,向西走,然后一直走到左边的楼梯上
- 向南走下楼梯,然后向东走,沿着小楼梯到地下室
- 向东走到牢房区域
- 先踩下开关,打开牢房门前往右上角的最后一个牢房
- 开关位于JAIL文字的左上方
- 沿着挖出来的隧道一直走,岔路口向左走
- 到金库,Chedburn NPC会给你本地图的水晶球
`,
},
"Kidnapped Santa": {
title: 'Kidnapped Santa', wt: `
- 出生在一个类似城镇的地方
- 沿着这条路向东走,然后向南走
- 到达道路尽头的一个码头时,向西走一段路,踩在精灵的上面,乘坐渡船[124, -30]
- 搭船来到了Fantasy Island
- 小心那个游荡的绿色NPC,不惜一切代价避开他,否则他会把你打回出发点
- 向西走,然后向北走,再向西绕过岩石。要非常小心,不要踩到水里或掉下悬崖,否则你会死
- 然后回到南边,在那里你会看到一些门
- 走进蓝色的门(左二)[111,-60]
- 过了蓝门后继续沿路向南
- 然后沿路向东,再向南
- 再向东走,会看到“恐怖之家”,进入这栋楼[137, -84]
- 向北走,进入洞口[164, -81]
- 穿过隧道到达另一端的洞穴口[142, -63],避开所有怪物和NPC
- 来到另一个岛上
- 向南走,然后向东绕过建筑物,可以进入圣诞老人的洞穴[133, -2]
- 在建筑物内向西走,再向北走,在圣诞老人家work shop的东北角,你会看到一个楼梯,走下去[169,4]
- 在这一区域,要避开所有出现破损或有异样的地砖,也要避开四处游荡的邪恶的格林奇NPC
- 沿着地牢里的走廊向东走,然后向南走,避开所有看起来不同的瓷砖
- 它们上面有一些小裂缝和花纹,如果你是用手机的话,我建议你把亮度调高,以防万一
- 最终会看到一个发绿光的小开关
- 走到开关上[165, 18],激活它,然后进入向北打开的大门
- 走到黄色精灵NPC脸上[166,25],可以得到本地图的水晶球
`,
},
"Holiday terror": {
title: 'Holiday terror', wt: `
- 1. 从出生地沿着路向东,然后向北。过桥并沿着穿过城镇的小路继续前行,避开任何明显的陷阱(道路上的洞、打开的井盖等)。
- 2. 继续向东和向北前进,直到到达 Mansion's Labyrinth(豪宅迷宫)[121,29]
- 3. 豪宅入口在[131,41]
- 4. 进入豪宅后向北走,你会看到一条由骷髅守卫的道路
- 5. 沿着棕色的小路走,在黑色的区域前停下
- 6. 按照如下的方式行进
- 上3格,左2,上2,右4,下1,右3,上6,左2,下1,左6,下2,左2,上4,右5,上4
- 7. 来到一个区域,在这里你必须在两个洞穴中做出选择
- 第一次选择,答案是Christmas Miracle,选择左边的洞窟。
- 第二次选择,答案是24/12/2019,选择左边的洞窟。
- 第三次选择,答案是Hohoho Coldington,选择右边的洞窟。
- 第四次选择,答案是Christmas Miracle Cave,选择左边的洞窟。
- 8. 出现在一个用糖果棒装饰的红色地板的房间里,去地图的右上角一个冰洞的入口[101,-74]
- 9. 进入冰洞。向西走,寻找叫Erik the last elf的黄色小NPC
- 10. 拿到水晶球
`,
},
"Among Us": {
title: 'Among Us', wt: `
- 出生点步行到传送点进入地图 1 [399,12]
- 到达地图1,你出现在食堂,往下走,绕到红色按钮处[502,-1]
- 答案:D B A A D D B B B C A D D D 最终: B (Green)
- 然后你会被传送到地图2
- 在地图2中,你需要沿着小路向南走,然后向东进入通风口,前往下一个部分[556,24]
- 穿过通风口后,进入食堂。向南走到红色按钮所在的位置 [571,32]
- 答题阶段,答案如下BBACBDC A
- 被传送到地图3
- 先直接向南走一点,再沿着走廊走。进入左边的一个通风口[345,170]
- 会传送到办公室,在那里找到最后一个红色按钮[356,173]
- 答题阶段,答案如下CCADABBCD
- 进入"PEEP SHOW",获得本地图的水晶球
`,
},
"Kiss My Festivus": {
title: 'Kiss My Festivus', wt: `
- 从起点出发,沿着小路向北走到出租车处,乘坐前往Dark Forest的出租车 [96,16]
- 沿着公路向东走,继续向东进入雪地
- 沿着暗淡的蓝色轨迹向东南方向走,穿过树林,直到你到达一个铁栅栏[坐标为114,-89]
- 铁栅栏进不去。有人会告诉你乘坐他们的雪地车。
- 向西走到雪地车旁,注意不要踩到任何冬青树(鲜艳黄红色的矮树),否则你将回到起点。
- 被传送到锯木厂,在伐木工那里获得钥匙。
- 然后向南走,然后向东走(向东走很长一段路),沿着小路返回铁栅栏处。
- 来到一个炫酷的45°视角迷宫,你要走到地图的东北部,抵达另一个洞穴口[156,-74]
- 先往左下方走到岔路口,然后往右上方走,接下来将只有一条路
- 到达岛屿沿着小楼梯上去,绕到正下方那艘天鹅船
- 到一个新的岛屿,向南走几步,踩在[12, -79]的蓝色火花上
- 被传送到另一个有几辆拖车的岛上
- 向北走,进入一个新的山洞口
- 人被挡住了,要在冰层下向西北方向一直走,主要是向上和向左走
- 沿着这条路一直往上走,然后在开阔的地方往东走,你会看到一座房子[房子的入口在26,58]
- 进入房子,向北走几步,穿过闪闪发光的入口,你就可以进入房子了
- 沿着东南方向走,你会看到Evil-Duck NPC,他将给你本地图的水晶球
`,
},
"Stanley Hotel": {
title: 'Stanley Hotel', wt: `
- 从起点开始,你会看到正北方有一座房子。向北走几步到门前,进入房子。
- 传送到一个有门的地方。绕过并向上走,激活位于[188,72]的大门开关。
- 向东北方向前进,沿着血迹穿过森林,直到你到达一个山洞。
- 依次使用使用防御(踩盾牌标记),然后攻击(剑),然后魔法(闪亮的蓝色气泡)来杀死怪物。
- 最后,你会来到工人Bob的房间,他将给你本地图的水晶球。
`,
},
"DoggoQuest": {
title: 'DoggoQuest', wt: `
- 你出现在一个房间里
- 向东走,然后向南走,沿着小走廊就可以离开这个房间
- 来到这个地牢的01层
- 首先向南走,然后绕过墙,攻击你看到的第一个怪物[101,1]
- 然后向西走到墙边,向北攻击史莱姆
- 继续向北,攻击下一个怪物
- 向北走到拐角处,然后向东走到楼梯处继续前进[坐标为101,1]
- 来到第二层,直接向东走上楼梯[11,-19]
- 来到了这个地牢的第03层
- 向东再向南走到墙边,然后向东走,与绿色史莱姆战斗
- 继续向东走,经过被打败的史莱姆,然后向南和向西绕过墙,向北走一格,向西打败另一个史莱姆
- 向西南方向走下楼梯[53,-49]
- 来到了第 04 层
- 走到墙边,撞右边两个镣铐之间的墙,然后向北直接走到墙里[15,-65]
- 直接向北走,踏上红色的东西
- 沿着楼梯向南和东南方向走右边楼梯[39,-69]
- 来到第5层
- 向北走,然后向西绕过中间的十字架,向南走到下一个楼梯[29,-93]
- 来到第 6 层
- 杀死那只大绿狗
- 回到刚才的楼梯,来到05层[33,-114]
- 在第05层,你会看到原来的十字架位置附近出现了新的楼梯口
- 走上该楼梯[54, -99]
- 到达了最后的?层
- 沿着小路向下走,然后沿着冰冷的台阶走到Rudolph NPC
- 在他身边来回走动
- 踩在他身上的次数足够多时,Rudolph会把该图的水晶球交给你
`,
},
"Pokemon CT": {
title: 'Pokemon CT', wt: `
- 宝可梦新增了战斗系统,路过高草丛会几率进入战斗
- 战斗系统为一个十字形界面,上:技能/精灵球捕捉,下:逃跑,左:回血,右:攻击
- 战斗守则:攻击,当你血量为33时回血
- 打败最终BOSS需要捕捉两只,捕捉地点:
- 一:把包裹交给大木博士后,去常磐市的路上
- 二:进入森林后遇到的毛毛虫
- 捕捉时需要将其打到残血。
- 最终BOSS打法:
- 第一个敌方精灵,毛虫进化的蝴蝶,先放技能,使其眩晕,在眩晕期间攻击,一旦醒过来就眩晕,重复。
- 第一个BOSS死后,第二个BOSS会秒杀蝴蝶, 此时用第二个精灵。
- 第二个精灵打法:攻击,看见它放absorbing技能就去回血(当然你没血了也要去回血),重复。
- 【游戏开始】
- 出生在你房间的二楼
- 下楼梯离开房间。走出家门。从那里向东北方向进入高草丛,将被传送到大木博士(Professor Oak)的实验室
- 踩大木博士
- 踏上桌子,选择你的宝可梦
- 现在出门去常磐市(Veridian City)拿一个包裹
- 离开大木博士的实验室,向北走,穿过草地,前往常磐市(Veridian City)
- 进入城市后,前往 Poke Mart [134,-3]
- 回到大木博士的实验室,返回时可以跳下小路西侧的山崖,避开高草丛
- 把包裹交给大木博士后。回常磐市
- 在房子和两个精灵之间的小路上继续向北走,穿过城市[79,-21]
- 过了精灵后一路向北
- 进入一所房子,经过它才能进入常磐森林
- 穿过常磐森林才能到达尼比市
- 森林的入口向东走,直到看到高草,然后向北走,直到下一片高草
- 绕过树木向东走,然后向北走
- 现在绕过树木向西走,然后向北走
- 然后穿过草地向西和向南走
- 沿着这条小路蜿蜒穿过高高的草丛
- 沿着小路穿过草地,最终离开森林
- 离开森林后,沿着草丛旁小路向北走,到达 Pewter City。向北向西绕到大房子处,到达道馆
- 走到大胡桃夹子前,挑战小刚
- 赢得这场战斗后你会被带到大木博士那里,他会给本地图的水晶球
`,
},
"Winter in Gatlin": {
title: 'Winter in Gatlin', wt: `
- 从出生点出发
- 往右走到达树林,往右上走跨过铁栅栏,再往右走,经过红车时从右边缝隙穿过往下走
- 沿公路向下走到第一个岔路向右走到废弃的小屋[14,80]
- 进入小屋时,你会在一个黑色的小房间里,走到亮起的圆圈处
- 在下一个房间里,会有一连串的数字,按以下顺序走到数字上
- 1,4,6,8,7,6,4
- 在最后一个房间,Epic_Heasley NPC 会给你本图的水晶球
`,
},
};
const $city_wrapper = $root.querySelectorAll('div[class^="core-layout__"]');
$city_wrapper.forEach(el => {
let $wh_container = $root.querySelector('#wh-xmas-cont');
if (!$wh_container) {
$(el).prepend(insert_html);
$wh_container = $root.querySelector('#wh-xmas-cont');
// 显示 隐藏
const jquery$wh_container = $($wh_container);
const $cont_gray = jquery$wh_container.find('.cont-gray');
jquery$wh_container.find('button').click(e => {
if (e.target.innerText === '[隐藏]') {
$cont_gray.hide();
e.target.innerText = '[显示]';
} else {
$cont_gray.show();
e.target.innerText = '[隐藏]';
}
});
// 内容
const $wt_content = jquery$wh_container.find('#wt-content');
jquery$wh_container.find('select').change(e => {
const selected = e.target.value;
$wt_content.html(`${ wt_dict[selected].title }
${ wt_dict[selected].wt }
`)
});
}
});
}
// 宝箱检测
if (xmasTownNotify) {
const chestTypeDict = { '1': '金', '2': '银', '3': '铜', };
const chestTypeColorDict = { '1': 'gold', '2': 'silver', '3': 'sandybrown', };
const lootTypeDict = {
'chests': '钥匙箱',
'gifts': '礼物',
'combinationChest': '密码箱',
'keys': '钥匙',
};
const keyTypeDict = { 'b': '铜', 's': '银', 'g': '金', };
let dropHist = localStorage.getItem('wh-loot-store')
? JSON.parse(localStorage.getItem('wh-loot-store'))
: {};
const alertSettings = localStorage.getItem('wh-loot-setting')
? JSON.parse(localStorage.getItem('wh-loot-setting'))
: { blink: 'y', sound: 'y', chest: 'y' };
let $ct_wrap;
let soundLoopFlag = false;
const getDOMOb = new MutationObserver(() => {
$ct_wrap = $root.querySelector('#ct-wrap');
if ($ct_wrap) {
getDOMOb.disconnect();
const insert_html = `
`;
$($ct_wrap).before(insert_html);
const $wh_loot_container = $root.querySelector('#wh-loot-container') as HTMLElement;
const $btn = $wh_loot_container.querySelector('#wh-loot-btn button') as HTMLButtonElement;
const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button') as HTMLButtonElement;
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') as HTMLInputElement;
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound') as HTMLInputElement;
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest') as HTMLInputElement;
const $audio = $wh_loot_container.querySelector('audio');
$btn.onclick = e => {
let target = e.target as HTMLButtonElement;
target.innerText = target.innerText === '设置' ? '收起' : '设置';
$($ex).toggleClass('wh-hide');
target.blur();
};
$clear_btn.onclick = e => {
let target = e.target as HTMLButtonElement;
target.blur();
dropHist = {};
$tbody.innerHTML = '';
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
};
$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($root, { childList: true, subtree: true });
}
});
const ob = new MutationObserver(() => {
ob.disconnect();
// 页面刷新重新获取dom
$root = document.querySelector('#christmastownroot');
$ct_wrap = $root.querySelector('#ct-wrap');
if (!$ct_wrap) {
ob.observe($root, { childList: true, subtree: true });
return;
}
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) {
ob.observe($root, { childList: true, subtree: true });
return;
}
const $pos_spl = $pos.innerText.trim().split(',');
const player_position = {
x: parseInt($pos_spl[0]),
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');
if (!$wh_loot_container) {
console.error('掉落助手未找到DOM容器');
ob.observe($root, { childList: true, subtree: true });
return;
}
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink') as HTMLInputElement;
const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound') as HTMLInputElement;
const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest') as HTMLInputElement;
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 += `${ path }[${ nearby_item.x },${ nearby_item.y }] ${ item_name }
`
} 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 += `${ path }[${ nearby_item.x },${ nearby_item.y }] ${ item_name }
`
}
// 确认地图坐标存在
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() + 1 }-${ now.getDate() } ${ 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 += `| ${ e.pos } | ${ e.map } | ${ e.name } | ${ e.last } | ${ e.isPassed ? '已取得' : '不确定' } |
`;
});
$tbody.innerHTML = table_html;
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
ob.observe($root, { childList: true, subtree: true });
});
getDOMOb.observe($root, { childList: true, subtree: true });
}
}
// rw雷达
if (href.includes('profiles.php?XID=0')) {
const utl = {
set: function (k, v) {
const obj = JSON.parse(localStorage['wh_rw_raider']) || {};
obj[k] = v;
localStorage['wh_rw_raider'] = JSON.stringify(obj);
},
get: function (k) {
const obj = JSON.parse(localStorage['wh_rw_raider']) || {};
return obj[k];
},
setFactionID: function (id) {
this.set('faction', id);
},
setRWFactionID: function (id) {
this.set('rw_faction', id);
},
getFactionID: async function (apikey) {
const response = await fetch('https://api.torn.com/faction/?selections=basic&key=' + apikey);
const res_obj = await response.json();
const faction_id = res_obj['ID'];
if (faction_id) {
this.setFactionID(faction_id);
return faction_id;
} else return -1;
},
getRWFactionID: function (apikey) {
},
};
const rw_raider = async function () {
if (href.includes('#rader')) {
Utils.addStyle('div.content-title,div.info-msg-cont{display:none;}');
const wh_node = document.createElement('div');
wh_node.id = 'wh-rd-cont';
wh_node.innerHTML = `
`;
// 原页面完全加载
await elementReady('div.msg[role="alert"]');
const t_cont = document.querySelector('div.content-wrapper');
// t
t_cont.append(wh_node);
}
};
addEventListener('hashchange', rw_raider);
rw_raider().then();
}
// 特定代码块 TODO 修复
if (InfoUtils.getInstance().getPlayerInfo().userID === 2687093 && Utils.getDeviceType() === Device.PC) {
InfoUtils.getInstance().getSidebarData().then(data => {
Log.info({ data })
let item = document.getElementById('nav-items');
if (item) {
let copy = item.cloneNode(true);
// TODO 待验证
(copy.firstChild).style.backgroundColor = '#ff5722';
// copy.firstChild.style.backgroundColor = '#ff5722';
let a = copy.firstChild.firstChild as HTMLAnchorElement;
a.href = '/item.php?temp=1';
let span = a.lastChild as HTMLElement;
span.innerHTML = '物品';
span.style.color = 'white';
item.after(copy);
}
});
}
}
}