import cityFinder from "../func/module/cityFinder"; import { missionDict } from "../dictionary/translation"; import getTaskHint from "../func/translate/getTaskHint"; import Device from "../enum/Device"; import WuhuBase from "./WuhuBase"; import CommonUtils from "./utils/CommonUtils"; import Log from "./Log"; import WuhuConfig from "./WuhuConfig"; import Alert from "./utils/Alert"; import InfoUtils from "./utils/InfoUtils"; import SHOP_BEER_STATIC_ITEM_HTML from "../static/html/buyBeer/shop_beer_static_item.html"; import ADD_BEER_HEAD_HTML from "../static/html/buyBeer/add_beer_head.html"; import QUICK_CRIMES_HTML from "../static/html/quick_crimes.html"; import RW_RIDER_HTML from "../static/html/rw_rider.html"; import christmasTownHelper from "../func/module/christmasTownHelper"; import LotteryHelper from "./action/LotteryHelper"; import TornStyleBlock from "./utils/TornStyleBlock"; export default class UrlPattern extends WuhuBase { static resolve() { let { href, beer } = UrlPattern.glob; // 捡垃圾助手 if (href.includes('city.php') && WuhuConfig.get('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 block = new TornStyleBlock('叠E保护').insert2Dom(); block.setContent(``); // 绑定点击事件 block.querySelector('input').onchange = e => { let target = e.target as HTMLInputElement; document.body.classList.toggle('wh-gym-stack'); WuhuConfig.set('SEProtect', target.checked, true); }; if (WuhuConfig.get('SEProtect')) document.body.classList.add('wh-gym-stack'); } // 啤酒店 if (href.includes('shops.php?step=bitsnbobs')) { let block = new TornStyleBlock('啤酒助手').insert2Dom(); block.setContent(ADD_BEER_HEAD_HTML); const msg_node = block.querySelector('#wh-msg'); // 加入啤酒 // CommonUtils.elementReady('ul.items-list').then(node => { block.querySelector('button').addEventListener('click', e => { let node = document.querySelector('ul.items-list'); if (!node) { msg_node.innerHTML = '❌ 商品未加载完'; Log.error('商品未加载完'); return; } if (node.querySelector('span[id="180-name"]')) { msg_node.innerHTML = '❌ 页面已经有啤酒了'; Log.warn('商店页面已有啤酒'); 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 = SHOP_BEER_STATIC_ITEM_HTML; if (clear_node) clear_node.before(beer); else node.append(beer); // (e.target).remove(); (e.target).disabled = true; msg_node.innerHTML = '添加成功'; }); // }); // 监听啤酒购买 $(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/) && WuhuConfig.get('quickCrime')) { if (self !== top) { const isValidate = document.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate'); CommonUtils.elementReady('#header-root').then(e => e.style.display = 'none'); CommonUtils.elementReady('#sidebarroot').then(e => e.style.display = 'none'); CommonUtils.elementReady('#chatRoot').then(e => e.style.display = 'none'); if (!isValidate) document.body.style.overflow = 'hidden'; CommonUtils.elementReady('.content-wrapper').then(e => { e.style.margin = '0px'; e.style.position = 'absolute'; e.style.top = '-35px'; }); CommonUtils.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 = QUICK_CRIMES_HTML; 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/) && WuhuConfig.get('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/) && new Date().getMonth() > 9) christmasTownHelper(); // 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')) { CommonUtils.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 = RW_RIDER_HTML; // 原页面完全加载 await CommonUtils.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(); } // 特定 if (InfoUtils.getInstance().getPlayerInfo().userID === 2687093 && CommonUtils.getDeviceType() === Device.PC) { InfoUtils.getInstance().getSidebarData().then(data => { let item = document.getElementById('nav-items'); if (item) { let copy = item.cloneNode(true); (copy.firstChild).style.backgroundColor = '#678c00'; 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); } }); } // 彩票助手 if (href.includes('loader.php?sid=lottery')) { LotteryHelper.getInstance().init(); } } }