This commit is contained in:
Liwanyi 2022-11-04 17:33:19 +08:00
parent f5e4a5cfe3
commit 95ca6914a9
9 changed files with 159 additions and 72 deletions

View File

@ -4,6 +4,14 @@
# CHANGE # CHANGE
## 0.6.8
2022年11月4日
### 添加
- 边栏-可选隐藏侧边栏
## 0.6.7 ## 0.6.7
2022年11月3日 2022年11月3日

View File

@ -1,6 +1,6 @@
{ {
"name": "wuhu-torn-helper", "name": "wuhu-torn-helper",
"version": "0.6.7", "version": "0.6.8",
"description": "芜湖助手", "description": "芜湖助手",
"dependencies": {}, "dependencies": {},
"scripts": { "scripts": {

File diff suppressed because one or more lines are too long

View File

@ -3,9 +3,9 @@ import travelHelper from "../func/module/travelHelper";
import priceWatcherHandle from "../func/module/priceWatcherHandle"; import priceWatcherHandle from "../func/module/priceWatcherHandle";
import WuhuBase from "./WuhuBase"; import WuhuBase from "./WuhuBase";
import WuhuConfig from "./WuhuConfig"; import WuhuConfig from "./WuhuConfig";
import CommonUtils from "./utils/CommonUtils";
import CompanyHelper from "./action/CompanyHelper"; import CompanyHelper from "./action/CompanyHelper";
import AttackHelper from "./action/AttackHelper"; import AttackHelper from "./action/AttackHelper";
import SidebarHelper from "./action/SidebarHelper";
export class Common extends WuhuBase { export class Common extends WuhuBase {
className = 'Common'; className = 'Common';
@ -17,60 +17,14 @@ export class Common extends WuhuBase {
// 啤酒提醒 // 啤酒提醒
if (WuhuConfig.get('_15Alarm')) glob.beer.start(); if (WuhuConfig.get('_15Alarm')) glob.beer.start();
// 点击4条转跳对应的页面// SidebarHelper.getInstance();
if (WuhuConfig.get('barsRedirect') && !document.body.classList.contains('without-sidebar')) {
const eb = document.getElementById('barEnergy') as HTMLAnchorElement;
const nb = document.getElementById('barNerve') as HTMLAnchorElement;
const hb = document.getElementById('barHappy') as HTMLAnchorElement;
const lb = document.getElementById('barLife') as HTMLAnchorElement;
if (eb) {
eb.addEventListener('click', () => location.href = '/gym.php');
eb.href = '/gym.php';
} else {
CommonUtils.elementReady('#barEnergy').then(eb => {
eb.addEventListener('click', () => location.href = '/gym.php');
(eb as HTMLAnchorElement).href = '/gym.php';
});
}
if (nb) {
nb.addEventListener('click', () => location.href = '/crimes.php');
nb.href = '/crimes.php';
} else {
CommonUtils.elementReady('#barNerve').then(nb => {
nb.addEventListener('click', () => location.href = '/crimes.php');
(nb as HTMLAnchorElement).href = '/crimes.php';
});
}
if (hb) {
hb.addEventListener('click', () => location.href = '/item.php#boosters-items');
hb.href = '/item.php#boosters-items';
} else {
CommonUtils.elementReady('#barHappy').then(hb => {
hb.addEventListener('click', () => location.href = '/item.php#boosters-items');
(hb as HTMLAnchorElement).href = '/item.php#boosters-items';
});
}
if (lb) {
lb.addEventListener('click', () => location.href = '/item.php#medical-items');
lb.href = '/item.php#medical-items';
} else {
CommonUtils.elementReady('#barLife').then(lb => {
lb.addEventListener('click', () => location.href = '/item.php#medical-items');
(lb as HTMLAnchorElement).href = '/item.php#medical-items';
});
}
}
/** /**
* * All('script[src*="google"]')
* TODO * All('#gtm_tag')
* All('script[src*="chat/gonline"]')
* All('head script[nonce]')
*/ */
// if (WuhuConfig.get('removeScripts') && false) {
// document.querySelectorAll('script[src*="google"]').forEach(item => item.remove());
// document.querySelectorAll('#gtm_tag').forEach(item => item.remove());
// document.querySelectorAll('script[src*="chat/gonline"]').forEach(item => item.remove());
// document.querySelectorAll('head script[nonce]').forEach(item => item.remove());
// }
// 存钱相关 // 存钱相关
depoHelper(); depoHelper();
@ -79,7 +33,6 @@ export class Common extends WuhuBase {
travelHelper().then(); travelHelper().then();
// 战斗相关 // 战斗相关
// attackHelper().then();
AttackHelper.getInstance(); AttackHelper.getInstance();
// 公司助手 // 公司助手

View File

@ -109,8 +109,15 @@ export default class WuhuConfig extends WuhuBase {
{ key: 'ShowNameHistory', val: true }, { key: 'ShowNameHistory', val: true },
// 盯梢模式强度 0-550 1-950 2-1450 ms // 盯梢模式强度 0-550 1-950 2-1450 ms
{ key: 'WatchTargetFreq', val: 1 }, { key: 'WatchTargetFreq', val: 1 },
// 隐藏侧边栏
{ key: 'HideSidebar', val: false },
// 添加隐藏边栏按钮
{ key: 'HideSidebarBtn', val: true },
// 危险行为⚠️ /**
*
* @deprecated
*/
{ key: 'dangerZone', val: false }, { key: 'dangerZone', val: false },
].forEach(df => { ].forEach(df => {
if (typeof WuhuConfig.get(df.key) !== typeof df.val) { if (typeof WuhuConfig.get(df.key) !== typeof df.val) {

View File

@ -349,7 +349,7 @@ export default class ZhongIcon extends WuhuBase {
list.push({ list.push({
domType: 'button', domType: 'button',
domId: '', domId: '',
domText: '🪵 寻找木桩', domText: '🌲寻找木桩',
clickFunc: () => window.location.href = 'https://www.torn.com/item.php?temp=4#xunzhaomuzhuang' clickFunc: () => window.location.href = 'https://www.torn.com/item.php?temp=4#xunzhaomuzhuang'
}); });
// 更新历史 // 更新历史

View File

@ -0,0 +1,103 @@
import WuhuBase from "../WuhuBase";
import WuhuConfig from "../WuhuConfig";
import CommonUtils from "../utils/CommonUtils";
import Global from "../Global";
import Device from "../../enum/Device";
import Log from "../Log";
export default class SidebarHelper extends WuhuBase {
className = 'SidebarHelper';
private readonly sidebarRootNode: HTMLElement;
private readonly toggleBtn: HTMLButtonElement;
private isHide: boolean;
constructor() {
super();
this.sidebarRootNode = document.querySelector('#sidebarroot');
this.toggleBtn = document.createElement('button');
this.isHide = !!WuhuConfig.get('HideSidebar');
if (!document.body.classList.contains('without-sidebar')) {
this.initToggleBtn();
this.barRedirect();
} else {
Log.warn('[SidebarHelper] 页面未开启边栏,边栏助手退出');
}
}
// 初始化隐藏按钮
private initToggleBtn(): void {
if (Global.getInstance().device === Device.PC && this.sidebarRootNode && WuhuConfig.get('HideSidebarBtn')) {
this.isHide ? this.hideHandler() : this.showHandler();
let container = document.createElement('div');
container.append(this.toggleBtn);
container.style.width = '0';
container.style.zIndex = '1';
container.style.opacity = '0.75';
this.toggleBtn.classList.add('torn-btn');
this.sidebarRootNode.before(container);
this.toggleBtn.addEventListener('click', () => {
this.isHide ? this.showHandler() : this.hideHandler();
});
}
}
private hideHandler(): void {
this.sidebarRootNode.classList.add('wh-hide');
this.isHide = WuhuConfig.set('HideSidebar', true);
this.toggleBtn.innerHTML = '>>';
}
private showHandler(): void {
this.sidebarRootNode.classList.remove('wh-hide');
this.isHide = WuhuConfig.set('HideSidebar', false);
this.toggleBtn.innerHTML = '<<';
}
// 4条转跳
private barRedirect(): void {
if (WuhuConfig.get('barsRedirect')) {
const eb = document.getElementById('barEnergy') as HTMLAnchorElement;
const nb = document.getElementById('barNerve') as HTMLAnchorElement;
const hb = document.getElementById('barHappy') as HTMLAnchorElement;
const lb = document.getElementById('barLife') as HTMLAnchorElement;
if (eb) {
eb.addEventListener('click', () => location.href = '/gym.php');
eb.href = '/gym.php';
} else {
CommonUtils.elementReady('#barEnergy').then(eb => {
eb.addEventListener('click', () => location.href = '/gym.php');
(eb as HTMLAnchorElement).href = '/gym.php';
});
}
if (nb) {
nb.addEventListener('click', () => location.href = '/crimes.php');
nb.href = '/crimes.php';
} else {
CommonUtils.elementReady('#barNerve').then(nb => {
nb.addEventListener('click', () => location.href = '/crimes.php');
(nb as HTMLAnchorElement).href = '/crimes.php';
});
}
if (hb) {
hb.addEventListener('click', () => location.href = '/item.php#boosters-items');
hb.href = '/item.php#boosters-items';
} else {
CommonUtils.elementReady('#barHappy').then(hb => {
hb.addEventListener('click', () => location.href = '/item.php#boosters-items');
(hb as HTMLAnchorElement).href = '/item.php#boosters-items';
});
}
if (lb) {
lb.addEventListener('click', () => location.href = '/item.php#medical-items');
lb.href = '/item.php#medical-items';
} else {
CommonUtils.elementReady('#barLife').then(lb => {
lb.addEventListener('click', () => location.href = '/item.php#medical-items');
(lb as HTMLAnchorElement).href = '/item.php#medical-items';
});
}
}
}
}

View File

@ -384,6 +384,30 @@ export default class SettingsHandler extends WuhuBase {
domId: '' domId: ''
}); });
// 侧边栏
list.push({
domType: 'plain',
domId: '',
domHTML: '侧边栏',
tagName: 'h4',
});
// 4条转跳
list.push({
domType: 'checkbox',
domId: '',
domText: ' 4条转跳',
dictName: 'barsRedirect',
tip: '点击4条时转跳对应页面手机端不建议开启',
});
// 添加隐藏边栏按钮
list.push({
domType: 'checkbox',
domId: '',
domText: ' 添加隐藏边栏按钮',
dictName: 'HideSidebarBtn',
tip: '仅PC'
});
// 其他 // 其他
list.push({ list.push({
domType: 'plain', domType: 'plain',
@ -436,14 +460,6 @@ export default class SettingsHandler extends WuhuBase {
tip: 'PT市场页面购买时跳过确认', tip: 'PT市场页面购买时跳过确认',
isHide: true, isHide: true,
}); });
// 4条转跳
list.push({
domType: 'checkbox',
domId: '',
domText: ' 4条转跳',
dictName: 'barsRedirect',
tip: '点击4条时转跳对应页面',
});
// 清除多余的脚本 // 清除多余的脚本
// list.push({ // list.push({
// domType: 'checkbox', // domType: 'checkbox',

View File

@ -20,9 +20,9 @@ export default class ViewLogsHandler extends WuhuBase {
logs.forEach(log => { logs.forEach(log => {
let p = document.createElement('p'); let p = document.createElement('p');
p.innerText = log; p.innerText = log;
if (log.includes('ERR')) { if (log.slice(0, 10).includes('ERR')) {
p.style.backgroundColor = '#ff000080'; p.style.backgroundColor = '#ff000080';
} else if (log.includes('WRN')) { } else if (log.slice(0, 10).includes('WRN')) {
p.style.backgroundColor = '#ffff0080'; p.style.backgroundColor = '#ffff0080';
} }
text.append(p); text.append(p);