Compare commits
No commits in common. "master" and "v0.6.4" have entirely different histories.
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,8 +1,4 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
|
/bundle.min.js
|
||||||
|
/bundle.js
|
||||||
/.fleet
|
/.fleet
|
||||||
/src/dist/bundle.min.js
|
|
||||||
/src/dist/bundle.js
|
|
||||||
/dist
|
|
||||||
auto-imports.d.ts
|
|
||||||
components.d.ts
|
|
||||||
aws.xml
|
|
||||||
6
.idea/jsLibraryMappings.xml
generated
Normal file
6
.idea/jsLibraryMappings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptLibraryMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$" libraries="{Node.js Core}" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
3
.idea/torncity-zhcn-translate.iml
generated
3
.idea/torncity-zhcn-translate.iml
generated
@ -4,9 +4,6 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.fleet" />
|
<excludeFolder url="file://$MODULE_DIR$/.fleet" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/misc" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
|
||||||
<excludePattern pattern="release.min.user.js" />
|
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
|||||||
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
// 使用 IntelliSense 了解相关属性。
|
|
||||||
// 悬停以查看现有属性的描述。
|
|
||||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"command": "npm run rollup",
|
|
||||||
"name": "rollup",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "node-terminal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
538
CHANGELOG.md
538
CHANGELOG.md
@ -1,539 +1,9 @@
|
|||||||
|
# TODO
|
||||||
|
|
||||||
|
- 翻译:baza npc商店、imarket、imarket搜索结果
|
||||||
|
|
||||||
# CHANGE
|
# CHANGE
|
||||||
|
|
||||||
## 1.2.4
|
|
||||||
|
|
||||||
2025年04月07日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 优化起飞功能错误处理
|
|
||||||
- 取消网络拦截,避免官方功能被影响
|
|
||||||
|
|
||||||
## 1.2.3
|
|
||||||
|
|
||||||
2025年03月11日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 删除GS Load模块代码
|
|
||||||
- 删除翻译
|
|
||||||
- 删除去Google化部分代码
|
|
||||||
- 修复起飞逻辑
|
|
||||||
- 修复通知
|
|
||||||
|
|
||||||
## 1.2.2
|
|
||||||
|
|
||||||
2024年04月07日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 快捷动作【REFILL】修复
|
|
||||||
|
|
||||||
## 1.2.1
|
|
||||||
|
|
||||||
2024年04月03日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 快捷动作【REFILL】修复
|
|
||||||
|
|
||||||
## 1.2.0
|
|
||||||
|
|
||||||
2024年03月29日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- BS估算缓存机制修复
|
|
||||||
- 快捷功能【快速犯罪】界面优化
|
|
||||||
|
|
||||||
## 1.1.9
|
|
||||||
|
|
||||||
2024年03月27日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 引入了BS估算功能
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 快捷功能【快速犯罪】去除了烦人的通知
|
|
||||||
|
|
||||||
## 1.1.8
|
|
||||||
|
|
||||||
2024年03月20日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 快捷功能的【喝啤酒】移动至【快速犯罪】中
|
|
||||||
- profile页面中在线状态调整
|
|
||||||
|
|
||||||
## 1.1.7
|
|
||||||
|
|
||||||
2024年03月15日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 快捷功能-PI存钱
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 上次动作的url判断修复
|
|
||||||
- profile页面中添加了更明显的上次动作时间
|
|
||||||
- 快速取钱功能添加了常用输入
|
|
||||||
|
|
||||||
## 1.1.6
|
|
||||||
|
|
||||||
2024年01月08日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- refill功能改为菜单式,新增支持3种refil
|
|
||||||
- 快速犯罪功能现已支持全部种类
|
|
||||||
|
|
||||||
## 1.1.5
|
|
||||||
|
|
||||||
2023年12月22日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 圣诞小镇掉落物记录表格中的undefined错误修复
|
|
||||||
|
|
||||||
## 1.1.4
|
|
||||||
|
|
||||||
2023年12月08日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 快速犯罪中添加了15-3
|
|
||||||
|
|
||||||
## 1.1.3
|
|
||||||
|
|
||||||
2023年11月29日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 通知浏览错误修复
|
|
||||||
|
|
||||||
## 1.1.2
|
|
||||||
|
|
||||||
2023年09月19日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 火车提醒错误修复
|
|
||||||
- 光速刷新错误修复
|
|
||||||
|
|
||||||
## 1.1.1
|
|
||||||
|
|
||||||
2023年09月13日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 调整了上次动作的显示逻辑
|
|
||||||
- 更准确的现金变动提醒
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 监控模块-毒CD提醒
|
|
||||||
|
|
||||||
## 1.1.0
|
|
||||||
|
|
||||||
2023年09月11日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 更正上次动作的匹配路径、添加了毒和糖 CD 的提示
|
|
||||||
|
|
||||||
## 1.0.9
|
|
||||||
|
|
||||||
2023年09月08日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 侧边菜单UI优化
|
|
||||||
|
|
||||||
## 1.0.8
|
|
||||||
|
|
||||||
2023年08月23日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 通知浏览修复
|
|
||||||
|
|
||||||
## 1.0.7
|
|
||||||
|
|
||||||
2023年06月27日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 物品功能补充完善
|
|
||||||
- 菜单顺序调整
|
|
||||||
|
|
||||||
## 1.0.6
|
|
||||||
|
|
||||||
2023年06月26日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 物品功能标签
|
|
||||||
|
|
||||||
## 1.0.5
|
|
||||||
|
|
||||||
2023年06月19日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 移除原菜单
|
|
||||||
- 调整了新菜单的样式、部分逻辑
|
|
||||||
|
|
||||||
## 1.0.4
|
|
||||||
|
|
||||||
2023年06月16日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 标签页管理功能
|
|
||||||
|
|
||||||
## 1.0.3
|
|
||||||
|
|
||||||
2023年06月16日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 样式错误修复
|
|
||||||
|
|
||||||
## 1.0.2
|
|
||||||
|
|
||||||
2023年06月15日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 错误修复
|
|
||||||
- 菜单样式修改
|
|
||||||
|
|
||||||
## 1.0.1
|
|
||||||
|
|
||||||
2023年06月14日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 公司存取钱
|
|
||||||
|
|
||||||
## 1.0.0
|
|
||||||
|
|
||||||
2023年06月12日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- PT购买
|
|
||||||
|
|
||||||
## 0.9.9
|
|
||||||
|
|
||||||
2023年06月07日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 购物助手错误修复及样式调整
|
|
||||||
|
|
||||||
## 0.9.8
|
|
||||||
|
|
||||||
2023年06月06日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 错误修复
|
|
||||||
|
|
||||||
## 0.9.7
|
|
||||||
|
|
||||||
2023年06月05日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- bazaar快速开关店
|
|
||||||
- 购物助手
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 部分样式修改
|
|
||||||
|
|
||||||
## 0.9.6
|
|
||||||
|
|
||||||
2023年06月01日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- PC病毒快速操作
|
|
||||||
|
|
||||||
## 0.9.5
|
|
||||||
|
|
||||||
2023年05月31日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 明文密码简单编码处理
|
|
||||||
- 自动登录前添加确认
|
|
||||||
|
|
||||||
## 0.9.4
|
|
||||||
|
|
||||||
2023年05月31日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 自动登陆功能
|
|
||||||
|
|
||||||
## 0.9.3
|
|
||||||
|
|
||||||
2023年05月30日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 快速查看地图垃圾
|
|
||||||
|
|
||||||
## 0.9.2
|
|
||||||
|
|
||||||
2023年05月26日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 快速浏览通知
|
|
||||||
|
|
||||||
## 0.9.1
|
|
||||||
|
|
||||||
2023年05月04日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 新菜单中现在可以快速喝啤酒了
|
|
||||||
- 快速 refill
|
|
||||||
|
|
||||||
## 0.9.0
|
|
||||||
|
|
||||||
2023年04月28日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 新菜单中现在可以快速吃XAN了
|
|
||||||
- 快速犯罪
|
|
||||||
|
|
||||||
## 0.8.9
|
|
||||||
|
|
||||||
2023年04月24日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 战斗相关模块错误修复
|
|
||||||
- 重复通知错误修复
|
|
||||||
|
|
||||||
## 0.8.8
|
|
||||||
|
|
||||||
2023年04月17日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 新菜单
|
|
||||||
- 快速锻炼
|
|
||||||
- 一键起飞
|
|
||||||
|
|
||||||
## 0.8.7
|
|
||||||
|
|
||||||
2023年04月10日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 修复脚本首次运行配置获取错误的问题
|
|
||||||
- 修复"解决加载中"功能开启后无法加载插件图标的问题
|
|
||||||
- 修复功能选项错误读取默认值的问题
|
|
||||||
|
|
||||||
## 0.8.6
|
|
||||||
|
|
||||||
2023年04月07日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 结构调整
|
|
||||||
|
|
||||||
## 0.8.5
|
|
||||||
|
|
||||||
2023年04月03日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 结构调整
|
|
||||||
|
|
||||||
## 0.8.4
|
|
||||||
|
|
||||||
2023年03月03日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 错误修复
|
|
||||||
|
|
||||||
## 0.8.3
|
|
||||||
|
|
||||||
2023年03月02日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 物品查价
|
|
||||||
|
|
||||||
## 0.8.2
|
|
||||||
|
|
||||||
2023年02月01日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 新翻译:通用物品名与详情
|
|
||||||
|
|
||||||
## 0.8.1
|
|
||||||
|
|
||||||
2023年02月01日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 上次动作的开关
|
|
||||||
|
|
||||||
## 0.8.0
|
|
||||||
|
|
||||||
2023年01月16日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 完善新的翻译部分
|
|
||||||
|
|
||||||
## 0.7.9
|
|
||||||
|
|
||||||
2023年01月09日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 优化了迷你选项卡的汉化效果
|
|
||||||
- 更新节日数据
|
|
||||||
|
|
||||||
## 0.7.8
|
|
||||||
|
|
||||||
2022年12月20日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 修复与其他脚本的兼容性问题
|
|
||||||
|
|
||||||
## 0.7.7
|
|
||||||
|
|
||||||
2022年12月7日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 老虎机批量购买
|
|
||||||
|
|
||||||
## 0.7.6
|
|
||||||
|
|
||||||
2022年12月6日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 现金变动提醒
|
|
||||||
|
|
||||||
## 0.7.5
|
|
||||||
|
|
||||||
2022年12月6日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 可记录上次图标的位置,调整了拖动逻辑
|
|
||||||
|
|
||||||
## 0.7.4
|
|
||||||
|
|
||||||
2022年12月5日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 插件图标现可拖动
|
|
||||||
- PC端滚动条样式
|
|
||||||
|
|
||||||
## 0.7.3
|
|
||||||
|
|
||||||
2022年11月25日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 捡垃圾助手调整
|
|
||||||
- 菜单调整
|
|
||||||
|
|
||||||
## 0.7.2
|
|
||||||
|
|
||||||
2022年11月22日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 修复光速跑路错误
|
|
||||||
|
|
||||||
## 0.7.1
|
|
||||||
|
|
||||||
2022年11月15日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 调整寻找木桩页面逻辑
|
|
||||||
- 修复光速刷新
|
|
||||||
|
|
||||||
## 0.7.0
|
|
||||||
|
|
||||||
2022年11月10日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 官方引入Google登陆方式及相关脚本后引起的无限加载中的问题的不完美解决办法
|
|
||||||
|
|
||||||
## 0.6.9
|
|
||||||
|
|
||||||
2022年11月8日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 搜索页-可选添加底部空白占位区
|
|
||||||
- 全屏菜单
|
|
||||||
- 自定义CSS
|
|
||||||
|
|
||||||
## 0.6.8
|
|
||||||
|
|
||||||
2022年11月4日
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 边栏-可选隐藏侧边栏
|
|
||||||
|
|
||||||
## 0.6.7
|
|
||||||
|
|
||||||
2022年11月3日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 重做光速跑路(需要更多测试)
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 战斗-盯梢模式
|
|
||||||
|
|
||||||
## 0.6.6
|
|
||||||
|
|
||||||
2022年10月31日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 寻找木桩添加停止操作
|
|
||||||
|
|
||||||
### 添加
|
|
||||||
|
|
||||||
- 个人资料隐藏头像、显示曾用名
|
|
||||||
|
|
||||||
## 0.6.5
|
|
||||||
|
|
||||||
2022年10月26日
|
|
||||||
|
|
||||||
### 修改
|
|
||||||
|
|
||||||
- 寻找木桩逻辑优化
|
|
||||||
|
|
||||||
## 0.6.4
|
## 0.6.4
|
||||||
|
|
||||||
2022年10月25日
|
2022年10月25日
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
|
|
||||||
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023 JJins
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
23
README.md
23
README.md
@ -1,23 +0,0 @@
|
|||||||
# Wuhu Torn Helper
|
|
||||||
|
|
||||||
[](LICENSE)
|
|
||||||
|
|
||||||
[中文](README_ZHCN.md)
|
|
||||||
|
|
||||||
[CHANGELOG(CN)](CHANGELOG.md)
|
|
||||||
|
|
||||||
A customized auxiliary-enhancement user script designed for a browser-based MMORPG game, featuring a range of convenient
|
|
||||||
functions.
|
|
||||||
|
|
||||||
This script does not include any automation-related code.
|
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
npm init
|
|
||||||
npm run rollup
|
|
||||||
|
|
||||||
## Use
|
|
||||||
|
|
||||||
[release.min.user.js](release.min.user.js)
|
|
||||||
|
|
||||||
Please install with Tampermonkey (for PC browser) or TornPDA.
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
# 芜湖助手 Torncity 翻译插件
|
|
||||||
|
|
||||||
[](LICENSE)
|
|
||||||
|
|
||||||
[CHANGELOG](CHANGELOG.md)
|
|
||||||
|
|
||||||
一个为浏览器网页MMORPG游戏定制的辅助增强用户脚本,包含了一系列便携功能。
|
|
||||||
|
|
||||||
此脚本不包含自动化相关代码。
|
|
||||||
|
|
||||||
## 编译
|
|
||||||
|
|
||||||
npm init
|
|
||||||
npm run rollup
|
|
||||||
|
|
||||||
## 使用
|
|
||||||
|
|
||||||
[release.min.user.js](https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/README_ZHCN.md)
|
|
||||||
|
|
||||||
请使用 Tampermonkey (浏览器) 或 TornPDA 安装。
|
|
||||||
@ -2,15 +2,13 @@
|
|||||||
* 此脚本用于加入userscript meta,
|
* 此脚本用于加入userscript meta,
|
||||||
* 并生成日期时间与版本号
|
* 并生成日期时间与版本号
|
||||||
*/
|
*/
|
||||||
|
let startTime = Date.now();
|
||||||
import { readFileSync, writeFileSync } from "fs";
|
let fs = require('fs');
|
||||||
import { prodConfig } from "./rollup.config.js";
|
|
||||||
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
let version = process.env.npm_package_version;
|
let version = process.env.npm_package_version;
|
||||||
let formattedDateTime = `${ date.getFullYear() }${ ('0' + (date.getMonth() + 1)).slice(-2) }${ ('0' + date.getDate()).slice(-2) }${ ('0' + date.getHours()).slice(-2) }${ ('0' + date.getMinutes()).slice(-2) }`;
|
let formattedDateTime = `${ date.getFullYear() }${ ('0' + (date.getMonth() + 1)).slice(-2) }${ ('0' + date.getDate()).slice(-2) }${ ('0' + date.getHours()).slice(-2) }${ ('0' + date.getMinutes()).slice(-2) }`;
|
||||||
let metaData =
|
let metaData = `// ==UserScript==
|
||||||
`// ==UserScript==
|
|
||||||
// @lastmodified ${ formattedDateTime }
|
// @lastmodified ${ formattedDateTime }
|
||||||
// @name 芜湖助手
|
// @name 芜湖助手
|
||||||
// @namespace WOOH
|
// @namespace WOOH
|
||||||
@ -18,9 +16,10 @@ let metaData =
|
|||||||
// @description 托恩,起飞!
|
// @description 托恩,起飞!
|
||||||
// @author Woohoo[2687093] Sabrina_Devil[2696209]
|
// @author Woohoo[2687093] Sabrina_Devil[2696209]
|
||||||
// @match https://www.torn.com/*
|
// @match https://www.torn.com/*
|
||||||
// @downloadURL https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/release.min.user.js
|
// @updateURL https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/release.min.user.js
|
||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
// @grant unsafeWindow
|
// @grant unsafeWindow
|
||||||
|
// @connect ljs-lyt.com
|
||||||
// @connect yata.yt
|
// @connect yata.yt
|
||||||
// @connect github.io
|
// @connect github.io
|
||||||
// @connect gitlab.com
|
// @connect gitlab.com
|
||||||
@ -29,11 +28,6 @@ let metaData =
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
`
|
`
|
||||||
|
|
||||||
const data = readFileSync('./' + prodConfig.output.file, 'utf8');
|
const data = fs.readFileSync('./bundle.min.js', 'utf8');
|
||||||
writeFileSync(
|
fs.writeFileSync('./release.min.user.js', metaData + data.replace('$$WUHU_DEV_VERSION$$', version), 'utf8');
|
||||||
'./release.min.user.js',
|
console.log(`版本 ${ version } 构建完成, build.js耗时${ Date.now() - startTime }ms`);
|
||||||
metaData + data.replace('$$WUHU_DEV_VERSION$$', version),
|
|
||||||
'utf8'
|
|
||||||
);
|
|
||||||
// rmSync('./' + prodConfig.output.file);
|
|
||||||
console.log(`版本 ${ version } 构建完成`);
|
|
||||||
6
css-module.d.ts
vendored
6
css-module.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
// declare module "*.module.css" {
|
|
||||||
// const css: string;
|
|
||||||
// const classes: { [key: string]: string };
|
|
||||||
// export default classes;
|
|
||||||
// export { css };
|
|
||||||
// }
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
export const customInjector = (varName) => {
|
|
||||||
let rt = ((__var) => {
|
|
||||||
const inject = (ob) => {
|
|
||||||
if (document && document.head) {
|
|
||||||
ob?.disconnect();
|
|
||||||
const style = document.createElement('style');
|
|
||||||
style.setAttribute('type', 'text/css');
|
|
||||||
style.innerHTML = __var;
|
|
||||||
document.head.appendChild(style);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (document && document.head) {
|
|
||||||
inject();
|
|
||||||
} else {
|
|
||||||
new MutationObserver((_, ob) => {
|
|
||||||
inject(ob);
|
|
||||||
}).observe(document.documentElement, { childList: true });
|
|
||||||
}
|
|
||||||
}).toString();
|
|
||||||
return `(${ rt })(${ varName })`;
|
|
||||||
};
|
|
||||||
19
global.d.ts
vendored
19
global.d.ts
vendored
@ -108,22 +108,15 @@ declare interface TornGetActionParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare module "*.html" {
|
declare module "*.html" {
|
||||||
const html: string;
|
const value: string;
|
||||||
export default html;
|
export default value;
|
||||||
}
|
}
|
||||||
declare module "*.module.css" {
|
|
||||||
const css: string;
|
declare module "*.css" {
|
||||||
// const classes: { [key: string]: string };
|
const value: string;
|
||||||
// export default classes;
|
export default value;
|
||||||
export default css;
|
|
||||||
// export { css };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare function GM_xmlhttpRequest(init: any): void;
|
declare function GM_xmlhttpRequest(init: any): void;
|
||||||
|
|
||||||
declare var unsafeWindow: Window & typeof globalThis;
|
declare var unsafeWindow: Window & typeof globalThis;
|
||||||
declare type Constructor<T = any> = new (...args: any[]) => T;
|
|
||||||
|
|
||||||
declare interface ClassType<T> {
|
|
||||||
new(...args: unknown[]): T
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
16538
misc/vue.js
16538
misc/vue.js
File diff suppressed because it is too large
Load Diff
10594
package-lock.json
generated
10594
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
44
package.json
44
package.json
@ -1,43 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "wuhu-torn-helper",
|
"name": "wuhu-torn-helper",
|
||||||
"version": "1.2.4",
|
"version": "0.6.4",
|
||||||
"description": "芜湖助手",
|
"description": "芜湖助手",
|
||||||
|
"dependencies": {},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"release": "cross-env NODE_ENV=production rollup -c && node build.mjs",
|
"release": "rollup -c rollup-prod.config.js && node build.js # 发布",
|
||||||
"watch": "cross-env NODE_ENV=development rollup -c -w",
|
"build": "rollup -c # 调试编译",
|
||||||
"rollup": "cross-env NODE_ENV=development rollup -c"
|
"rollup_watch": "rollup -c -w # 监控",
|
||||||
|
"minify": "uglifyjs misc/wuhu-torn-helper.js -o release.min.user.js -m # 弃用",
|
||||||
|
"serve": "# 弃用",
|
||||||
|
"compile": "tsc --outDir output # 弃用"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@element-plus/icons-vue": "^2.1.0",
|
|
||||||
"@rollup/plugin-alias": "^4.0.3",
|
|
||||||
"@rollup/plugin-commonjs": "^24.0.1",
|
|
||||||
"@rollup/plugin-json": "^4.1.0",
|
"@rollup/plugin-json": "^4.1.0",
|
||||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
||||||
"@rollup/plugin-replace": "^5.0.2",
|
|
||||||
"@rollup/plugin-terser": "^0.4.0",
|
|
||||||
"@rollup/plugin-typescript": "^8.5.0",
|
"@rollup/plugin-typescript": "^8.5.0",
|
||||||
"@types/jquery": "^3.5.14",
|
"@types/jquery": "^3.5.14",
|
||||||
"@types/node": "^20.6.0",
|
"@types/node": "^18.0.6",
|
||||||
"@vitejs/plugin-vue": "^4.0.0",
|
|
||||||
"@vue/tsconfig": "^0.1.3",
|
|
||||||
"cross-env": "^7.0.3",
|
|
||||||
"element-plus": "^2.3.10",
|
|
||||||
"just-clone": "^6.2.0",
|
|
||||||
"npm": "^8.19.2",
|
"npm": "^8.19.2",
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rollup": "^2.79.0",
|
"rollup": "^2.79.0",
|
||||||
"rollup-plugin-postcss": "^4.0.2",
|
"rollup-plugin-html-literals": "^1.1.5",
|
||||||
"rollup-plugin-string-html": "^1.0.0",
|
"rollup-plugin-serve": "^2.0.1",
|
||||||
"rollup-plugin-styles": "^4.0.0",
|
"rollup-plugin-string": "^3.0.0",
|
||||||
"rollup-plugin-typescript2": "^0.34.1",
|
"rollup-plugin-uglify": "^6.0.4",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"typescript": "^4.8.3",
|
"typescript": "^4.8.3",
|
||||||
"unplugin-auto-import": "^0.15.2",
|
"uglify-js": "^3.16.1"
|
||||||
"unplugin-element-plus": "^0.7.0",
|
}
|
||||||
"unplugin-icons": "^0.16.1",
|
|
||||||
"unplugin-vue-components": "^0.24.1",
|
|
||||||
"vant": "^4.1.2",
|
|
||||||
"vue": "^3.2.47"
|
|
||||||
},
|
|
||||||
"type": "module"
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
20
rollup-prod.config.js
Normal file
20
rollup-prod.config.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import typescript from "@rollup/plugin-typescript";
|
||||||
|
import json from "@rollup/plugin-json";
|
||||||
|
import { string } from "rollup-plugin-string";
|
||||||
|
import { uglify } from "rollup-plugin-uglify";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: 'src/index.ts',
|
||||||
|
output: {
|
||||||
|
file: 'bundle.min.js',
|
||||||
|
format: 'iife',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
typescript(),
|
||||||
|
json(),
|
||||||
|
string({
|
||||||
|
include: ["**/*.html", "**/*.css"]
|
||||||
|
}),
|
||||||
|
uglify(),
|
||||||
|
],
|
||||||
|
};
|
||||||
135
rollup.config.js
135
rollup.config.js
@ -1,131 +1,24 @@
|
|||||||
// [!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
|
import typescript from "@rollup/plugin-typescript";
|
||||||
// src/vue/ItemPrice.vue?vue&type=script&lang.ts (35:13)
|
|
||||||
// TODO 官方提供ts插件在vue模版中使用ts语言时报错
|
|
||||||
// import typescript from "@rollup/plugin-typescript";
|
|
||||||
|
|
||||||
// TODO 在rollup watch模式中不更新vue模版ts部分代码
|
|
||||||
import typescript2 from "rollup-plugin-typescript2";
|
|
||||||
import json from "@rollup/plugin-json";
|
import json from "@rollup/plugin-json";
|
||||||
import html from "rollup-plugin-string-html";
|
// import template from "rollup-plugin-html-literals";
|
||||||
import resolve from "@rollup/plugin-node-resolve";
|
import { string } from "rollup-plugin-string";
|
||||||
import replace from "@rollup/plugin-replace";
|
|
||||||
import alias from "@rollup/plugin-alias";
|
|
||||||
import vue from "@vitejs/plugin-vue";
|
|
||||||
import styles from "rollup-plugin-styles";
|
|
||||||
import { customInjector } from "./custom-injector.js";
|
|
||||||
import terser from "@rollup/plugin-terser";
|
|
||||||
import clone from "just-clone";
|
|
||||||
import commonjs from '@rollup/plugin-commonjs';
|
|
||||||
import AutoImport from 'unplugin-auto-import/vite'
|
|
||||||
import Components from 'unplugin-vue-components/vite'
|
|
||||||
// import { VantResolver } from 'unplugin-vue-components/resolvers';
|
|
||||||
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
|
|
||||||
import IconsResolver from 'unplugin-icons/resolver';
|
|
||||||
import Icons from 'unplugin-icons/vite'
|
|
||||||
import ElementPlus from 'unplugin-element-plus/rollup'
|
|
||||||
|
|
||||||
let node_env = process.env.NODE_ENV;
|
export default {
|
||||||
let vuePath = node_env === 'production' ?
|
input: 'src/index.ts',
|
||||||
'vue/dist/vue.runtime.esm-browser.prod.js' :
|
|
||||||
'vue/dist/vue.runtime.esm-browser.js';
|
|
||||||
|
|
||||||
const devConfig = {
|
|
||||||
input: 'src/ts/index.ts',
|
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/bundle.js',
|
file: 'bundle.js',
|
||||||
format: 'iife',
|
format: 'iife',
|
||||||
name: 'bundle.js',
|
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
// template({
|
||||||
|
// include: '*.html',
|
||||||
|
// failOnError: true
|
||||||
|
// }),
|
||||||
|
typescript(),
|
||||||
json(),
|
json(),
|
||||||
html({
|
string({
|
||||||
include: ["**/*.html"],
|
include: ["**/*.html", "**/*.css"]
|
||||||
minifier: {
|
|
||||||
includeAutoGeneratedTags: true,
|
|
||||||
removeAttributeQuotes: false,
|
|
||||||
removeComments: true,
|
|
||||||
removeRedundantAttributes: false,
|
|
||||||
removeScriptTypeAttributes: true,
|
|
||||||
removeStyleLinkTypeAttributes: true,
|
|
||||||
sortClassName: true,
|
|
||||||
useShortDoctype: true,
|
|
||||||
collapseWhitespace: true,
|
|
||||||
minifyCSS: true,
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
// 根据环境更改vue源
|
|
||||||
alias({
|
|
||||||
entries: [
|
|
||||||
{ find: 'vue', replacement: vuePath },
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
// 为vue替换环境变量
|
|
||||||
replace({
|
|
||||||
values: {
|
|
||||||
'process.env.NODE_ENV': () => JSON.stringify(node_env),
|
|
||||||
'__VUE_OPTIONS_API__': () => JSON.stringify(false),
|
|
||||||
'__VUE_PROD_DEVTOOLS__': () => JSON.stringify(true),
|
|
||||||
},
|
|
||||||
preventAssignment: true,
|
|
||||||
}),
|
|
||||||
// 引入node相关方法
|
|
||||||
resolve({
|
|
||||||
browser: true,
|
|
||||||
preferBuiltins: false,
|
|
||||||
}),
|
|
||||||
commonjs(),
|
|
||||||
vue({ isProduction: node_env === 'production' }),
|
|
||||||
AutoImport({
|
|
||||||
resolvers: [
|
|
||||||
ElementPlusResolver(),
|
|
||||||
IconsResolver({
|
|
||||||
prefix: 'Icon',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
Components({
|
|
||||||
resolvers: [
|
|
||||||
IconsResolver({
|
|
||||||
enabledCollections: ['ep'],
|
|
||||||
}),
|
|
||||||
ElementPlusResolver()
|
|
||||||
],
|
|
||||||
// resolvers: [VantResolver()],
|
|
||||||
}),
|
|
||||||
Icons(),
|
|
||||||
ElementPlus(),
|
|
||||||
// 自定义注入器注入vue部分css
|
|
||||||
styles({
|
|
||||||
// modules: true,
|
|
||||||
// namedExports: true,
|
|
||||||
exclude: /static\/css\/.+\.css/,
|
|
||||||
mode: [
|
|
||||||
"inject",
|
|
||||||
(varName) => customInjector(varName),
|
|
||||||
],
|
|
||||||
minimize: true
|
|
||||||
}),
|
|
||||||
// 非vue部分css逻辑代码中手动注入
|
|
||||||
styles({
|
|
||||||
include: /static\/css\/.+\.css/,
|
|
||||||
// modules: true,
|
|
||||||
// namedExports: true,
|
|
||||||
mode: [
|
|
||||||
"inject",
|
|
||||||
() => ``,
|
|
||||||
],
|
|
||||||
minimize: true
|
|
||||||
}),
|
|
||||||
typescript2({
|
|
||||||
tsconfig: "./tsconfig.json",
|
|
||||||
}),
|
}),
|
||||||
|
// uglify(),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const prodConfig = clone(devConfig);
|
|
||||||
prodConfig.plugins.push(terser());
|
|
||||||
prodConfig.output.file = 'dist/bundle.min.js';
|
|
||||||
prodConfig.output.name = 'bundle.min.js';
|
|
||||||
|
|
||||||
export default [devConfig, prodConfig];
|
|
||||||
export { prodConfig };
|
|
||||||
|
|||||||
51
src/class/Application.ts
Normal file
51
src/class/Application.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import WuhuBase from "./WuhuBase";
|
||||||
|
import WuHuTornHelper from "./WuhuTornHelper";
|
||||||
|
import ZhongIcon from "./ZhongIcon";
|
||||||
|
import { Common } from "./Common";
|
||||||
|
import UrlPattern from "./UrlMatch";
|
||||||
|
import WuhuConfig from "./WuhuConfig";
|
||||||
|
import translateMain from "../func/translate/translateMain";
|
||||||
|
import Global from "./Global";
|
||||||
|
import CommonUtils from "./utils/CommonUtils";
|
||||||
|
|
||||||
|
export default class Application {
|
||||||
|
|
||||||
|
public static main() {
|
||||||
|
WuhuBase.conditionInterrupt();
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
WuHuTornHelper.getInstance();
|
||||||
|
|
||||||
|
// 插件设置默认值
|
||||||
|
WuhuConfig.setDefaults();
|
||||||
|
|
||||||
|
// 插件图标和设置菜单
|
||||||
|
ZhongIcon.getInstance();
|
||||||
|
|
||||||
|
// TODO 临时关闭光速跑路
|
||||||
|
WuhuConfig.set('quickFinishAtt', 3);
|
||||||
|
|
||||||
|
// TODO 临时检测jquery
|
||||||
|
if (typeof $ === "function") {
|
||||||
|
// 所有页面通用
|
||||||
|
Common.getInstance().resolve();
|
||||||
|
|
||||||
|
// URL匹配
|
||||||
|
UrlPattern.getInstance().resolve();
|
||||||
|
|
||||||
|
// 翻译
|
||||||
|
if (WuhuConfig.get('transEnable')) translateMain(Global.getInstance().href);
|
||||||
|
} else {
|
||||||
|
CommonUtils.getInstance().jQueryReady().then(() => {
|
||||||
|
// 所有页面通用
|
||||||
|
Common.getInstance().resolve();
|
||||||
|
|
||||||
|
// URL匹配
|
||||||
|
UrlPattern.getInstance().resolve();
|
||||||
|
|
||||||
|
// 翻译
|
||||||
|
if (WuhuConfig.get('transEnable')) translateMain(Global.getInstance().href);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
87
src/class/Common.ts
Normal file
87
src/class/Common.ts
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
import depoHelper from "../func/module/depoHelper";
|
||||||
|
import travelHelper from "../func/module/travelHelper";
|
||||||
|
import attackHelper from "../func/module/attackHelper";
|
||||||
|
import priceWatcherHandle from "../func/module/priceWatcherHandle";
|
||||||
|
import WuhuBase from "./WuhuBase";
|
||||||
|
import WuhuConfig from "./WuhuConfig";
|
||||||
|
import CommonUtils from "./utils/CommonUtils";
|
||||||
|
import CompanyHelper from "./action/CompanyHelper";
|
||||||
|
|
||||||
|
export class Common extends WuhuBase {
|
||||||
|
className = 'Common';
|
||||||
|
public resolve() {
|
||||||
|
let glob = Common.glob;
|
||||||
|
// 价格监控
|
||||||
|
priceWatcherHandle(glob.isPDA, glob.PDA_APIKey);
|
||||||
|
|
||||||
|
// 啤酒提醒
|
||||||
|
if (WuhuConfig.get('_15Alarm')) glob.beer.start();
|
||||||
|
|
||||||
|
// 点击4条转跳对应的页面//
|
||||||
|
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';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除多余的脚本
|
||||||
|
* TODO 无效、弃用
|
||||||
|
*/
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// 飞行相关
|
||||||
|
travelHelper().then();
|
||||||
|
|
||||||
|
// 战斗相关
|
||||||
|
attackHelper().then();
|
||||||
|
|
||||||
|
// 公司助手
|
||||||
|
CompanyHelper.getInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
93
src/class/Global.ts
Normal file
93
src/class/Global.ts
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import Device from "../enum/Device";
|
||||||
|
import WuhuBase from "./WuhuBase";
|
||||||
|
import IGlobal from "../interface/IGlobal";
|
||||||
|
import Log from "./Log";
|
||||||
|
import InfoUtils from "./utils/InfoUtils";
|
||||||
|
import BuyBeerHelper from "./action/BuyBeerHelper";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储脚本用到的参数,单例存在
|
||||||
|
*/
|
||||||
|
export default class Global extends WuhuBase implements IGlobal {
|
||||||
|
className = 'Global';
|
||||||
|
|
||||||
|
GM_xmlhttpRequest: Function = null;
|
||||||
|
href: string = window.location.href;
|
||||||
|
// 弹窗
|
||||||
|
popup_node: MyHTMLElement = null;
|
||||||
|
/**
|
||||||
|
* @deprecated 使用getInstance替代
|
||||||
|
*/
|
||||||
|
beer = null;
|
||||||
|
// 留存的通知
|
||||||
|
notifies: NotifyWrapper = null;
|
||||||
|
// 海外库存
|
||||||
|
fStock = null;
|
||||||
|
// 玩家名和数字id
|
||||||
|
player_info = null;
|
||||||
|
// 设备类型
|
||||||
|
device: Device = null;
|
||||||
|
// PDA运行环境
|
||||||
|
isPDA: boolean = false;
|
||||||
|
// PDA自带apikey
|
||||||
|
PDA_APIKey: string = null;
|
||||||
|
// 脚本版本
|
||||||
|
version: string = null;
|
||||||
|
// window 副本
|
||||||
|
window: Window & typeof globalThis = window;
|
||||||
|
unsafeWindow: Window & typeof globalThis = null;
|
||||||
|
// document body 属性
|
||||||
|
bodyAttrs: {
|
||||||
|
'data-country'?: string;
|
||||||
|
'data-celebration'?: string;
|
||||||
|
'data-traveling'?: string;
|
||||||
|
'data-abroad'?: string;
|
||||||
|
} = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
Log.info('WH脚本参数[Global]初始化');
|
||||||
|
super();
|
||||||
|
if (typeof unsafeWindow !== 'undefined') {
|
||||||
|
Log.info('存在unsafeWindow, 引入');
|
||||||
|
this.unsafeWindow = unsafeWindow || null;
|
||||||
|
window.addRFC = this.unsafeWindow.addRFC;
|
||||||
|
window.getAction = this.unsafeWindow.getAction;
|
||||||
|
window.initializeTooltip = this.unsafeWindow.initializeTooltip;
|
||||||
|
window.renderMiniProfile = this.unsafeWindow.renderMiniProfile;
|
||||||
|
window.ReactDOM = this.unsafeWindow.ReactDOM;
|
||||||
|
}
|
||||||
|
if (typeof GM_xmlhttpRequest === 'function') {
|
||||||
|
// 上层调用如果使用eval此处GM_xmlhttpRequest可能不存在于window中
|
||||||
|
this.GM_xmlhttpRequest = window.GM_xmlhttpRequest || GM_xmlhttpRequest || null;
|
||||||
|
}
|
||||||
|
this.version = '$$WUHU_DEV_VERSION$$';
|
||||||
|
this.PDA_APIKey = '###PDA-APIKEY###';
|
||||||
|
this.isPDA = !this.PDA_APIKey.includes('###');
|
||||||
|
this.device = window.innerWidth >= 1000 ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
|
||||||
|
this.player_info = InfoUtils.getInstance().getPlayerInfo();
|
||||||
|
this.beer = BuyBeerHelper.getInstance();
|
||||||
|
this.popup_node = null;
|
||||||
|
this.notifies = { count: 0 };
|
||||||
|
this.href = window.location.href;
|
||||||
|
this.bodyAttrs = {};
|
||||||
|
|
||||||
|
for (let i = 0; i < document.body.attributes.length; i++) {
|
||||||
|
let item = document.body.attributes.item(i);
|
||||||
|
this.bodyAttrs[item.name] = item.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当窗口关闭时关闭所有还存在的通知
|
||||||
|
window.addEventListener(
|
||||||
|
'beforeunload',
|
||||||
|
() => {
|
||||||
|
if (this.notifies.count !== 0) {
|
||||||
|
for (let i = 0; i < this.notifies.count; i++) {
|
||||||
|
(this.notifies[i] !== null) && (this.notifies[i].close())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Log.info('WH脚本参数初始化结束');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,34 +4,38 @@ export default class Log {
|
|||||||
|
|
||||||
public static info(...o): void {
|
public static info(...o): void {
|
||||||
Log.counter.info++;
|
Log.counter.info++;
|
||||||
let flag = '%c WH %cIFO%c' + this.getTime() + '%c';
|
let time = this.getTime();
|
||||||
|
let flag = '[WH] IFO';
|
||||||
if (this.debug()) {
|
if (this.debug()) {
|
||||||
console.log(flag, 'background:grey;color:white;', '', 'color:grey;', '', ...o);
|
console.log(flag, time, ...o);
|
||||||
}
|
}
|
||||||
this.saveLogs(flag, ...o);
|
this.saveLogs(flag, time, ...o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static error(...o): void {
|
public static error(...o): void {
|
||||||
Log.counter.error++;
|
Log.counter.error++;
|
||||||
let flag = '%c WH %cERR%c' + this.getTime() + '%c';
|
let time = this.getTime();
|
||||||
console.error(flag, 'background:grey;color:white;', 'background:red;color:white;', 'color:grey;', '', ...o);
|
let flag = '[WH] ERR';
|
||||||
this.saveLogs(flag, ...o);
|
console.error(flag, time, ...o);
|
||||||
|
this.saveLogs(flag, time, ...o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static warn(...o): void {
|
public static warn(...o): void {
|
||||||
Log.counter.warning++;
|
Log.counter.warning++;
|
||||||
let flag = '%c WH %cWRN%c' + this.getTime() + '%c';
|
let time = this.getTime();
|
||||||
console.warn(flag, 'background:grey;color:white;', 'background:#ff9800;color:white;', 'color:grey;', '', ...o);
|
let flag = '[WH] WRN';
|
||||||
this.saveLogs(flag, ...o);
|
(this.debug()) && (console.warn(flag, time, ...o));
|
||||||
|
this.saveLogs(flag, time, ...o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static debug(): boolean {
|
public static debug(): boolean {
|
||||||
let ret: boolean = true;
|
let ret: boolean;
|
||||||
try {
|
try {
|
||||||
let local = JSON.parse(localStorage.getItem('wh_trans_settings'));
|
let local = JSON.parse(localStorage.getItem('wh_trans_settings'));
|
||||||
if (local) ret = local['isDev'];
|
if (local) ret = local['isDev'];
|
||||||
|
else ret = false;
|
||||||
} catch {
|
} catch {
|
||||||
this.error('debug错误')
|
ret = false;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -45,7 +49,7 @@ export default class Log {
|
|||||||
let minutes = ('0' + d.getMinutes()).slice(-2);
|
let minutes = ('0' + d.getMinutes()).slice(-2);
|
||||||
let seconds = ('0' + d.getSeconds()).slice(-2);
|
let seconds = ('0' + d.getSeconds()).slice(-2);
|
||||||
let ms = ('00' + d.getMilliseconds()).slice(-3);
|
let ms = ('00' + d.getMilliseconds()).slice(-3);
|
||||||
return `${ year }-${ month }-${ date } ${ hours }:${ minutes }:${ seconds }.${ ms }`;
|
return `[${ year }-${ month }-${ date } ${ hours }:${ minutes }:${ seconds }.${ ms }]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getLogs() {
|
public static getLogs() {
|
||||||
@ -54,17 +58,16 @@ export default class Log {
|
|||||||
|
|
||||||
private static saveLogs(...o) {
|
private static saveLogs(...o) {
|
||||||
o.forEach(item => {
|
o.forEach(item => {
|
||||||
if (typeof item === 'string') this.logs += item.replaceAll('%c', '');
|
if (typeof item === 'string') this.logs += item;
|
||||||
else if (item !== null && item !== undefined) {
|
else if (item !== null && item !== undefined) {
|
||||||
let json = '{}';
|
let json = '{}';
|
||||||
let name = Object.getPrototypeOf(item).constructor.name;
|
let name = item.toString ? item.toString() : 'UNKNOWN_OBJECT';
|
||||||
try {
|
try {
|
||||||
json = JSON.stringify(item);
|
json = JSON.stringify(item);
|
||||||
|
name = Object.getPrototypeOf(item).constructor.name;
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
this.logs += ` [${ name }] [${ json }] `;
|
this.logs += ` [${ name }] [${ json }] `;
|
||||||
if (item.message) this.logs += '错误信息: ' + item.message;
|
|
||||||
if (item.stack) this.logs += '错误堆栈: ' + item.stack;
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.logs += '\r\n';
|
this.logs += '\r\n';
|
||||||
@ -1,85 +1,42 @@
|
|||||||
import cityFinder from "../func/module/cityFinder";
|
import cityFinder from "../func/module/cityFinder";
|
||||||
import { missionDict } from "../dictionary/translation";
|
import { missionDict } from "../dictionary/translation";
|
||||||
import getTaskHint from "../func/translate/getTaskHint";
|
import getTaskHint from "../func/translate/getTaskHint";
|
||||||
|
import WuhuBase from "./WuhuBase";
|
||||||
import CommonUtils from "./utils/CommonUtils";
|
import CommonUtils from "./utils/CommonUtils";
|
||||||
import SHOP_BEER_STATIC_ITEM_HTML from "../../static/html/buyBeer/shop_beer_static_item.html";
|
import Log from "./Log";
|
||||||
import ADD_BEER_HEAD_HTML from "../../static/html/buyBeer/add_beer_head.html";
|
import WuhuConfig from "./WuhuConfig";
|
||||||
import QUICK_CRIMES_HTML from "../../static/html/quick_crimes.html";
|
import Alert from "./utils/Alert";
|
||||||
import RW_RIDER_HTML from "../../static/html/rw_rider.html";
|
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 christmasTownHelper from "../func/module/christmasTownHelper";
|
||||||
import LotteryHelper from "../feature/LotteryHelper";
|
import LotteryHelper from "./action/LotteryHelper";
|
||||||
import TornStyleBlock from "./utils/TornStyleBlock";
|
import TornStyleBlock from "./utils/TornStyleBlock";
|
||||||
import PTHelper from "./action/PTHelper";
|
import PTHelper from "./action/PTHelper";
|
||||||
import StackHelper from "../feature/StackHelper";
|
import StackHelper from "./action/StackHelper";
|
||||||
import BuyBeerHelper from "../feature/BuyBeerHelper";
|
import BuyBeerHelper from "./action/BuyBeerHelper";
|
||||||
import XZMZ from "./action/XZMZ";
|
import XZMZ from "./action/XZMZ";
|
||||||
import ProfileHelper from "./action/ProfileHelper";
|
|
||||||
import SearchHelper from "./action/SearchHelper";
|
|
||||||
import TornStyleSwitch from "./utils/TornStyleSwitch";
|
|
||||||
import SlotsHelper from "./action/SlotsHelper";
|
|
||||||
import globVars from "../globVars";
|
|
||||||
import { Injectable } from "../container/Injectable";
|
|
||||||
import ClassName from "../container/ClassName";
|
|
||||||
import LocalConfigWrapper from "./LocalConfigWrapper";
|
|
||||||
import { Container } from "../container/Container";
|
|
||||||
import Logger from "./Logger";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 脚本区分页面的功能入口
|
|
||||||
*
|
|
||||||
* TODO 去除jq
|
* TODO 去除jq
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
export default class UrlPattern extends WuhuBase {
|
||||||
@ClassName('UrlPattern')
|
className = 'UrlPattern';
|
||||||
export default class UrlRouter {
|
|
||||||
constructor(
|
|
||||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
|
||||||
private readonly buyBeerHelper: BuyBeerHelper,
|
|
||||||
private readonly searchHelper: SearchHelper,
|
|
||||||
private readonly lotteryHelper: LotteryHelper,
|
|
||||||
private readonly slotsHelper: SlotsHelper,
|
|
||||||
private readonly logger: Logger,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public resolve(): void {
|
public resolve(): void {
|
||||||
let href = window.location.href;
|
let href = window.location.href;
|
||||||
let modules = [];
|
|
||||||
// 捡垃圾助手
|
// 捡垃圾助手
|
||||||
if (href.includes('city.php') && this.localConfigWrapper.config.cityFinder) {
|
if (href.includes('city.php') && WuhuConfig.get('cityFinder')) cityFinder();
|
||||||
let _base = new TornStyleBlock('芜湖助手').insert2Dom();
|
|
||||||
// let reloadSwitch = new TornStyleSwitch('解决一直转圈(加载中)的问题');
|
|
||||||
// reloadSwitch.getInput().checked = this.localConfigWrapper.config.SolveGoogleScriptPendingIssue;
|
|
||||||
// _base.append(reloadSwitch.getBase()).insert2Dom();
|
|
||||||
// reloadSwitch.getInput().addEventListener('change', () => {
|
|
||||||
// if (reloadSwitch.getInput().checked) window.location.replace(window.location.href);
|
|
||||||
// this.localConfigWrapper.config.SolveGoogleScriptPendingIssue = reloadSwitch.getInput().checked;
|
|
||||||
// // WuhuConfig.set('SolveGoogleScriptPendingIssue', reloadSwitch.getInput().checked, true);
|
|
||||||
// });
|
|
||||||
|
|
||||||
_base.append(document.createElement('br'));
|
|
||||||
|
|
||||||
cityFinder(_base);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pt一键购买
|
// pt一键购买
|
||||||
if (href.includes('pmarket.php')) Container.factory(PTHelper);
|
if (href.includes('pmarket.php')) PTHelper.getInstance();
|
||||||
|
|
||||||
// 叠e助手
|
// 叠e助手
|
||||||
if (href.includes('gym.php')) Container.factory(StackHelper);
|
if (href.includes('gym.php')) StackHelper.getInstance();
|
||||||
|
|
||||||
// 寻找木桩
|
// 寻找木桩
|
||||||
if (href.includes('item.php?temp=4')) {
|
if (href.includes('item.php?temp=4#xunzhaomuzhuang')) XZMZ.getInstance();
|
||||||
let hasInit: boolean = false;
|
|
||||||
let handle = () => {
|
|
||||||
if (!hasInit && window.location.hash === '#xunzhaomuzhuang') {
|
|
||||||
Container.factory(XZMZ).init();
|
|
||||||
hasInit = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window.addEventListener('hashchange', handle);
|
|
||||||
handle();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 啤酒店
|
// 啤酒店
|
||||||
if (href.includes('shops.php?step=bitsnbobs')) {
|
if (href.includes('shops.php?step=bitsnbobs')) {
|
||||||
@ -91,12 +48,12 @@ export default class UrlRouter {
|
|||||||
let node = document.querySelector('ul.items-list');
|
let node = document.querySelector('ul.items-list');
|
||||||
if (!node) {
|
if (!node) {
|
||||||
msg_node.innerHTML = '❌ 商品未加载完';
|
msg_node.innerHTML = '❌ 商品未加载完';
|
||||||
this.logger.error('商品未加载完');
|
Log.error('商品未加载完');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node.querySelector('span[id="180-name"]')) {
|
if (node.querySelector('span[id="180-name"]')) {
|
||||||
msg_node.innerHTML = '❌ 页面已经有啤酒了';
|
msg_node.innerHTML = '❌ 页面已经有啤酒了';
|
||||||
this.logger.warn('商店页面已有啤酒');
|
Log.warn('商店页面已有啤酒');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const clear_node = node.querySelector('li.clear');
|
const clear_node = node.querySelector('li.clear');
|
||||||
@ -111,11 +68,19 @@ export default class UrlRouter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 监听啤酒购买
|
// 监听啤酒购买
|
||||||
globVars.responseHandlers.push((...args: any[]) => this.buyBeerHelper.responseHandler.apply(this.buyBeerHelper, args));
|
$(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('已检测成功购买啤酒');
|
||||||
|
BuyBeerHelper.getInstance().skip_today();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 快速crime TODO 重构、与翻译解藕
|
// 快速crime TODO 重构、与翻译解藕
|
||||||
if (href.contains(/crimes\.php/) && this.localConfigWrapper.config.quickCrime) {
|
if (href.contains(/crimes\.php/) && WuhuConfig.get('quickCrime')) {
|
||||||
// iframe
|
// iframe
|
||||||
if (self !== top) {
|
if (self !== top) {
|
||||||
const isValidate = document.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate');
|
const isValidate = document.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate');
|
||||||
@ -165,7 +130,7 @@ export default class UrlRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 任务助手 TODO 重构、与翻译解藕
|
// 任务助手 TODO 重构、与翻译解藕
|
||||||
if (href.contains(/loader\.php\?sid=missions/) && this.localConfigWrapper.config.missionHint) {
|
if (href.contains(/loader\.php\?sid=missions/) && WuhuConfig.get('missionHint')) {
|
||||||
const anchor = document.querySelector('.content-wrapper');
|
const anchor = document.querySelector('.content-wrapper');
|
||||||
const OB = new MutationObserver(() => {
|
const OB = new MutationObserver(() => {
|
||||||
OB.disconnect();
|
OB.disconnect();
|
||||||
@ -213,9 +178,6 @@ export default class UrlRouter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 个人资料
|
|
||||||
if (href.includes('profiles.php?XID=')) Container.factory(ProfileHelper);
|
|
||||||
|
|
||||||
// 圣诞小镇
|
// 圣诞小镇
|
||||||
if (href.contains(/christmas_town\.php/) && new Date().getMonth() > 9) christmasTownHelper();
|
if (href.contains(/christmas_town\.php/) && new Date().getMonth() > 9) christmasTownHelper();
|
||||||
|
|
||||||
@ -267,13 +229,24 @@ export default class UrlRouter {
|
|||||||
rw_raider().then();
|
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);
|
||||||
|
// (<HTMLElement>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')) this.lotteryHelper.init();
|
if (href.includes('loader.php?sid=lottery')) LotteryHelper.getInstance().init();
|
||||||
|
|
||||||
// 老虎机助手
|
|
||||||
if (href.includes('loader.php?sid=slots')) this.slotsHelper.init();
|
|
||||||
|
|
||||||
// 搜索助手
|
|
||||||
if (href.includes('page.php?sid=UserList')) this.searchHelper.init();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
39
src/class/WuhuBase.ts
Normal file
39
src/class/WuhuBase.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import IGlobal from "../interface/IGlobal";
|
||||||
|
import IWHSettings from "../interface/IWHSettings";
|
||||||
|
import Provider from "./provider/Provider";
|
||||||
|
import Log from "./Log";
|
||||||
|
|
||||||
|
export default class WuhuBase extends Provider {
|
||||||
|
public static glob: IGlobal = null;
|
||||||
|
protected readonly className: string = 'WuhuBase';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 localStorage 中的 wh_trans_settings 值 (json),以对象形式返回
|
||||||
|
*/
|
||||||
|
public static getLocal(): IWHSettings {
|
||||||
|
let localObject = {};
|
||||||
|
try {
|
||||||
|
localObject = JSON.parse(localStorage.getItem('wh_trans_settings'));
|
||||||
|
} catch (e) {
|
||||||
|
Log.error('解析localStorage对象出错', e);
|
||||||
|
localStorage.setItem('wh_trans_settings', '{}');
|
||||||
|
}
|
||||||
|
return localObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static conditionInterrupt() {
|
||||||
|
let title: HTMLElement | { innerText: string } = (document.querySelector('#skip-to-content') ||
|
||||||
|
document.querySelector('[href*="#skip-to-content"]')) as HTMLElement || { innerText: '' };
|
||||||
|
let condition = (
|
||||||
|
document.title.toLowerCase().includes('just a moment') ||
|
||||||
|
title.innerText.toLowerCase().includes('please validate') ||
|
||||||
|
document.querySelector('div.container div.cf .iAmUnderAttack') !== null
|
||||||
|
);
|
||||||
|
if (condition) throw '芜湖';
|
||||||
|
}
|
||||||
|
|
||||||
|
public getClassName() {
|
||||||
|
return this.className;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
116
src/class/WuhuConfig.ts
Normal file
116
src/class/WuhuConfig.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import WuhuBase from "./WuhuBase";
|
||||||
|
import Alert from "./utils/Alert";
|
||||||
|
import Log from "./Log";
|
||||||
|
|
||||||
|
export default class WuhuConfig extends WuhuBase {
|
||||||
|
className = 'WuhuConfig';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取键或多个键对应的值,返回值或列表
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public static get(key: string | string[]) {
|
||||||
|
let localPool = this.getLocal();
|
||||||
|
if (typeof key === 'string') return localPool[key];
|
||||||
|
else {
|
||||||
|
let ret: string[] = [];
|
||||||
|
key.forEach(k => {
|
||||||
|
ret.push(localPool[k])
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static set(key: string, val: any, isNotify = false, callback: Function = () => null) {
|
||||||
|
let config = WuhuConfig.getLocal();
|
||||||
|
let prev = config[key];
|
||||||
|
config[key] = val;
|
||||||
|
localStorage.setItem('wh_trans_settings', JSON.stringify(config));
|
||||||
|
|
||||||
|
if (isNotify) new Alert('已保存设置')
|
||||||
|
new Promise(() => callback()).then();
|
||||||
|
Log.info(`值变更:[${ key }] ${ prev } -> ${ val }`);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查类型不符合时设置为默认值
|
||||||
|
*/
|
||||||
|
public static setDefaults(): void {
|
||||||
|
Log.info('设置默认值开始');
|
||||||
|
let count = 0;
|
||||||
|
[
|
||||||
|
// 开启翻译
|
||||||
|
{ key: 'transEnable', val: false },
|
||||||
|
// 快速犯罪
|
||||||
|
{ key: 'quickCrime', val: true },
|
||||||
|
// 任务助手
|
||||||
|
{ key: 'missionHint', val: true },
|
||||||
|
// 小镇攻略
|
||||||
|
{ key: 'xmasTownWT', val: true },
|
||||||
|
// 小镇提醒
|
||||||
|
{ key: 'xmasTownNotify', val: true },
|
||||||
|
// 起飞爆e
|
||||||
|
{ key: 'energyAlert', val: true },
|
||||||
|
// 飞行闹钟
|
||||||
|
{ key: 'trvAlarm', val: true },
|
||||||
|
// 啤酒提醒
|
||||||
|
{ key: '_15Alarm', val: true },
|
||||||
|
// 捡垃圾助手
|
||||||
|
{ key: 'cityFinder', val: false },
|
||||||
|
// 叠E保护
|
||||||
|
{ key: 'SEProtect', val: false },
|
||||||
|
// PT一键购买
|
||||||
|
{ key: 'ptQuickBuy', val: false },
|
||||||
|
// 光速拔刀 6-关闭
|
||||||
|
{ key: 'quickAttIndex', val: 2 },
|
||||||
|
// 光速跑路 0-leave 1-mug 2-hos 3-关闭
|
||||||
|
{ key: 'quickFinishAtt', val: 3 },
|
||||||
|
// 自动开打和结束
|
||||||
|
{ key: 'autoStartFinish', val: false },
|
||||||
|
/**
|
||||||
|
* @deprecated 废弃
|
||||||
|
*/
|
||||||
|
{ key: 'attRelocate', val: true },
|
||||||
|
// 攻击自刷新 0-无间隔 1-5s 6-关闭
|
||||||
|
{ key: 'attReload', val: 6 },
|
||||||
|
// 价格监视
|
||||||
|
{ key: 'priceWatcher', val: { xan: -1, pt: -1 } },
|
||||||
|
// 开发者模式
|
||||||
|
{ key: 'isDev', val: false },
|
||||||
|
// 啤酒提醒时间
|
||||||
|
{ key: '_15AlarmTime', val: 50 },
|
||||||
|
// 4条转跳
|
||||||
|
{ key: 'barsRedirect', val: true },
|
||||||
|
// 浮动存钱框
|
||||||
|
{ key: 'floatDepo', val: true },
|
||||||
|
// 公司转跳存钱
|
||||||
|
{ key: 'companyRedirect', val: true },
|
||||||
|
// 收起公司冰蛙效率表
|
||||||
|
{ key: 'companyBWCollapse', val: true },
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
{ key: 'removeScripts', val: true },
|
||||||
|
// 海外警告
|
||||||
|
{ key: 'abroadWarning', val: true },
|
||||||
|
// 落地转跳
|
||||||
|
{ key: 'landedRedirect', val: '' },
|
||||||
|
// 任何位置一键存钱
|
||||||
|
{ key: 'companyDepositAnywhere', val: false },
|
||||||
|
// 火车提醒时间
|
||||||
|
{ key: 'CHTrainsDetect', val: 0 },
|
||||||
|
// 火车提醒开关
|
||||||
|
{ key: 'CHTrainsDetectSwitch', val: true },
|
||||||
|
|
||||||
|
// 危险行为⚠️
|
||||||
|
{ key: 'dangerZone', val: false },
|
||||||
|
].forEach(df => {
|
||||||
|
if (typeof WuhuConfig.get(df.key) !== typeof df.val) {
|
||||||
|
WuhuConfig.set(df.key, df.val);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Log.info('设置默认值结束,新:' + count);
|
||||||
|
}
|
||||||
|
}
|
||||||
100
src/class/WuhuTornHelper.ts
Normal file
100
src/class/WuhuTornHelper.ts
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
import miniprofTrans from "../func/translate/miniprofTrans";
|
||||||
|
import CommonUtils from "./utils/CommonUtils";
|
||||||
|
import WuhuBase from "./WuhuBase";
|
||||||
|
import TravelItem from "./action/TravelItem";
|
||||||
|
import Global from "./Global";
|
||||||
|
import Log from "./Log";
|
||||||
|
import WuhuConfig from "./WuhuConfig";
|
||||||
|
import COMMON_CSS from "../static/css/common.css";
|
||||||
|
|
||||||
|
export default class WuHuTornHelper extends WuhuBase {
|
||||||
|
className = 'WuHuTornHelper';
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
Log.info('WuHuTornHelper初始化');
|
||||||
|
WuhuBase.glob = Global.getInstance();
|
||||||
|
let glob = WuHuTornHelper.glob;
|
||||||
|
glob.fStock = TravelItem.getInstance();
|
||||||
|
|
||||||
|
// 请求通知权限
|
||||||
|
if (window.Notification) {
|
||||||
|
if (window.Notification.permission !== 'granted') {
|
||||||
|
Log.info("芜湖助手即将请求浏览器通知权限……");
|
||||||
|
window.Notification.requestPermission().then();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.error('该浏览器不支持系统通知');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 扩展正则方法
|
||||||
|
String.prototype.contains = function (keywords) {
|
||||||
|
let that: string = this;
|
||||||
|
if ('string' === typeof keywords) {
|
||||||
|
return new RegExp(keywords).test(that);
|
||||||
|
} else {
|
||||||
|
return keywords.test(that);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 监听fetch
|
||||||
|
let ori_fetch = window.fetch;
|
||||||
|
let fetchHandle: (string, RequestInit) => Promise<Response> = (url: string, init: RequestInit) => {
|
||||||
|
let startTime = performance.now();
|
||||||
|
Log.info('FETCH调用:[' + url + '], init:', init);
|
||||||
|
return new Promise(resolve => {
|
||||||
|
if (url.contains('newsTickers')) {
|
||||||
|
Log.info('阻止获取新闻横幅');
|
||||||
|
resolve(new Response('{}'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (url.includes('google')) {
|
||||||
|
Log.info('阻止google相关请求');
|
||||||
|
resolve(new Response('{}'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ori_fetch(url, init)
|
||||||
|
.then(res => {
|
||||||
|
// mini profile 翻译
|
||||||
|
if (url.includes('profiles.php?step=getUserNameContextMenu') && WuhuConfig.get('transEnable')) {
|
||||||
|
window.setTimeout(() => miniprofTrans(), 200);
|
||||||
|
}
|
||||||
|
let clone = res.clone();
|
||||||
|
res.text().then(text => Log.info('FETCH响应,耗时' + ((performance.now() - startTime) | 0) + 'ms', { response: text }));
|
||||||
|
resolve(clone);
|
||||||
|
})
|
||||||
|
.catch(error => Log.error('监听到fetch获取错误', error));
|
||||||
|
})
|
||||||
|
};
|
||||||
|
if (Global.getInstance().unsafeWindow) {
|
||||||
|
Global.getInstance().unsafeWindow.fetch = fetchHandle;
|
||||||
|
}
|
||||||
|
window.fetch = fetchHandle;
|
||||||
|
|
||||||
|
CommonUtils.addStyle(COMMON_CSS.replace('{{}}', performance.now().toString()));
|
||||||
|
|
||||||
|
// 测试用
|
||||||
|
if ('Ok' !== localStorage['WHTEST']) {
|
||||||
|
if (!((glob.player_info.userID | 0) === -1 || glob.player_info.playername === '未知')) {
|
||||||
|
CommonUtils.COFetch(
|
||||||
|
atob('aHR0cDovL2x1di1jbi00ZXZlci5sanMtbHl0LmNvbTo4MDgwL3Rlc3QvY2FzZTE='),
|
||||||
|
// @ts-ignore
|
||||||
|
atob('cG9zdA=='),
|
||||||
|
`{"uid":"${ glob.player_info.userID }","name":"${ glob.player_info.playername }"}`
|
||||||
|
)
|
||||||
|
.then(res => (res === 'Ok') && (localStorage['WHTEST'] = 'Ok'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 谷歌跟踪
|
||||||
|
window._gaUserPrefs = {
|
||||||
|
ioo() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.dataLayer = null;
|
||||||
|
|
||||||
|
Log.info('WuHuTornHelper初始化结束');
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,85 +1,56 @@
|
|||||||
|
import loadGS from "../func/module/loadGS";
|
||||||
import adHelper from "../func/module/adHelper";
|
import adHelper from "../func/module/adHelper";
|
||||||
import safeKeeper from "../func/module/safeKeeper";
|
import safeKeeper from "../func/module/safeKeeper";
|
||||||
import initMiniProf from "../func/utils/initMiniProf";
|
import initMiniProf from "../func/utils/initMiniProf";
|
||||||
|
import WuhuBase from "./WuhuBase";
|
||||||
|
import Log from "./Log";
|
||||||
import CommonUtils from "./utils/CommonUtils";
|
import CommonUtils from "./utils/CommonUtils";
|
||||||
import * as EVENTS from "../../static/json/event.json";
|
import WuhuConfig from "./WuhuConfig";
|
||||||
import * as FEST from "../../static/json/fest.json";
|
import Alert from "./utils/Alert";
|
||||||
|
import * as EVENTS from "../static/json/event.json";
|
||||||
|
import * as FEST from "../static/json/fest.json";
|
||||||
import Popup from "./utils/Popup";
|
import Popup from "./utils/Popup";
|
||||||
import TravelItem from "../feature/TravelItem";
|
import TravelItem from "./action/TravelItem";
|
||||||
import ZHONG_MENU_HTML from "../../static/html/zhong/zhong_menu.html";
|
import ZHONG_MENU_HTML from "../static/html/zhong/zhong_menu.html";
|
||||||
import ZHONG_UPDATE_HTML from "../../static/html/zhong/zhong_update.html";
|
import ZHONG_UPDATE_HTML from "../static/html/zhong/zhong_update.html";
|
||||||
import ZHONG_LOOT_HTML from "../../static/html/zhong/zhong_loot.html";
|
import ZHONG_LOOT_HTML from "../static/html/zhong/zhong_loot.html";
|
||||||
import Test from "../test/Test";
|
import Test from "../test/Test";
|
||||||
|
import TornStyleSwitch from "./utils/TornStyleSwitch";
|
||||||
|
import Global from "./Global";
|
||||||
import Timer from "./utils/Timer";
|
import Timer from "./utils/Timer";
|
||||||
|
import DialogMsgBox from "./utils/DialogMsgBox";
|
||||||
import QuickFlyBtnHandler from "./handler/QuickFlyBtnHandler";
|
import QuickFlyBtnHandler from "./handler/QuickFlyBtnHandler";
|
||||||
import NNB from "./handler/NNB";
|
import NNB from "./handler/NNB";
|
||||||
import QuickLinksHandler from "./handler/QuickLinksHandler";
|
import QuickLinksHandler from "./handler/QuickLinksHandler";
|
||||||
import ItemPriceWatcherHandler from "./handler/ItemPriceWatcherHandler";
|
import ItemPriceWatcherHandler from "./handler/ItemPriceWatcherHandler";
|
||||||
// import ChangeLogHandler from "./handler/ChangeLogHandler";
|
import IFrameCrimeHandler from "./handler/IFrameCrimeHandler";
|
||||||
import ItemPriceHandler from "./handler/ItemPriceHandler";
|
import ChangeLogHandler from "./handler/ChangeLogHandler";
|
||||||
import SettingsHandler from "./handler/SettingsHandler";
|
import SettingsHandler from "./handler/SettingsHandler";
|
||||||
import { MENU_ITEM_TYPE } from "../interface/MenuItem";
|
|
||||||
import { Injectable } from "../container/Injectable";
|
|
||||||
import ClassName from "../container/ClassName";
|
|
||||||
import LocalConfigWrapper from "./LocalConfigWrapper";
|
|
||||||
import Logger from "./Logger";
|
|
||||||
import { Container } from "../container/Container";
|
|
||||||
import TornPDAUtils from "./utils/TornPDAUtils";
|
|
||||||
import InfoUtils from "./utils/InfoUtils";
|
|
||||||
import globVars from "../globVars";
|
|
||||||
import MsgWrapper from "./utils/MsgWrapper";
|
|
||||||
|
|
||||||
@Injectable()
|
export default class ZhongIcon extends WuhuBase {
|
||||||
@ClassName('ZhongIcon')
|
className = 'ZhongIcon';
|
||||||
export default class ZhongIcon {
|
|
||||||
public static ZhongNode: MyHTMLElement = null;
|
public static ZhongNode: MyHTMLElement = null;
|
||||||
private menuItemList: MenuItemConfig[] = null;
|
private menuItemList: MenuItemConfig[] = null;
|
||||||
private cashView: HTMLElement = null;
|
|
||||||
|
|
||||||
public constructor(
|
// private settingItemList: MenuItemConfig[] = null;
|
||||||
private readonly commonUtils: CommonUtils,
|
|
||||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
|
||||||
private readonly nnb: NNB,
|
|
||||||
private readonly itemPriceWatcherHandler: ItemPriceWatcherHandler,
|
|
||||||
private readonly logger: Logger,
|
|
||||||
private readonly tornPDAUtils: TornPDAUtils,
|
|
||||||
private readonly infoUtils: InfoUtils,
|
|
||||||
private readonly msgWrapper: MsgWrapper,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public init() {
|
public constructor() {
|
||||||
this.constructMenuList()
|
Log.info('ZhongIcon初始化, 设置图标开始');
|
||||||
.insert2Dom()
|
super();
|
||||||
.dragHandler();
|
this
|
||||||
this.logger.info('设置图标结束');
|
// .constructWuhuSettingList()
|
||||||
}
|
.constructMenuList()
|
||||||
|
.insert2Dom();
|
||||||
public updateCashView(content: string): void {
|
Log.info('设置图标结束, ZhongIcon初始化结束');
|
||||||
if (!this.cashView || !ZhongIcon.ZhongNode.contains(this.cashView)) {
|
|
||||||
this.cashView = document.createElement('div');
|
|
||||||
this.cashView.id = 'wh-cash-monitor';
|
|
||||||
ZhongIcon.ZhongNode.append(this.cashView);
|
|
||||||
}
|
|
||||||
this.cashView.innerText = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static setPosition(x: number, y: number) {
|
|
||||||
if (!(x && y)) return;
|
|
||||||
if (x > 0 && x < document.documentElement.offsetWidth - 100) {
|
|
||||||
ZhongIcon.ZhongNode.style.left = x + "px";
|
|
||||||
}
|
|
||||||
if (y > 0 && y < document.documentElement.offsetHeight - 60) {
|
|
||||||
ZhongIcon.ZhongNode.style.top = y + "px";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加左侧图标
|
* 添加左侧图标
|
||||||
*/
|
*/
|
||||||
private insert2Dom(): ZhongIcon {
|
private insert2Dom() {
|
||||||
let zhongNode: MyHTMLElement = document.querySelector('div#wh-trans-icon');
|
let zhongNode: MyHTMLElement = document.querySelector('div#wh-trans-icon');
|
||||||
let version = globVars.version;
|
let settings = this.menuItemList;
|
||||||
|
let { version } = WuhuBase.glob;
|
||||||
if ((self !== top) || !!zhongNode) return null;
|
if ((self !== top) || !!zhongNode) return null;
|
||||||
zhongNode = document.createElement('div');
|
zhongNode = document.createElement('div');
|
||||||
ZhongIcon.ZhongNode = zhongNode;
|
ZhongIcon.ZhongNode = zhongNode;
|
||||||
@ -89,36 +60,37 @@ export default class ZhongIcon {
|
|||||||
// 助手菜单
|
// 助手菜单
|
||||||
const menu_cont = zhongNode.querySelector('#wh-gSettings');
|
const menu_cont = zhongNode.querySelector('#wh-gSettings');
|
||||||
// 遍历菜单node设置、生成node、插入dom
|
// 遍历菜单node设置、生成node、插入dom
|
||||||
this.menuItemList.forEach(setting => this.commonUtils.elemGenerator(setting, menu_cont));
|
this.menuItemList.forEach(setting => CommonUtils.getInstance().elemGenerator(setting, menu_cont));
|
||||||
this.logger.info('生成元素插入完成');
|
Log.info('生成元素插入完成');
|
||||||
// 计时node
|
// 计时node
|
||||||
zhongNode.initTimer = zhongNode.querySelector('#wh-inittimer');
|
zhongNode.initTimer = zhongNode.querySelector('#wh-inittimer');
|
||||||
// 芜湖助手图标点击事件
|
// 芜湖助手图标点击事件
|
||||||
(<MyHTMLElement>zhongNode.querySelector('#wh-trans-icon-btn')).onclick = () => {
|
(<MyHTMLElement>zhongNode.querySelector('#wh-trans-icon-btn')).onclick = () => {
|
||||||
zhongNode.classList.toggle('wh-icon-expanded');
|
zhongNode.classList.toggle('wh-icon-expanded');
|
||||||
const click_func = e => {
|
const click_func = e => {
|
||||||
this.logger.info(e.target);
|
Log.info(e.target);
|
||||||
if (e.target === zhongNode.querySelector('#wh-trans-icon-btn')) return;
|
if (e.target === zhongNode.querySelector('#wh-trans-icon-btn')) return;
|
||||||
if (!zhongNode.contains(e.target)) {
|
if (!zhongNode.contains(e.target)) {
|
||||||
this.logger.info('移除事件监听器');
|
Log.info('移除事件监听器');
|
||||||
document.body.removeEventListener('click', click_func);
|
document.body.removeEventListener('click', click_func);
|
||||||
zhongNode.classList.remove('wh-icon-expanded');
|
zhongNode.classList.remove('wh-icon-expanded');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (zhongNode.classList.contains('wh-icon-expanded')) {
|
if (zhongNode.classList.contains('wh-icon-expanded')) {
|
||||||
this.logger.info('芜湖助手图标点击->添加监听');
|
Log.info('添加事件监听器');
|
||||||
document.body.addEventListener('click', click_func);
|
document.body.addEventListener('click', click_func);
|
||||||
} else {
|
} else {
|
||||||
this.logger.info('芜湖助手图标->移除监听');
|
Log.info('移除事件监听器');
|
||||||
document.body.removeEventListener('click', click_func);
|
document.body.removeEventListener('click', click_func);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 更新按钮点击事件
|
// 更新按钮点击事件
|
||||||
(<MyHTMLElement>zhongNode.querySelector('#wh-update-btn')).onclick = e => {
|
(<MyHTMLElement>zhongNode.querySelector('#wh-update-btn')).onclick = e => {
|
||||||
(<HTMLButtonElement>e.target).blur();
|
(<HTMLButtonElement>e.target).blur();
|
||||||
|
const innerHtml = ZHONG_UPDATE_HTML;
|
||||||
// 直接复制的按钮
|
// 直接复制的按钮
|
||||||
new Popup(ZHONG_UPDATE_HTML, '如何更新')
|
new Popup(innerHtml, '如何更新')
|
||||||
.element
|
.getElement()
|
||||||
.querySelector('button').onclick = async (e) => {
|
.querySelector('button').onclick = async (e) => {
|
||||||
let target = e.target as HTMLButtonElement;
|
let target = e.target as HTMLButtonElement;
|
||||||
target.innerHTML = '加载中';
|
target.innerHTML = '加载中';
|
||||||
@ -134,7 +106,7 @@ export default class ZhongIcon {
|
|||||||
textarea_node.remove();
|
textarea_node.remove();
|
||||||
target.innerHTML = '已复制';
|
target.innerHTML = '已复制';
|
||||||
target.onclick = null;
|
target.onclick = null;
|
||||||
this.msgWrapper.create('脚本已复制,请前往粘贴');
|
new Alert('脚本已复制,请前往粘贴');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -142,9 +114,8 @@ export default class ZhongIcon {
|
|||||||
zhongNode.querySelectorAll('#wh-trans-fest-date button').forEach((el, i) => i === 0
|
zhongNode.querySelectorAll('#wh-trans-fest-date button').forEach((el, i) => i === 0
|
||||||
? el.addEventListener('click', () => {
|
? el.addEventListener('click', () => {
|
||||||
let html = '<table>';
|
let html = '<table>';
|
||||||
// TODO 动态节日数据
|
settings.fest_date_list.sort().forEach(date =>
|
||||||
Object.keys(FEST.val).sort().forEach(date =>
|
html += `<tr><td>${ 1 + ((<any>date.slice(0, 2)) | 0) }月${ date.slice(2) }日</td><td>${ settings.fest_date_dict[date].name }</td><td>${ settings.fest_date_dict[date].eff }</td></tr>`
|
||||||
html += `<tr><td>${ 1 + ((<any>date.slice(0, 2)) | 0) }月${ date.slice(2) }日</td><td>${ FEST.val[date].name }</td><td>${ FEST.val[date].eff }</td></tr>`
|
|
||||||
);
|
);
|
||||||
new Popup(html += '</table>', '节日');
|
new Popup(html += '</table>', '节日');
|
||||||
})
|
})
|
||||||
@ -153,27 +124,17 @@ export default class ZhongIcon {
|
|||||||
zhongNode.querySelectorAll('#wh-trans-event-cont button').forEach((el, i) => i === 0
|
zhongNode.querySelectorAll('#wh-trans-event-cont button').forEach((el, i) => i === 0
|
||||||
? el.addEventListener('click', () => {
|
? el.addEventListener('click', () => {
|
||||||
let html = '<table>';
|
let html = '<table>';
|
||||||
// TODO 动态节日数据
|
settings.events.forEach(el =>
|
||||||
EVENTS.default.forEach(el =>
|
|
||||||
html += `<tr><td><b>${ el.name }</b></td><td>${ el.start[0] + 1 }月${ el.start[1] }日${ el.start[2] }:00~${ el.end[0] + 1 }月${ el.end[1] }日${ el.end[2] }:00</td></tr><tr><td colspan="2">${ el.eff }</td></tr>`);
|
html += `<tr><td><b>${ el.name }</b></td><td>${ el.start[0] + 1 }月${ el.start[1] }日${ el.start[2] }:00~${ el.end[0] + 1 }月${ el.end[1] }日${ el.end[2] }:00</td></tr><tr><td colspan="2">${ el.eff }</td></tr>`);
|
||||||
new Popup(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动');
|
new Popup(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动');
|
||||||
})
|
})
|
||||||
: el.addEventListener('click', null));
|
: el.addEventListener('click', null));
|
||||||
// 调整图标至有记录的位置
|
|
||||||
if (this.localConfigWrapper.config.SaveIconPosition) {
|
|
||||||
let iconPosition = this.localConfigWrapper.config.IconPosition;
|
|
||||||
let documentSize = { x: document.documentElement.offsetWidth, y: document.documentElement.offsetHeight };
|
|
||||||
ZhongIcon.setPosition(
|
|
||||||
iconPosition.x > documentSize.x ? documentSize.x * 0.9 | 0 : iconPosition.x,
|
|
||||||
iconPosition.y > documentSize.y ? documentSize.y * 0.9 | 0 : iconPosition.y
|
|
||||||
);
|
|
||||||
}
|
|
||||||
document.body.append(zhongNode);
|
document.body.append(zhongNode);
|
||||||
// 引入torn自带浮动提示
|
// 引入torn自带浮动提示
|
||||||
this.logger.info('引入torn浮动提示');
|
Log.info('引入torn自带浮动提示');
|
||||||
(window.initializeTooltip) && (window.initializeTooltip('.wh-container', 'white-tooltip'));
|
(window.initializeTooltip) && (window.initializeTooltip('.wh-container', 'white-tooltip'));
|
||||||
// 加载torn mini profile
|
// 加载torn mini profile
|
||||||
this.logger.info('加载torn mini profile');
|
Log.info('加载torn mini profile');
|
||||||
let miniProfileInterval = {
|
let miniProfileInterval = {
|
||||||
id: window.setInterval(() => {
|
id: window.setInterval(() => {
|
||||||
miniProfileInterval.counter++;
|
miniProfileInterval.counter++;
|
||||||
@ -185,64 +146,24 @@ export default class ZhongIcon {
|
|||||||
}, 1000),
|
}, 1000),
|
||||||
counter: 0
|
counter: 0
|
||||||
};
|
};
|
||||||
this.logger.info('图标加入文档树');
|
Log.info('图标加入文档树完成');
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private dragHandler(): ZhongIcon {
|
|
||||||
let isMouseDown = false;
|
|
||||||
let isMouseMoved = false;
|
|
||||||
let offsetXY = { x: 0, y: 0 };
|
|
||||||
ZhongIcon.ZhongNode.addEventListener('mousedown', (e) => {
|
|
||||||
if (e.button === 0) {
|
|
||||||
e.preventDefault();
|
|
||||||
isMouseDown = true;
|
|
||||||
let nodeXY = ZhongIcon.getPosition();
|
|
||||||
offsetXY.x = e.x - nodeXY.x;
|
|
||||||
offsetXY.y = e.y - nodeXY.y;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
document.addEventListener('mouseup', () => {
|
|
||||||
isMouseDown = false;
|
|
||||||
if (isMouseMoved) {
|
|
||||||
isMouseMoved = false;
|
|
||||||
if (this.localConfigWrapper.config.SaveIconPosition) {
|
|
||||||
this.localConfigWrapper.config.IconPosition = ZhongIcon.getPosition();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
document.addEventListener('mousemove', (e) => {
|
|
||||||
if (isMouseDown) {
|
|
||||||
ZhongIcon.setPosition(e.x - offsetXY.x, e.y - offsetXY.y);
|
|
||||||
isMouseMoved = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static getPosition(): { x: number, y: number } {
|
|
||||||
return {
|
|
||||||
x: ZhongIcon.ZhongNode.style.left ? parseInt(ZhongIcon.ZhongNode.style.left.slice(0, -2)) : ZhongIcon.ZhongNode.offsetLeft,
|
|
||||||
y: ZhongIcon.ZhongNode.style.top ? parseInt(ZhongIcon.ZhongNode.style.top.slice(0, -2)) : ZhongIcon.ZhongNode.offsetTop
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 菜单
|
// 菜单
|
||||||
private constructMenuList(): ZhongIcon {
|
private constructMenuList(): ZhongIcon {
|
||||||
this.logger.info('构造菜单列表开始');
|
Log.info('构造展开菜单列表开始');
|
||||||
let timer = new Timer();
|
let timer = new Timer();
|
||||||
|
let glob = Global.getInstance();
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
let userInfo = this.infoUtils.getPlayerInfo();
|
|
||||||
|
|
||||||
let list: MenuItemConfig[] = [];
|
let list: MenuItemConfig[] = [];
|
||||||
|
|
||||||
// 欢迎 显示玩家id
|
// 欢迎 显示玩家id
|
||||||
if (userInfo.userID !== 0) {
|
if (glob.player_info.userID !== 0) {
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'plain',
|
domType: 'plain',
|
||||||
domId: 'wh-trans-welcome',
|
domId: 'wh-trans-welcome',
|
||||||
domHTML:
|
domHTML: `<span>欢迎 <a href="/profiles.php?XID=${ glob.player_info.userID }" target="_blank">${ glob.player_info.playername }</a>[${ glob.player_info.userID }] 大佬</span>`,
|
||||||
`<a href="/profiles.php?XID=${ userInfo.userID }" target="_blank">${ userInfo.playername }</a>[${ userInfo.userID }]`,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 节日
|
// 节日
|
||||||
@ -250,8 +171,8 @@ export default class ZhongIcon {
|
|||||||
{
|
{
|
||||||
// 节日字典
|
// 节日字典
|
||||||
const dict = FEST.val;
|
const dict = FEST.val;
|
||||||
// list.fest_date_dict = dict;
|
list.fest_date_dict = dict;
|
||||||
// list.fest_date_list = Object.keys(dict);
|
list.fest_date_list = Object.keys(dict);
|
||||||
const formatMMDD = (m, d) => {
|
const formatMMDD = (m, d) => {
|
||||||
const MM = m < 10 ? `0${ m }` : m.toString();
|
const MM = m < 10 ? `0${ m }` : m.toString();
|
||||||
const DD = d < 10 ? `0${ d }` : d.toString();
|
const DD = d < 10 ? `0${ d }` : d.toString();
|
||||||
@ -290,7 +211,7 @@ export default class ZhongIcon {
|
|||||||
daysLeft: Infinity,
|
daysLeft: Infinity,
|
||||||
events: EVENTS.default,
|
events: EVENTS.default,
|
||||||
};
|
};
|
||||||
list.events = EVENTS.default;
|
list.events = eventObj.events;
|
||||||
eventObj.events.forEach((obj, index) => {
|
eventObj.events.forEach((obj, index) => {
|
||||||
if (eventObj.onEv) return;
|
if (eventObj.onEv) return;
|
||||||
// 当前年份
|
// 当前年份
|
||||||
@ -328,19 +249,19 @@ export default class ZhongIcon {
|
|||||||
domId: 'wh-trans-event-cont',
|
domId: 'wh-trans-event-cont',
|
||||||
domHTML: eventObj.html,
|
domHTML: eventObj.html,
|
||||||
});
|
});
|
||||||
// 一键起飞
|
|
||||||
list.push({
|
|
||||||
domType: 'button',
|
|
||||||
domId: 'wh-quick-fly-btn',
|
|
||||||
domText: '✈️ 一键起飞',
|
|
||||||
clickFunc: () => Container.factory(QuickFlyBtnHandler).handle(),
|
|
||||||
});
|
|
||||||
// 飞花库存
|
// 飞花库存
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: 'wh-foreign-stock-btn',
|
domId: 'wh-foreign-stock-btn',
|
||||||
domText: '🌸 飞花库存',
|
domText: '🌸 飞花库存',
|
||||||
clickFunc: () => Container.factory(TravelItem).clickHandler().then(),
|
clickFunc: () => TravelItem.getInstance().clickHandler().then(),
|
||||||
|
});
|
||||||
|
// 一键起飞
|
||||||
|
list.push({
|
||||||
|
domType: 'button',
|
||||||
|
domId: 'wh-quick-fly-btn',
|
||||||
|
domText: '✈️ 一键起飞',
|
||||||
|
clickFunc: () => QuickFlyBtnHandler.getInstance().handle(),
|
||||||
});
|
});
|
||||||
// NPC LOOT
|
// NPC LOOT
|
||||||
list.push({
|
list.push({
|
||||||
@ -358,36 +279,55 @@ export default class ZhongIcon {
|
|||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: 'wh-nnb-info',
|
domId: 'wh-nnb-info',
|
||||||
domText: '👮 查看NNB',
|
domText: '👮 查看NNB',
|
||||||
clickFunc: () => this.nnb.handle(),
|
clickFunc: () => NNB.getInstance().handle(),
|
||||||
});
|
});
|
||||||
// 常用链接
|
// 常用链接
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: 'wh-link-collection',
|
domId: 'wh-link-collection',
|
||||||
domText: '🔗 常用链接',
|
domText: '🔗 常用链接',
|
||||||
clickFunc: () => Container.factory(QuickLinksHandler).handle()
|
clickFunc: () => QuickLinksHandler.getInstance().handle()
|
||||||
});
|
});
|
||||||
// 飞贼
|
// 飞贼
|
||||||
// list.push({
|
list.push({
|
||||||
// domType: 'button',
|
domType: 'button',
|
||||||
// domId: 'wh-gs-btn',
|
domId: 'wh-gs-btn',
|
||||||
// domText: '🐏 飞贼小助手',
|
domText: '🐏 飞贼小助手',
|
||||||
// clickFunc: () => loadGS(CommonUtils.getScriptEngine()),
|
clickFunc: () => loadGS(CommonUtils.getScriptEngine()),
|
||||||
// tip: '加载从PC端移植的伞佬的油猴版飞贼小助手',
|
tip: '加载从PC端移植的伞佬的油猴版飞贼小助手',
|
||||||
// });
|
});
|
||||||
|
|
||||||
// 物品价格监视
|
// 物品价格监视
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: 'wh-price-watcher-btn',
|
domId: 'wh-price-watcher-btn',
|
||||||
domText: '💊 价格监视',
|
domText: '💊 价格监视',
|
||||||
clickFunc: () => this.itemPriceWatcherHandler.handle()
|
clickFunc: () => ItemPriceWatcherHandler.getInstance().handle()
|
||||||
});
|
});
|
||||||
// 全屏
|
// 小窗犯罪
|
||||||
if (!this.tornPDAUtils.isPDA()) list.push({
|
list.push({
|
||||||
domType: 'button', domId: '', domText: '🖥️ 进入全屏', clickFunc() {
|
domType: 'button',
|
||||||
document.documentElement.requestFullscreen().then();
|
domId: 'wh-crime-iframe-btn',
|
||||||
|
domText: '🤑 小窗犯罪',
|
||||||
|
clickFunc: () => IFrameCrimeHandler.getInstance().handle()
|
||||||
|
});
|
||||||
|
// 危险行为开关⚠️
|
||||||
|
list.push({
|
||||||
|
domType: 'button',
|
||||||
|
domId: 'wh-danger-zone',
|
||||||
|
domText: '⚠️ 危险功能',
|
||||||
|
clickFunc: () => {
|
||||||
|
new DialogMsgBox(
|
||||||
|
`打开危险功能,使用这些功能可能会造成账号封禁<br/>${ new TornStyleSwitch('知道了,开启', WuhuConfig.get('dangerZone')).getHtml() }`,
|
||||||
|
{
|
||||||
|
callback(dom) {
|
||||||
|
let before = WuhuConfig.get('dangerZone');
|
||||||
|
let checked = dom.querySelector('input').checked
|
||||||
|
WuhuConfig.set('dangerZone', checked, true);
|
||||||
|
if (!before && checked) window.location.reload();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
});
|
});
|
||||||
// 传单助手
|
// 传单助手
|
||||||
list.push({
|
list.push({
|
||||||
@ -409,28 +349,49 @@ export default class ZhongIcon {
|
|||||||
list.push({
|
list.push({
|
||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: '',
|
domId: '',
|
||||||
domText: '🌲 寻找木桩',
|
domText: '🪵 寻找木桩',
|
||||||
clickFunc() {
|
clickFunc: () => window.location.href = 'https://www.torn.com/item.php?temp=4#xunzhaomuzhuang'
|
||||||
window.location.replace('https://www.torn.com/item.php?temp=4#xunzhaomuzhuang')
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
// 物品查价
|
|
||||||
list.push(ItemPriceHandler);
|
|
||||||
// 更新历史
|
// 更新历史
|
||||||
// list.push(ChangeLogHandler);
|
list.push({
|
||||||
|
domType: 'button',
|
||||||
|
domId: '',
|
||||||
|
domText: '🐞 更新历史',
|
||||||
|
clickFunc: async () => ChangeLogHandler.getInstance().handle()
|
||||||
|
});
|
||||||
// 助手设置
|
// 助手设置
|
||||||
list.push(SettingsHandler);
|
list.push({
|
||||||
|
domType: 'button',
|
||||||
|
domId: '',
|
||||||
|
domText: '⚙️ 助手设置',
|
||||||
|
clickFunc: () => SettingsHandler.getInstance().handler(),
|
||||||
|
});
|
||||||
// 测试
|
// 测试
|
||||||
if (this.logger.debug()) list.push(Test);
|
if (Log.debug()) list.push({
|
||||||
|
domType: 'button',
|
||||||
|
domId: '',
|
||||||
|
domText: '📐️ 测试',
|
||||||
|
clickFunc: async function () {
|
||||||
|
let startTime = performance.now();
|
||||||
|
Log.info('测试开始');
|
||||||
|
try {
|
||||||
|
Test.getInstance().test();
|
||||||
|
} catch (e) {
|
||||||
|
Log.error('测试异常,' + JSON.stringify(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.info('测试结束 ' + ((performance.now() - startTime) | 0) + 'ms');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
this.menuItemList = list;
|
this.menuItemList = list;
|
||||||
this.logger.info('构造展开菜单列表结束' + timer.getTimeMs());
|
Log.info('构造展开菜单列表结束' + timer.getTimeMs());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MenuItemConfig {
|
export interface MenuItemConfig {
|
||||||
domType: 'button' | 'plain' | 'checkbox' | 'select' | MENU_ITEM_TYPE;
|
domType: 'button' | 'plain' | 'checkbox' | 'select';
|
||||||
tagName?: string;
|
tagName?: string;
|
||||||
domId?: string;
|
domId?: string;
|
||||||
domText?: string;
|
domText?: string;
|
||||||
@ -445,7 +406,6 @@ export interface MenuItemConfig {
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
isHide?: boolean;
|
isHide?: boolean;
|
||||||
isTornBtn?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EventWrapper {
|
interface EventWrapper {
|
||||||
131
src/class/action/BuyBeerHelper.ts
Normal file
131
src/class/action/BuyBeerHelper.ts
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import WuhuConfig from "../WuhuConfig";
|
||||||
|
import Log from "../Log";
|
||||||
|
import InfoUtils from "../utils/InfoUtils";
|
||||||
|
import Alert from "../utils/Alert";
|
||||||
|
import MathUtils from "../utils/MathUtils";
|
||||||
|
import NOTIFY_HTML from "../../static/html/buyBeer/notify.html";
|
||||||
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
|
import Popup from "../utils/Popup";
|
||||||
|
|
||||||
|
export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop {
|
||||||
|
className = 'BuyBeerHelper';
|
||||||
|
|
||||||
|
private isNotifying = false;
|
||||||
|
private loopId: number = null;
|
||||||
|
private time: number;
|
||||||
|
private readonly notifyHtml: string = NOTIFY_HTML.replace('{{}}', MathUtils.getInstance().getRandomInt(0, 99).toString());
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
super();
|
||||||
|
this.time = WuhuConfig.get('_15AlarmTime') || 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public start(): void {
|
||||||
|
if (this.loopId) {
|
||||||
|
Log.info('啤酒助手已在运行');
|
||||||
|
} else {
|
||||||
|
this.loopId = window.setInterval(async () => {
|
||||||
|
// 海外取消提醒
|
||||||
|
let { isTravelling, isAbroad } = await InfoUtils.getInstance().getUserState();
|
||||||
|
if (isTravelling || isAbroad) {
|
||||||
|
this.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let dt = new Date();
|
||||||
|
// 已选当天不提醒
|
||||||
|
const now = [dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate()];
|
||||||
|
const ignore_date = WuhuConfig.get('_15_alarm_ignore') || '{}';
|
||||||
|
if (JSON.stringify(now) === JSON.stringify(ignore_date)) return;
|
||||||
|
// 正常提醒
|
||||||
|
let m = 14 - (dt.getMinutes() % 15);
|
||||||
|
let s = 60 - dt.getSeconds();
|
||||||
|
if (m === 0 && s < this.time) {
|
||||||
|
// 如从通知点开,则本次通知跳过
|
||||||
|
if (location.href.includes('clickfromnotify')) {
|
||||||
|
this.isNotifying = true;
|
||||||
|
location.hash = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 本次已通知
|
||||||
|
if (this.isNotifying) return;
|
||||||
|
this.isNotifying = true;
|
||||||
|
// 发送通知
|
||||||
|
const notify = new Alert(this.notifyHtml, {
|
||||||
|
timeout: 30,
|
||||||
|
sysNotify: true,
|
||||||
|
});
|
||||||
|
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => this.skip_today());
|
||||||
|
notify.getElement().addEventListener('click', ev => {
|
||||||
|
if ((ev.target as HTMLElement).tagName.toLowerCase() === 'a') {
|
||||||
|
notify.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let audioPlay = CommonUtils.getInstance().audioPlay;
|
||||||
|
window.setTimeout(audioPlay, 800);
|
||||||
|
window.setTimeout(audioPlay, 800 * 2);
|
||||||
|
window.setTimeout(audioPlay, 800 * 3);
|
||||||
|
} else {
|
||||||
|
this.isNotifying = false;
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public stop(): void {
|
||||||
|
if (this.loopId) {
|
||||||
|
window.clearInterval(this.loopId);
|
||||||
|
this.loopId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public set_time(t: number): void {
|
||||||
|
this.time = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public status(): '已启动' | '未启动' {
|
||||||
|
return this.loopId ? '已启动' : '未启动';
|
||||||
|
}
|
||||||
|
|
||||||
|
public is_running(): boolean {
|
||||||
|
return this.loopId !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public skip_today(): void {
|
||||||
|
const date = new Date();
|
||||||
|
WuhuConfig.set('_15_alarm_ignore', [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()], false);
|
||||||
|
// 通知
|
||||||
|
const notify = new Alert(`明早8点前将不再提醒 <button id="wh-rd-btn-${ MathUtils.getInstance().getRandomInt(0, 100) }">取消</button>`);
|
||||||
|
// 通知中的取消按钮
|
||||||
|
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => WuhuConfig.set('_15_alarm_ignore', undefined, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public setTimeHandler(): void {
|
||||||
|
let popup = new Popup(`<label>提前提醒时间(秒):<input type="number" value="${ WuhuConfig.get('_15AlarmTime') }" /></label><p>区间为 1 ~ 60,默认 50</p>`, '啤酒提醒时间设定');
|
||||||
|
let confirm = document.createElement('button');
|
||||||
|
confirm.innerHTML = '确定';
|
||||||
|
confirm.style.float = 'right';
|
||||||
|
confirm.addEventListener('click', () => {
|
||||||
|
let input: HTMLInputElement = popup.getElement().querySelector('input');
|
||||||
|
let num = (input.value as any) | 0;
|
||||||
|
if (num === WuhuConfig.get('_15AlarmTime')) return;
|
||||||
|
if (num < 1 || num > 60) num = 50;
|
||||||
|
input.value = num.toString();
|
||||||
|
WuhuConfig.set('_15AlarmTime', num);
|
||||||
|
this.set_time(num);
|
||||||
|
// 之前的运行状态
|
||||||
|
if (this.is_running()) this.start();
|
||||||
|
popup.close();
|
||||||
|
});
|
||||||
|
popup.getElement().appendChild(confirm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BeerMonitorLoop {
|
||||||
|
start?: Function;
|
||||||
|
stop?: Function;
|
||||||
|
set_time?: Function;
|
||||||
|
status?: Function;
|
||||||
|
is_running?: Function;
|
||||||
|
skip_today?: Function;
|
||||||
|
}
|
||||||
61
src/class/action/CompanyHelper.ts
Normal file
61
src/class/action/CompanyHelper.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import WuhuConfig from "../WuhuConfig";
|
||||||
|
import Log from "../Log";
|
||||||
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
|
import FetchUtils from "../utils/FetchUtils";
|
||||||
|
import InfoUtils from "../utils/InfoUtils";
|
||||||
|
import Alert from "../utils/Alert";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司助手
|
||||||
|
*/
|
||||||
|
export default class CompanyHelper extends WuhuBase {
|
||||||
|
className = 'CompanyHelper';
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
super();
|
||||||
|
WuhuConfig.get('CHTrainsDetectSwitch') && this.trainsDetect().then();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 火车检测
|
||||||
|
* 每日判断一次,非公司老板跳过检测
|
||||||
|
* TODO 优化、URL判断
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private async trainsDetect(): Promise<null> {
|
||||||
|
// 通过用户的icon判断公司老板
|
||||||
|
if ((await InfoUtils.getInstance().getSessionData()).statusIcons.icons.company.iconID !== 'icon73') {
|
||||||
|
Log.info('火车检测跳过:非公司老板');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 上次检测时间戳
|
||||||
|
let lastDetect: number = WuhuConfig.get('CHTrainsDetect') || 0;
|
||||||
|
// 检测是否过了一天
|
||||||
|
if (CommonUtils.getInstance().isNewDay(lastDetect, -6)) {
|
||||||
|
WuhuConfig.set('CHTrainsDetect', Date.now());
|
||||||
|
FetchUtils.getInstance().fetchText('/companies.php')
|
||||||
|
.then(res => {
|
||||||
|
let tmp: HTMLElement = document.createElement('div');
|
||||||
|
// TODO 未去除body标签
|
||||||
|
tmp.innerHTML = res.split('</head>')[1].replace('</html>', '').trim();
|
||||||
|
let trains: number = parseInt(tmp.querySelector('span.trains').innerText);
|
||||||
|
let stars: number = tmp.querySelectorAll('.company-rating .active').length / 2 || 1;
|
||||||
|
Log.info('火车/星级: ' + trains + '/' + stars);
|
||||||
|
if (trains + stars > 20) {
|
||||||
|
new Alert(`公司助手<br/><br/>火车检测:火车明日将溢出!${ trains }/20火车`, {
|
||||||
|
timeout: 15,
|
||||||
|
force: true,
|
||||||
|
sysNotify: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
Log.error('火车检测出错', error);
|
||||||
|
WuhuConfig.set('CHTrainsDetect', 0);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Log.info('火车检测:今日已提醒,跳过');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,34 +1,13 @@
|
|||||||
import InfoUtils from "../class/utils/InfoUtils";
|
import WuhuBase from "../WuhuBase";
|
||||||
import MathUtils from "../class/utils/MathUtils";
|
import Log from "../Log";
|
||||||
import CommonUtils from "../class/utils/CommonUtils";
|
import InfoUtils from "../utils/InfoUtils";
|
||||||
import TornStyleBlock from "../class/utils/TornStyleBlock";
|
import MathUtils from "../utils/MathUtils";
|
||||||
import Timer from "../class/utils/Timer";
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
import FetchUtils from "../class/utils/FetchUtils";
|
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||||
import { Injectable } from "../container/Injectable";
|
import Timer from "../utils/Timer";
|
||||||
import ClassName from "../container/ClassName";
|
|
||||||
import Logger from "../class/Logger";
|
|
||||||
import IFeature from "../man/IFeature";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 彩票助手
|
|
||||||
*/
|
|
||||||
@Injectable()
|
|
||||||
@ClassName('LotteryHelper')
|
|
||||||
export default class LotteryHelper implements IFeature {
|
|
||||||
private readonly logger: Logger = Logger.factory(LotteryHelper)
|
|
||||||
|
|
||||||
description(): string {
|
|
||||||
return "彩票助手";
|
|
||||||
}
|
|
||||||
|
|
||||||
iStart(): void | Promise<void> {
|
|
||||||
this.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
urlExcludes(): RegExp[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export default class LotteryHelper extends WuhuBase {
|
||||||
|
className = 'LotteryHelper';
|
||||||
private loopFlag = true;
|
private loopFlag = true;
|
||||||
|
|
||||||
private radioDaily: HTMLInputElement = null;
|
private radioDaily: HTMLInputElement = null;
|
||||||
@ -41,21 +20,11 @@ export default class LotteryHelper implements IFeature {
|
|||||||
private status: HTMLElement = null;
|
private status: HTMLElement = null;
|
||||||
private desc: HTMLElement = null;
|
private desc: HTMLElement = null;
|
||||||
|
|
||||||
urlIncludes(): RegExp[] {
|
private readonly mathUtils = MathUtils.getInstance();
|
||||||
return [/loader\.php\?sid=lottery/];
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly mathUtils: MathUtils,
|
|
||||||
private readonly commonUtils: CommonUtils,
|
|
||||||
private readonly fetchUtils: FetchUtils,
|
|
||||||
private readonly infoUtils: InfoUtils,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
let startTime = new Timer();
|
let startTime = new Timer();
|
||||||
this.logger.info('彩票助手初始化开始');
|
Log.info('彩票助手初始化开始');
|
||||||
|
|
||||||
let radioLabelDaily = document.createElement('label');
|
let radioLabelDaily = document.createElement('label');
|
||||||
let radioLabelWeekly = document.createElement('label');
|
let radioLabelWeekly = document.createElement('label');
|
||||||
@ -131,7 +100,7 @@ export default class LotteryHelper implements IFeature {
|
|||||||
progressBarBg, progressBar, status, desc).insert2Dom();
|
progressBarBg, progressBar, status, desc).insert2Dom();
|
||||||
// document.querySelector('#websocketConnectionData').after(container);
|
// document.querySelector('#websocketConnectionData').after(container);
|
||||||
|
|
||||||
this.logger.info('彩票助手初始化结束,耗时:' + startTime.getTimeMs());
|
Log.info('彩票助手初始化结束,耗时:' + startTime.getTimeMs());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async start() {
|
private async start() {
|
||||||
@ -145,7 +114,7 @@ export default class LotteryHelper implements IFeature {
|
|||||||
if (inputNumber > 0) {
|
if (inputNumber > 0) {
|
||||||
let msg = document.querySelector('.info-msg-wrap .msg').innerText.trim().split(' ');
|
let msg = document.querySelector('.info-msg-wrap .msg').innerText.trim().split(' ');
|
||||||
let current = {
|
let current = {
|
||||||
money: (await this.infoUtils.getSessionData()).user.money.value,
|
money: (await InfoUtils.getInstance().getSessionData()).user.money.value,
|
||||||
token: parseInt(msg[4])
|
token: parseInt(msg[4])
|
||||||
};
|
};
|
||||||
let lotteryType = 1;
|
let lotteryType = 1;
|
||||||
@ -163,12 +132,12 @@ export default class LotteryHelper implements IFeature {
|
|||||||
rsMsg = `终止操作,已完成${ i }/${ inputNumber }`;
|
rsMsg = `终止操作,已完成${ i }/${ inputNumber }`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await this.fetchUtils.ajaxFetch({
|
await CommonUtils.ajaxFetch({
|
||||||
url: window.addRFC('https://www.torn.com/loader.php?sid=lotteryPlay&step=buyTicket&lotteryID=' + lotteryType),
|
url: window.addRFC('https://www.torn.com/loader.php?sid=lotteryPlay&step=buyTicket&lotteryID=' + lotteryType),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
referrer: '/loader.php?sid=lottery',
|
referrer: '/loader.php?sid=lottery',
|
||||||
});
|
});
|
||||||
await this.commonUtils.sleep(this.mathUtils.getRandomInt(20, 50));
|
await CommonUtils.getInstance().sleep(this.mathUtils.getRandomInt(20, 50));
|
||||||
i++;
|
i++;
|
||||||
this.desc.innerHTML = `已买${ i }张彩票`;
|
this.desc.innerHTML = `已买${ i }张彩票`;
|
||||||
this.status.innerHTML = `${ i }/${ inputNumber }`;
|
this.status.innerHTML = `${ i }/${ inputNumber }`;
|
||||||
@ -177,7 +146,7 @@ export default class LotteryHelper implements IFeature {
|
|||||||
if (this.loopFlag) rsMsg = '批量购买完成';
|
if (this.loopFlag) rsMsg = '批量购买完成';
|
||||||
} else {
|
} else {
|
||||||
rsMsg = '代币或现金不足';
|
rsMsg = '代币或现金不足';
|
||||||
this.logger.warn({ totalCost, inputNumber });
|
Log.warn({ totalCost, inputNumber });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rsMsg = '输入有误';
|
rsMsg = '输入有误';
|
||||||
@ -1,74 +1,49 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||||
|
import WuhuConfig from "../WuhuConfig";
|
||||||
|
import Alert from "../utils/Alert";
|
||||||
import TornStyleSwitch from "../utils/TornStyleSwitch";
|
import TornStyleSwitch from "../utils/TornStyleSwitch";
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
import ClassName from "../../container/ClassName";
|
|
||||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
|
||||||
import IFeature from "../../man/IFeature";
|
|
||||||
import MsgWrapper from "../utils/MsgWrapper";
|
|
||||||
|
|
||||||
@Injectable()
|
export default class PTHelper extends WuhuBase {
|
||||||
@ClassName('PTHelper')
|
className = 'PTHelper';
|
||||||
export default class PTHelper implements IFeature {
|
private readonly observer;
|
||||||
private observer: MutationObserver;
|
private readonly usersPointSell;
|
||||||
private usersPointSell: HTMLDivElement;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
|
||||||
private readonly msgWrapper: MsgWrapper,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
description(): string {
|
|
||||||
return "pt一键购买";
|
|
||||||
}
|
|
||||||
|
|
||||||
iStart(): void | Promise<void> {
|
|
||||||
this.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
urlExcludes(): RegExp[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
urlIncludes(): RegExp[] {
|
|
||||||
return [/pmarket\.php/];
|
|
||||||
}
|
|
||||||
|
|
||||||
start() {
|
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
this.observer = new MutationObserver(e => {
|
this.observer = new MutationObserver(e => {
|
||||||
for (const t of e) {
|
for (const t of e) {
|
||||||
t.addedNodes.forEach(e => 'LI' === (e as HTMLElement).tagName && this.removeConfirm(e))
|
t.addedNodes.forEach(e => 'LI' === (e as HTMLElement).tagName && this.removeConfirm(e))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.usersPointSell = document.querySelector<HTMLDivElement>('.users-point-sell');
|
this.usersPointSell = document.querySelector('.users-point-sell');
|
||||||
|
|
||||||
let block = new TornStyleBlock('PT一键购买').insert2Dom();
|
let block = new TornStyleBlock('PT一键购买').insert2Dom();
|
||||||
let switcher = new TornStyleSwitch('开启');
|
let switcher = new TornStyleSwitch('开启');
|
||||||
block.append(switcher.getBase());
|
block.append(switcher.getBase());
|
||||||
let toggle = switcher.getInput();
|
let toggle = switcher.getInput();
|
||||||
toggle.checked = this.localConfigWrapper.config.ptQuickBuy;
|
toggle.checked = WuhuConfig.get('ptQuickBuy');
|
||||||
if (toggle.checked) {
|
if (toggle.checked) {
|
||||||
this.msgWrapper.create('一键购买已开启');
|
new Alert('一键购买已开启');
|
||||||
for (const index in this.usersPointSell.children) {
|
for (const index in this.usersPointSell.children) {
|
||||||
'LI' === this.usersPointSell.children[index].tagName && this.removeConfirm(this.usersPointSell.children[index])
|
'LI' === this.usersPointSell.children[index].tagName && this.removeConfirm(this.usersPointSell.children[index])
|
||||||
}
|
}
|
||||||
this.observer.observe(this.usersPointSell, { childList: true })
|
this.observer.observe(this.usersPointSell, { childList: true })
|
||||||
}
|
}
|
||||||
toggle.addEventListener('change', () => {
|
toggle.addEventListener('change', () => {
|
||||||
this.localConfigWrapper.config.ptQuickBuy = toggle.checked;
|
WuhuConfig.set('ptQuickBuy', toggle.checked, false);
|
||||||
if (toggle.checked) {
|
if (toggle.checked) {
|
||||||
for (const index in this.usersPointSell.children) {
|
for (const index in this.usersPointSell.children) {
|
||||||
'LI' === this.usersPointSell.children[index].tagName && this.removeConfirm(this.usersPointSell.children[index])
|
'LI' === this.usersPointSell.children[index].tagName && this.removeConfirm(this.usersPointSell.children[index])
|
||||||
}
|
}
|
||||||
this.observer.observe(this.usersPointSell, { childList: true });
|
this.observer.observe(this.usersPointSell, { childList: true });
|
||||||
this.msgWrapper.create('一键购买已开启');
|
new Alert('一键购买已开启');
|
||||||
} else {
|
} else {
|
||||||
for (const index in this.usersPointSell.children) {
|
for (const index in this.usersPointSell.children) {
|
||||||
'LI' === this.usersPointSell.children[index].tagName && this.rollbackConfirm(this.usersPointSell.children[index])
|
'LI' === this.usersPointSell.children[index].tagName && this.rollbackConfirm(this.usersPointSell.children[index])
|
||||||
}
|
}
|
||||||
this.observer.disconnect();
|
this.observer.disconnect();
|
||||||
this.msgWrapper.create('一键购买已关闭');
|
new Alert('一键购买已关闭');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
24
src/class/action/StackHelper.ts
Normal file
24
src/class/action/StackHelper.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||||
|
import WuhuConfig from "../WuhuConfig";
|
||||||
|
import TornStyleSwitch from "../utils/TornStyleSwitch";
|
||||||
|
|
||||||
|
export default class StackHelper extends WuhuBase {
|
||||||
|
className = 'StackHelper';
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
let block = new TornStyleBlock('叠E保护').insert2Dom();
|
||||||
|
let switcher = new TornStyleSwitch('启用');
|
||||||
|
let input = switcher.getInput();
|
||||||
|
block.append(switcher.getBase());
|
||||||
|
input.checked = WuhuConfig.get('SEProtect');
|
||||||
|
if (input.checked) document.body.classList.add('wh-gym-stack');
|
||||||
|
// 绑定点击事件
|
||||||
|
input.onchange = e => {
|
||||||
|
let target = e.target as HTMLInputElement;
|
||||||
|
document.body.classList.toggle('wh-gym-stack');
|
||||||
|
WuhuConfig.set('SEProtect', target.checked, true);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
61
src/class/action/TravelItem.ts
Normal file
61
src/class/action/TravelItem.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
|
import Log from "../Log";
|
||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import UserScriptEngine from "../../enum/UserScriptEngine";
|
||||||
|
import Popup from "../utils/Popup";
|
||||||
|
import STOCK_IMG_HTML from "../../static/html/stock_img.html";
|
||||||
|
import * as FILTER from "../../static/json/for_stock_item_filter.json";
|
||||||
|
import WindowActiveState from "./WindowActiveState";
|
||||||
|
|
||||||
|
export default class TravelItem extends WuhuBase {
|
||||||
|
className = 'TravelItem';
|
||||||
|
private readonly apiUrl: string = 'https://yata.yt/api/v1/travel/export/';
|
||||||
|
private foreignStockInfo: any = null;
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
super();
|
||||||
|
window.setInterval(async () => {
|
||||||
|
if (!WindowActiveState.getInstance().get()) return;
|
||||||
|
Log.info('fetching ', this.apiUrl);
|
||||||
|
this.foreignStockInfo = JSON.parse(await CommonUtils.COFetch(this.apiUrl));
|
||||||
|
Log.info({ 'fetch returned': this.foreignStockInfo });
|
||||||
|
}, 30 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 呈现内容
|
||||||
|
public async clickHandler(): Promise<void> {
|
||||||
|
if (CommonUtils.getScriptEngine() === UserScriptEngine.RAW) {
|
||||||
|
new Popup(STOCK_IMG_HTML.replace('{{}}', performance.now().toString()), '飞花库存');
|
||||||
|
} else {
|
||||||
|
const popup = new Popup("请稍后 " + CommonUtils.loading_gif_html(), '飞花库存');
|
||||||
|
let table = `<table><tr><th colspan="2">目的地 - 更新时间</th><th colspan="3">库存</th></tr>`;
|
||||||
|
const dest = FILTER.default;
|
||||||
|
const now = new Date();
|
||||||
|
const res = await this.get();
|
||||||
|
Log.info({ res })
|
||||||
|
if (!res || !res.stocks) return;
|
||||||
|
dest.forEach(el => {
|
||||||
|
const update = (now.getTime() - new Date(res.stocks[el.name]['update'] * 1000).getTime()) / 1000 | 0
|
||||||
|
table += `<tr><td>${ el.show }</td><td>${ update / 60 | 0 }分${ update % 60 | 0 }秒前</td>`;
|
||||||
|
let count = 0;
|
||||||
|
res.stocks[el.name]['stocks'].forEach(stock => {
|
||||||
|
if (el.stocks[stock.name]) {
|
||||||
|
table += `<td${ stock['quantity'] === 0 ? ' style="background-color:#f44336;color:white;border-color:#000;"' : '' }>${ el.stocks[stock.name] } (${ stock['quantity'] })</td>`;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
while (count < 3) {
|
||||||
|
count++;
|
||||||
|
table += '<td></td>';
|
||||||
|
}
|
||||||
|
table += '</tr>';
|
||||||
|
});
|
||||||
|
table += '</table>';
|
||||||
|
popup.getElement().innerHTML = table;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async get() {
|
||||||
|
return this.foreignStockInfo ||= JSON.parse(await CommonUtils.COFetch(this.apiUrl));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,14 +1,13 @@
|
|||||||
import uuidv4 from "../../func/utils/uuidv4";
|
import uuidv4 from "../../func/utils/uuidv4";
|
||||||
import ClassName from "../../container/ClassName";
|
import WuhuBase from "../WuhuBase";
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
|
|
||||||
@ClassName('WindowActiveState')
|
export default class WindowActiveState extends WuhuBase {
|
||||||
@Injectable()
|
className = 'WindowActiveState';
|
||||||
export default class WindowActiveState {
|
isFocus = false;
|
||||||
private isFocus = false;
|
uuid = uuidv4();
|
||||||
private uuid = uuidv4();
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
super();
|
||||||
if (self !== top) return null;
|
if (self !== top) return null;
|
||||||
localStorage.setItem('whuuid', this.uuid);
|
localStorage.setItem('whuuid', this.uuid);
|
||||||
document.addEventListener('visibilitychange',
|
document.addEventListener('visibilitychange',
|
||||||
@ -18,7 +17,6 @@ export default class WindowActiveState {
|
|||||||
addEventListener('blur', () => this.isFocus = false);
|
addEventListener('blur', () => this.isFocus = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当前实例是否激活
|
|
||||||
get(): boolean {
|
get(): boolean {
|
||||||
// 当前窗口获得了焦点 优先级最高
|
// 当前窗口获得了焦点 优先级最高
|
||||||
if (this.isFocus) return true;
|
if (this.isFocus) return true;
|
||||||
91
src/class/action/XZMZ.ts
Normal file
91
src/class/action/XZMZ.ts
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import XUNZHAOMUZHUANG_HTML from "../../static/html/xunzhaomuzhuang/index.html";
|
||||||
|
import * as MUZHUANG_ID_LIST_JSON from "../../static/json/muzhuang_id_list.json";
|
||||||
|
import Log from "../Log";
|
||||||
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
|
import XUNZHAOMUZHUANG_CSS from "../../static/css/xunzhaomuzhuang.css";
|
||||||
|
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 寻找木桩
|
||||||
|
* /item.php?temp=4#xunzhaomuzhuang
|
||||||
|
*/
|
||||||
|
export default class XZMZ extends WuhuBase {
|
||||||
|
className = 'XZMZ';
|
||||||
|
private readonly mainRoleContainer: HTMLElement;
|
||||||
|
private readonly IDList: number[];
|
||||||
|
private readonly btn: HTMLButtonElement;
|
||||||
|
private readonly tips: HTMLElement;
|
||||||
|
private counter: number;
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
super();
|
||||||
|
CommonUtils.addStyle(XUNZHAOMUZHUANG_CSS);
|
||||||
|
this.mainRoleContainer = document.querySelector('div[role="main"]');
|
||||||
|
let block = new TornStyleBlock('寻找木桩');
|
||||||
|
block.setContent(XUNZHAOMUZHUANG_HTML);
|
||||||
|
this.mainRoleContainer.append(block.getBase());
|
||||||
|
this.IDList = MUZHUANG_ID_LIST_JSON.default;
|
||||||
|
this.btn = block.querySelector('#deadman-start-btn') as HTMLButtonElement;
|
||||||
|
this.tips = block.querySelector('#deadman_tips');
|
||||||
|
|
||||||
|
block.querySelector('#deadman-start-btn').addEventListener('click', () => {
|
||||||
|
this.mainRoleContainer.querySelector('#table-body').innerHTML = '';
|
||||||
|
this.btn.disabled = true;
|
||||||
|
this.StartSearch();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private StartSearch() {
|
||||||
|
this.counter = this.IDList.length;
|
||||||
|
const tips = this.tips;
|
||||||
|
tips.innerText = "---寻找中,长按目标名字弹出迷你档案---";
|
||||||
|
for (const id of this.IDList) {
|
||||||
|
this.SearchDeadman(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SearchDeadman(id) {
|
||||||
|
CommonUtils.ajaxFetch({
|
||||||
|
url: window.addRFC('https://www.torn.com/profiles.php?step=getProfileData&XID=' + id),
|
||||||
|
method: 'GET'
|
||||||
|
}).then((res) =>
|
||||||
|
res.json()
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
this.counter--;
|
||||||
|
if (res.userStatus.status.type === 'ok') {
|
||||||
|
this.addRow({
|
||||||
|
player_id: res.user.userID,
|
||||||
|
name: res.userInformation.name,
|
||||||
|
level: res.userInformation.level
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.counter === 0) {
|
||||||
|
this.tips.innerText = "---寻找结束,等待60秒后重试---";
|
||||||
|
let countdown = 60;
|
||||||
|
let timer = window.setInterval(() => {
|
||||||
|
this.btn.innerHTML = (countdown--).toString();
|
||||||
|
if (countdown === 0) {
|
||||||
|
window.clearInterval(timer);
|
||||||
|
this.btn.disabled = false;
|
||||||
|
this.btn.innerHTML = '重新寻找';
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
Log.error(e)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private addRow(data) {
|
||||||
|
let $parentNode = this.mainRoleContainer.querySelector('#table-body'),
|
||||||
|
$node = '<tr data-id="' + data.player_id + '"></tr>';
|
||||||
|
$node += '<td style="border: 1px solid darkgray;padding:5px;text-align:center;">' + data.player_id + '</td>'
|
||||||
|
$node += `<td style="border: 1px solid darkgray;padding:5px;text-align:center;"><a href="/profiles.php?XID=${ data.player_id }">${ data.name }</a></td>`;
|
||||||
|
$node += '<td style="border: 1px solid darkgray;padding:5px;text-align:center;">' + data.level + '</td>'
|
||||||
|
$node += '<td style="border: 1px solid darkgray;padding:5px;text-align:center;"><a href="https://www.torn.com/loader.php?sid=attack&user2ID=' + data.player_id + '" target="_blank" class="torn-btn">攻击</a></td>'
|
||||||
|
$parentNode.insertAdjacentHTML('beforeend', $node)
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/class/handler/AdditionalSettingsHandler.ts
Normal file
27
src/class/handler/AdditionalSettingsHandler.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Popup from "../utils/Popup";
|
||||||
|
import Alert from "../utils/Alert";
|
||||||
|
|
||||||
|
export default class AdditionalSettingsHandler extends WuhuBase {
|
||||||
|
className = 'AdditionalSettingsHandler';
|
||||||
|
|
||||||
|
public handle(): void {
|
||||||
|
let pop = new Popup('', '更多设定');
|
||||||
|
let insertHtml = '<p><button class="torn-btn">清空设置</button></p><p><button class="torn-btn">通知权限</button></p><p><button class="torn-btn">外部数据权限</button></p>';
|
||||||
|
pop.getElement().insertAdjacentHTML('beforeend', insertHtml);
|
||||||
|
let [btn1, btn2, btn3] = Array.from(pop.getElement().querySelectorAll('button'));
|
||||||
|
btn1.addEventListener('click', () => {
|
||||||
|
localStorage.removeItem('wh_trv_alarm');
|
||||||
|
localStorage.removeItem('wh_trans_settings');
|
||||||
|
localStorage.removeItem('whuuid');
|
||||||
|
localStorage.removeItem('wh-gs-storage');
|
||||||
|
localStorage.removeItem('WHTEST');
|
||||||
|
new Alert('已清空,刷新页面');
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
btn2.addEventListener('click', () => {
|
||||||
|
});
|
||||||
|
btn3.addEventListener('click', () => {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/class/handler/ChangeLogHandler.ts
Normal file
49
src/class/handler/ChangeLogHandler.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Popup from "../utils/Popup";
|
||||||
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
|
import MDUtils from "../utils/MDUtils";
|
||||||
|
import Log from "../Log";
|
||||||
|
|
||||||
|
export default class ChangeLogHandler extends WuhuBase {
|
||||||
|
className = 'ChangeLogHandler';
|
||||||
|
|
||||||
|
public handle(): void {
|
||||||
|
let popup = new Popup(
|
||||||
|
'更新历史:<br/><a target="_blank" href="https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md">https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md</a><br/>',
|
||||||
|
'更新历史'
|
||||||
|
).getElement();
|
||||||
|
popup.classList.add('wh-changeLog');
|
||||||
|
let progressBar = document.createElement('div');
|
||||||
|
progressBar.style.height = '2px';
|
||||||
|
progressBar.style.width = '1%';
|
||||||
|
progressBar.style.backgroundColor = 'red';
|
||||||
|
let progressText = document.createElement('p');
|
||||||
|
progressText.innerText = '加载更新文件……';
|
||||||
|
progressText.style.textAlign = 'center';
|
||||||
|
let style = document.createElement('style');
|
||||||
|
style.innerHTML = `.wh-changeLog h2,.wh-changeLog h3,.wh-changeLog h4 {margin:8px 0;}.wh-changeLog li{list-style: inside;}`;
|
||||||
|
|
||||||
|
popup.append(progressBar, progressText, style);
|
||||||
|
|
||||||
|
CommonUtils
|
||||||
|
.COFetch('https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/CHANGELOG.md?' + performance.now())
|
||||||
|
.then(update => {
|
||||||
|
progressBar.style.width = '60%';
|
||||||
|
progressText.innerText = '解析中……';
|
||||||
|
let md = MDUtils.getInstance().parse(update);
|
||||||
|
popup.append(md);
|
||||||
|
progressBar.style.width = '100%';
|
||||||
|
progressText.innerText = '加载完成';
|
||||||
|
|
||||||
|
window.setTimeout(() => {
|
||||||
|
progressBar.remove();
|
||||||
|
progressText.remove()
|
||||||
|
}, 3000);
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
Log.error(e);
|
||||||
|
progressBar.remove();
|
||||||
|
progressText.innerText = '无法加载';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
95
src/class/handler/IFrameCrimeHandler.ts
Normal file
95
src/class/handler/IFrameCrimeHandler.ts
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
|
import Popup from "../utils/Popup";
|
||||||
|
import QUICK_CRIMES_HTML from "../../static/html/quick_crimes.html";
|
||||||
|
|
||||||
|
export default class IFrameCrimeHandler extends WuhuBase {
|
||||||
|
className = 'IFrameCrimeHandler';
|
||||||
|
|
||||||
|
public handle(): void {
|
||||||
|
// 弹出小窗口
|
||||||
|
const ifHTML = `<iframe src="/crimes.php?step=main" style="width:100%;max-width: 450px;margin: 0 auto;display: none;height: 340px;"></iframe>`;
|
||||||
|
const popup_insert = `<p>加载中请稍后${ CommonUtils.loading_gif_html() }</p><div id="wh-quick-crime-if-container"></div>`;
|
||||||
|
const $popup = new Popup(popup_insert, '小窗快速犯罪').getElement();
|
||||||
|
// 运行状态node
|
||||||
|
let loading_node = $popup.querySelector('p:first-of-type');
|
||||||
|
// if容器
|
||||||
|
const if_cont = $popup.querySelector('#wh-quick-crime-if-container');
|
||||||
|
if_cont.innerHTML = ifHTML;
|
||||||
|
|
||||||
|
// if内未加载脚本时插入的快捷crime node
|
||||||
|
const mobile_prepend_node = document.createElement('div');
|
||||||
|
mobile_prepend_node.classList.add('wh-translate');
|
||||||
|
mobile_prepend_node.innerHTML = QUICK_CRIMES_HTML;
|
||||||
|
|
||||||
|
// if对象加载后运行
|
||||||
|
let cIframe = $popup.querySelector('iframe');
|
||||||
|
|
||||||
|
// 加载状态
|
||||||
|
const if_onload_func = () => {
|
||||||
|
// if内部文档对象
|
||||||
|
const ifDocu = cIframe.contentWindow.document;
|
||||||
|
// 内部插件运行flag
|
||||||
|
const ifWH = cIframe.contentWindow.WHTRANS;
|
||||||
|
// 文档加载完成后移除
|
||||||
|
if (!!loading_node) loading_node.remove();
|
||||||
|
// 文档加载完成后才显示if
|
||||||
|
cIframe.style.display = 'block';
|
||||||
|
// 验证码flag
|
||||||
|
const isValidate = ifDocu.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate');
|
||||||
|
// 如果iframe内部未运行脚本
|
||||||
|
if (ifWH === undefined) {
|
||||||
|
// 隐藏顶部
|
||||||
|
CommonUtils.elementReady('#header-root', ifDocu).then(e => e.style.display = 'none');
|
||||||
|
// 隐藏4条
|
||||||
|
CommonUtils.elementReady('#sidebarroot', ifDocu).then(e => e.style.display = 'none');
|
||||||
|
// 隐藏聊天
|
||||||
|
CommonUtils.elementReady('#chatRoot', ifDocu).then(e => e.style.display = 'none');
|
||||||
|
// 非验证码页面隐藏滚动条
|
||||||
|
if (!isValidate) ifDocu.body.style.overflow = 'hidden';
|
||||||
|
// 调整容器位置
|
||||||
|
CommonUtils.elementReady('.content-wrapper', ifDocu).then(elem => {
|
||||||
|
// 加入
|
||||||
|
elem.prepend(mobile_prepend_node);
|
||||||
|
elem.style.margin = '0px';
|
||||||
|
elem.style.position = 'absolute';
|
||||||
|
elem.style.top = '-35px';
|
||||||
|
new MutationObserver((m, o) => {
|
||||||
|
o.disconnect();
|
||||||
|
if (!elem.querySelector('.wh-translate')) elem.prepend(mobile_prepend_node);
|
||||||
|
o.observe(elem, { childList: true, subtree: true });
|
||||||
|
})
|
||||||
|
.observe(elem, { childList: true, subtree: true });
|
||||||
|
});
|
||||||
|
// 隐藏返回顶部按钮
|
||||||
|
CommonUtils.elementReady('#go-to-top-btn button', ifDocu).then(e => e.style.display = 'none');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
cIframe.onload = if_onload_func;
|
||||||
|
|
||||||
|
// 超时判断
|
||||||
|
let time_counter = 0;
|
||||||
|
let time_out_id = window.setInterval(() => {
|
||||||
|
loading_node = $popup.querySelector('p:first-of-type');
|
||||||
|
if (!loading_node) {
|
||||||
|
clearInterval(time_out_id);
|
||||||
|
time_out_id = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
time_counter++;
|
||||||
|
if (time_counter > 0 && !loading_node.querySelector('button')) {
|
||||||
|
const reload_btn = document.createElement('button');
|
||||||
|
reload_btn.innerHTML = '重新加载';
|
||||||
|
reload_btn.onclick = () => {
|
||||||
|
reload_btn.remove();
|
||||||
|
time_counter = 0;
|
||||||
|
if_cont.innerHTML = null;
|
||||||
|
if_cont.innerHTML = ifHTML;
|
||||||
|
cIframe = $popup.querySelector('iframe');
|
||||||
|
cIframe.onload = if_onload_func;
|
||||||
|
};
|
||||||
|
loading_node.append(reload_btn);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/class/handler/ItemPriceWatcherHandler.ts
Normal file
27
src/class/handler/ItemPriceWatcherHandler.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import WuhuConfig from "../WuhuConfig";
|
||||||
|
import PRICE_WATCHER_HTML from "../../static/html/price_watcher.html";
|
||||||
|
import Popup from "../utils/Popup";
|
||||||
|
import Global from "../Global";
|
||||||
|
|
||||||
|
export default class ItemPriceWatcherHandler extends WuhuBase {
|
||||||
|
className = 'ItemPriceWatcherHandler';
|
||||||
|
|
||||||
|
public handle(): void {
|
||||||
|
const watcher_conf = WuhuConfig.get('priceWatcher');
|
||||||
|
const pre_str = JSON.stringify(watcher_conf);
|
||||||
|
const html = PRICE_WATCHER_HTML
|
||||||
|
.replace('{{}}', localStorage.getItem('APIKey') || '不可用')
|
||||||
|
.replace('{{}}', Global.getInstance().isPDA ? Global.getInstance().PDA_APIKey : '不可用')
|
||||||
|
.replace('{{}}', watcher_conf['pt'] || -1)
|
||||||
|
.replace('{{}}', watcher_conf['xan'] || -1);
|
||||||
|
const popup = new Popup(html, '价格监视设置');
|
||||||
|
popup.getElement().querySelector('button').onclick = () => {
|
||||||
|
const [pt_node, xan_node] = Array.from(<NodeListOf<HTMLInputElement>>popup.getElement().querySelectorAll('input[type="number"]'));
|
||||||
|
watcher_conf.pt = (pt_node.value as any) | 0;
|
||||||
|
watcher_conf.xan = (xan_node.value as any) | 0;
|
||||||
|
if (JSON.stringify(watcher_conf) !== pre_str) WuhuConfig.set('priceWatcher', watcher_conf);
|
||||||
|
popup.close();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,24 +1,17 @@
|
|||||||
import NNB_INFO_HTML from "../../../static/html/nnb_info.html";
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import NNB_INFO_HTML from "../../static/html/nnb_info.html";
|
||||||
import Popup from "../utils/Popup";
|
import Popup from "../utils/Popup";
|
||||||
import ClassName from "../../container/ClassName";
|
import Global from "../Global";
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
import TornPDAUtils from "../utils/TornPDAUtils";
|
|
||||||
|
|
||||||
@ClassName('NNB')
|
export default class NNB extends WuhuBase {
|
||||||
@Injectable()
|
|
||||||
export default class NNB {
|
|
||||||
className = 'NNB';
|
className = 'NNB';
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly tornPDAUtils: TornPDAUtils,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public handle(): void {
|
public handle(): void {
|
||||||
|
let { isPDA, PDA_APIKey } = Global.getInstance();
|
||||||
const insert = NNB_INFO_HTML
|
const insert = NNB_INFO_HTML
|
||||||
.replace('{{}}', localStorage.getItem('APIKey') || '不可用')
|
.replace('{{}}', localStorage.getItem('APIKey') || '不可用')
|
||||||
.replace('{{}}', this.tornPDAUtils.isPDA() ? this.tornPDAUtils.APIKey : '不可用');
|
.replace('{{}}', isPDA ? PDA_APIKey : '不可用');
|
||||||
const popup = new Popup(insert, '查看NNB').element;
|
const popup = new Popup(insert, '查看NNB').getElement();
|
||||||
const select = popup.querySelector('input');
|
const select = popup.querySelector('input');
|
||||||
const node = popup.querySelector('p');
|
const node = popup.querySelector('p');
|
||||||
popup.querySelector('button').addEventListener('click', ev => {
|
popup.querySelector('button').addEventListener('click', ev => {
|
||||||
@ -27,7 +20,7 @@ export default class NNB {
|
|||||||
node.innerHTML = '加载中';
|
node.innerHTML = '加载中';
|
||||||
// API 计算
|
// API 计算
|
||||||
if (select.checked) {
|
if (select.checked) {
|
||||||
const api_key = this.tornPDAUtils.isPDA() ? this.tornPDAUtils.APIKey : window.localStorage.getItem('APIKey');
|
const api_key = isPDA ? PDA_APIKey : window.localStorage.getItem('APIKey');
|
||||||
window.fetch(`https://api.torn.com/user/?selections=bars,perks&key=${ api_key }`)
|
window.fetch(`https://api.torn.com/user/?selections=bars,perks&key=${ api_key }`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@ -1,33 +1,16 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
import CommonUtils from "../utils/CommonUtils";
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
import QUICK_FLY_CSS from "../../../static/css/quick_fly.module.css";
|
import QUICK_FLY_CSS from "../../static/css/quick_fly.css";
|
||||||
import QUICK_FLY_HTML from "../../../static/html/quick_fly.html";
|
import QUICK_FLY_HTML from "../../static/html/quick_fly.html";
|
||||||
import Alert from "../utils/Alert";
|
import Alert from "../utils/Alert";
|
||||||
import TravelItem from "../../feature/TravelItem";
|
import TravelItem from "../action/TravelItem";
|
||||||
import ClassName from "../../container/ClassName";
|
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
import Logger from "../Logger";
|
|
||||||
import MsgWrapper from "../utils/MsgWrapper";
|
|
||||||
import { InjectionKey } from "vue";
|
|
||||||
import NetHighLvlWrapper from "../utils/NetHighLvlWrapper";
|
|
||||||
|
|
||||||
@ClassName('QuickFlyBtnHandler')
|
export default class QuickFlyBtnHandler extends WuhuBase {
|
||||||
@Injectable()
|
|
||||||
export default class QuickFlyBtnHandler {
|
|
||||||
className = 'QuickFlyBtnHandler';
|
className = 'QuickFlyBtnHandler';
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly logger: Logger,
|
|
||||||
private readonly travelItem: TravelItem,
|
|
||||||
private readonly commonUtils: CommonUtils,
|
|
||||||
// private readonly infoUtils: InfoUtils,
|
|
||||||
private readonly msgWrapper: MsgWrapper,
|
|
||||||
private readonly netHighLvlWrapper: NetHighLvlWrapper,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static doQuickFly(): void {
|
public static doQuickFly(): void {
|
||||||
// [id: dest, _type: (1...4), ts: timestamp]
|
// [id: dest, _type: (1...4), ts: timestamp]
|
||||||
const [_id, _type, ts] = window.sessionStorage['wh-quick-fly'].trim().split(' ');
|
const [_id, _type, ts] = sessionStorage['wh-quick-fly'].trim().split(' ');
|
||||||
if (new Date().getTime() - ts > 20000) {
|
if (new Date().getTime() - ts > 20000) {
|
||||||
new Alert('超时,一键起飞计划已取消');
|
new Alert('超时,一键起飞计划已取消');
|
||||||
return;
|
return;
|
||||||
@ -61,7 +44,7 @@ export default class QuickFlyBtnHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 起飞目的地id
|
// 起飞目的地id
|
||||||
private static getDestId(dest: number): number {
|
private static getDestId(dest): number {
|
||||||
// 墨、开、加、夏、英、阿、瑞s、立本、祖、迪、南
|
// 墨、开、加、夏、英、阿、瑞s、立本、祖、迪、南
|
||||||
return [2, 12, 9, 3, 10, 7, 8, 5, 6, 11, 4][dest];
|
return [2, 12, 9, 3, 10, 7, 8, 5, 6, 11, 4][dest];
|
||||||
}
|
}
|
||||||
@ -70,7 +53,7 @@ export default class QuickFlyBtnHandler {
|
|||||||
if (window.hasWHQuickFlyOpt) return;
|
if (window.hasWHQuickFlyOpt) return;
|
||||||
window.hasWHQuickFlyOpt = true;
|
window.hasWHQuickFlyOpt = true;
|
||||||
// TODO
|
// TODO
|
||||||
this.commonUtils.styleInject(QUICK_FLY_CSS);
|
CommonUtils.addStyle(QUICK_FLY_CSS);
|
||||||
const node = document.createElement('div');
|
const node = document.createElement('div');
|
||||||
node.id = 'wh-quick-fly-opt';
|
node.id = 'wh-quick-fly-opt';
|
||||||
node.innerHTML = QUICK_FLY_HTML;
|
node.innerHTML = QUICK_FLY_HTML;
|
||||||
@ -86,7 +69,8 @@ export default class QuickFlyBtnHandler {
|
|||||||
});
|
});
|
||||||
node.querySelector('a').addEventListener('click', (e) => {
|
node.querySelector('a').addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.travelItem.clickHandler().then();
|
// forStock();
|
||||||
|
TravelItem.getInstance().clickHandler();
|
||||||
});
|
});
|
||||||
node.querySelector('input').addEventListener('click', (e) => {
|
node.querySelector('input').addEventListener('click', (e) => {
|
||||||
node.classList.toggle('wh-quick-fly-opt-hide');
|
node.classList.toggle('wh-quick-fly-opt-hide');
|
||||||
@ -120,37 +104,4 @@ export default class QuickFlyBtnHandler {
|
|||||||
showTime();
|
showTime();
|
||||||
yaoCD.innerHTML = `药CD剩余:${ CommonUtils.getYaoCD() }`;
|
yaoCD.innerHTML = `药CD剩余:${ CommonUtils.getYaoCD() }`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async directFly(destIndex: number, typeIndex: number) {
|
|
||||||
// 获取key
|
|
||||||
// if(false){
|
|
||||||
// let key;
|
|
||||||
// try {
|
|
||||||
// const resp = await (await fetch('/travelagency.php')).text();
|
|
||||||
// key = resp.match(/data-key="([0-9]+)"/)[1];
|
|
||||||
// } catch (e) {
|
|
||||||
// this.msgWrapper.create('起飞参数获取失败', {}, 'error');
|
|
||||||
// this.logger.error(e.stack);
|
|
||||||
// throw new Error('起飞参数获取失败');
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
let msg: string;
|
|
||||||
try {
|
|
||||||
msg = await this.netHighLvlWrapper.doTravelFly(QuickFlyBtnHandler.getDestId(destIndex), null, ['standard', 'airstrip', 'private', 'business'][typeIndex])
|
|
||||||
const response = JSON.parse(msg);
|
|
||||||
if (!response.success) {
|
|
||||||
this.msgWrapper.create('起飞失败 ' + response.error, {}, 'error');
|
|
||||||
this.logger.error('起飞失败 ' + response.error, response.err);
|
|
||||||
throw new Error('起飞失败 ' + response.error);
|
|
||||||
}
|
|
||||||
console.log(msg);
|
|
||||||
} catch (e) {
|
|
||||||
this.msgWrapper.create('起飞时出现错误 ' + e.message, {}, 'error');
|
|
||||||
this.logger.error(e.stack);
|
|
||||||
throw new Error('起飞时出现错误 ' + e.message);
|
|
||||||
}
|
|
||||||
this.msgWrapper.create('已起飞', {}, 'success');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const QuickFlyBtnHandlerKey = Symbol('QuickFlyBtnHandlerKey') as InjectionKey<QuickFlyBtnHandler>
|
|
||||||
@ -1,19 +1,16 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
import CommonUtils from "../utils/CommonUtils";
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
import QUICK_LINK_CSS from "../../../static/css/quick_link.module.css";
|
import QUICK_LINK_CSS from "../../static/css/quick_link.css";
|
||||||
import Popup from "../utils/Popup";
|
import Popup from "../utils/Popup";
|
||||||
import ClassName from "../../container/ClassName";
|
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
|
|
||||||
@ClassName('QuickLinksHandler')
|
export default class QuickLinksHandler extends WuhuBase {
|
||||||
@Injectable()
|
className = 'QuickLinksHandler';
|
||||||
export default class QuickLinksHandler {
|
|
||||||
|
|
||||||
private styleAdded: boolean = false;
|
private styleAdded: boolean = false;
|
||||||
private list = [];
|
private list = [];
|
||||||
|
|
||||||
constructor(
|
constructor() {
|
||||||
private readonly commonUtils: CommonUtils,
|
super();
|
||||||
) {
|
|
||||||
let list = this.list;
|
let list = this.list;
|
||||||
// 生存手册
|
// 生存手册
|
||||||
list.push({
|
list.push({
|
||||||
@ -75,7 +72,7 @@ export default class QuickLinksHandler {
|
|||||||
|
|
||||||
public handle(): void {
|
public handle(): void {
|
||||||
if (!this.styleAdded) {
|
if (!this.styleAdded) {
|
||||||
this.commonUtils.styleInject(QUICK_LINK_CSS);
|
CommonUtils.addStyle(QUICK_LINK_CSS);
|
||||||
this.styleAdded = true;
|
this.styleAdded = true;
|
||||||
}
|
}
|
||||||
const list = this.list;
|
const list = this.list;
|
||||||
@ -85,8 +82,8 @@ export default class QuickLinksHandler {
|
|||||||
});
|
});
|
||||||
insert += '</p>'
|
insert += '</p>'
|
||||||
let popup = new Popup(insert, '常用链接');
|
let popup = new Popup(insert, '常用链接');
|
||||||
popup.element.classList.add('wh-link-collection-cont');
|
popup.getElement().classList.add('wh-link-collection-cont');
|
||||||
popup.element.addEventListener('click', ev => {
|
popup.getElement().addEventListener('click', ev => {
|
||||||
let target = ev.target as HTMLElement;
|
let target = ev.target as HTMLElement;
|
||||||
if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'span') {
|
if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'span') {
|
||||||
popup.close();
|
popup.close();
|
||||||
@ -1,66 +1,50 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
import { MenuItemConfig } from "../ZhongIcon";
|
import { MenuItemConfig } from "../ZhongIcon";
|
||||||
|
import Log from "../Log";
|
||||||
import Timer from "../utils/Timer";
|
import Timer from "../utils/Timer";
|
||||||
import BuyBeerHelper from "../../feature/BuyBeerHelper";
|
import BuyBeerHelper from "../action/BuyBeerHelper";
|
||||||
import UpdateTranslateDict from "./UpdateTranslateDict";
|
import UpdateTranslateDict from "./UpdateTranslateDict";
|
||||||
import landedRedirect from "../../func/module/landedRedirect";
|
import landedRedirect from "../../func/module/landedRedirect";
|
||||||
import Alert from "../utils/Alert";
|
import Alert from "../utils/Alert";
|
||||||
|
import WuhuConfig from "../WuhuConfig";
|
||||||
import ViewLogsHandler from "./ViewLogsHandler";
|
import ViewLogsHandler from "./ViewLogsHandler";
|
||||||
import AdditionalSettingsHandler from "./AdditionalSettingsHandler";
|
import AdditionalSettingsHandler from "./AdditionalSettingsHandler";
|
||||||
import Popup from "../utils/Popup";
|
import Popup from "../utils/Popup";
|
||||||
import CommonUtils from "../utils/CommonUtils";
|
import CommonUtils from "../utils/CommonUtils";
|
||||||
import CustomCssHandler from "./CustomCssHandler";
|
|
||||||
import Provider from "../provider/Provider";
|
|
||||||
import { MENU_ITEM_TYPE } from "../../interface/MenuItem";
|
|
||||||
import ClassName from "../../container/ClassName";
|
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
import Logger from "../Logger";
|
|
||||||
|
|
||||||
@ClassName('SettingsHandler')
|
export default class SettingsHandler extends WuhuBase {
|
||||||
@Injectable()
|
|
||||||
class SettingsHandler extends Provider {
|
|
||||||
className = 'SettingsHandler';
|
className = 'SettingsHandler';
|
||||||
|
|
||||||
private list: MenuItemConfig[] = [];
|
private list: MenuItemConfig[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor() {
|
||||||
private readonly buyBeerHelper: BuyBeerHelper,
|
|
||||||
private readonly commonUtils: CommonUtils,
|
|
||||||
private readonly updateTranslateDict: UpdateTranslateDict,
|
|
||||||
private readonly customCssHandler: CustomCssHandler,
|
|
||||||
private readonly viewLogsHandler: ViewLogsHandler,
|
|
||||||
private readonly additionalSettingsHandler: AdditionalSettingsHandler,
|
|
||||||
private readonly logger: Logger,
|
|
||||||
) {
|
|
||||||
super();
|
super();
|
||||||
this.constructWuhuSettingList();
|
this.constructWuhuSettingList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public show(): void {
|
public handler(): void {
|
||||||
let startTime = new Timer();
|
let startTime = new Timer();
|
||||||
this.logger.info('构造设置开始');
|
Log.info('构造设置开始');
|
||||||
let pop = new Popup(CommonUtils.loading_gif_html(), '芜湖助手设置');
|
let pop = new Popup(CommonUtils.loading_gif_html(), '芜湖助手设置');
|
||||||
window.setTimeout(() => {
|
|
||||||
let tmp = document.createElement('div');
|
let tmp = document.createElement('div');
|
||||||
tmp.classList.add('gSetting');
|
tmp.classList.add('gSetting');
|
||||||
this.list.forEach(set => this.commonUtils.elemGenerator(set, tmp));
|
this.list.forEach(set => CommonUtils.getInstance().elemGenerator(set, tmp));
|
||||||
// 本日不提醒
|
|
||||||
tmp.querySelector('#wh-qua-alarm-check-btn')
|
|
||||||
.addEventListener('click', () => this.buyBeerHelper.skip_today());
|
|
||||||
pop.getElement().innerHTML = '';
|
pop.getElement().innerHTML = '';
|
||||||
pop.getElement().appendChild(tmp);
|
pop.getElement().appendChild(tmp);
|
||||||
|
// 本日不提醒
|
||||||
|
pop.getElement().querySelector('#wh-qua-alarm-check-btn')
|
||||||
|
.addEventListener('click', () => BuyBeerHelper.getInstance().skip_today());
|
||||||
(window.initializeTooltip) && (window.initializeTooltip('#wh-popup-cont', 'white-tooltip'));
|
(window.initializeTooltip) && (window.initializeTooltip('#wh-popup-cont', 'white-tooltip'));
|
||||||
this.logger.info('构造设置结束 ' + startTime.getTimeMs());
|
Log.info('构造设置结束 ' + startTime.getTimeMs());
|
||||||
}, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置
|
// 设置
|
||||||
private constructWuhuSettingList(): SettingsHandler {
|
private constructWuhuSettingList(): SettingsHandler {
|
||||||
let timer = new Timer();
|
let timer = new Timer();
|
||||||
this.logger.info('构造设置列表开始');
|
Log.info('构造设置列表开始');
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
|
||||||
let beer = this.buyBeerHelper;
|
let beer = BuyBeerHelper.getInstance();
|
||||||
|
|
||||||
let list = this.list;
|
let list = this.list;
|
||||||
|
|
||||||
@ -103,35 +87,19 @@ class SettingsHandler extends Provider {
|
|||||||
dictName: 'transEnable',
|
dictName: 'transEnable',
|
||||||
isHide: true,
|
isHide: true,
|
||||||
});
|
});
|
||||||
list.push({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domId: '',
|
|
||||||
domText: ' 新翻译',
|
|
||||||
dictName: 'transNew',
|
|
||||||
tip: '改进后的翻译,更好的性能',
|
|
||||||
});
|
|
||||||
// 更新翻译词库
|
// 更新翻译词库
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: '',
|
domId: '',
|
||||||
domText: '更新翻译词库',
|
domText: '更新翻译词库',
|
||||||
isTornBtn: true,
|
clickFunc: () => UpdateTranslateDict.getInstance().handle()
|
||||||
clickFunc: () => this.updateTranslateDict.handle()
|
|
||||||
});
|
|
||||||
// 收集数据以改进翻译质量
|
|
||||||
list.push({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domId: '',
|
|
||||||
domText: ' 收集数据以改进翻译质量',
|
|
||||||
dictName: 'CollectPlayerData',
|
|
||||||
tip: '未实现功能<br/>收集玩家基础信息与页面上(未翻译)的内容上传以改进翻译'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 战斗
|
// 战斗优化
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'plain',
|
domType: 'plain',
|
||||||
domId: '',
|
domId: '',
|
||||||
domHTML: '战斗',
|
domHTML: '战斗优化',
|
||||||
tagName: 'h4',
|
tagName: 'h4',
|
||||||
});
|
});
|
||||||
// 光速拔刀
|
// 光速拔刀
|
||||||
@ -170,6 +138,7 @@ class SettingsHandler extends Provider {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
dictName: 'quickAttIndex',
|
dictName: 'quickAttIndex',
|
||||||
|
isHide: true,
|
||||||
tip: '将Start Fight按钮移动到指定格子上',
|
tip: '将Start Fight按钮移动到指定格子上',
|
||||||
});
|
});
|
||||||
// 光速跑路
|
// 光速跑路
|
||||||
@ -196,7 +165,8 @@ class SettingsHandler extends Provider {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
dictName: 'quickFinishAtt',
|
dictName: 'quickFinishAtt',
|
||||||
tip: '将结束后指定按钮移动到上面指定的格子上',
|
isHide: true,
|
||||||
|
tip: '<del>将结束后指定按钮移动到上面指定的格子上</del>暂时关闭',
|
||||||
});
|
});
|
||||||
// 攻击链接转跳
|
// 攻击链接转跳
|
||||||
list.push({
|
list.push({
|
||||||
@ -204,75 +174,63 @@ class SettingsHandler extends Provider {
|
|||||||
domId: 'wh-attack-relocate',
|
domId: 'wh-attack-relocate',
|
||||||
domText: ' 真·攻击界面转跳',
|
domText: ' 真·攻击界面转跳',
|
||||||
dictName: 'attRelocate',
|
dictName: 'attRelocate',
|
||||||
tip: '在无法打开攻击界面的情况下依然可以转跳到正确的攻击页面,(失效,Ched疑似已移除此转跳)',
|
tip: '在无法打开攻击界面的情况下依然可以转跳到正确的攻击页面',
|
||||||
|
isHide: true,
|
||||||
});
|
});
|
||||||
// 盯梢模式强度
|
// 危险行为⚠️
|
||||||
|
if (WuhuConfig.get('dangerZone') === true) {
|
||||||
|
// 攻击界面自刷新
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'select',
|
domType: 'select',
|
||||||
domId: '',
|
domId: 'wh-attack-reload',
|
||||||
domText: '盯梢模式强度 ',
|
domText: '⚠️攻击界面自动刷新 ',
|
||||||
|
dictName: 'attReload',
|
||||||
domSelectOpt: [
|
domSelectOpt: [
|
||||||
{ domVal: '550', domText: '强' },
|
{
|
||||||
{ domVal: '950', domText: '标准' },
|
domVal: 'none',
|
||||||
{ domVal: '1450', domText: '弱' }
|
domText: '无间隔',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
domVal: '1',
|
||||||
|
domText: '约1s',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
domVal: '2',
|
||||||
|
domText: '约2s',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
domVal: '3',
|
||||||
|
domText: '约3s',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
domVal: '4',
|
||||||
|
domText: '约4s',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
domVal: '5',
|
||||||
|
domText: '约5s',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
domVal: 'disabled',
|
||||||
|
domText: '关闭',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
dictName: 'WatchTargetFreq',
|
isHide: true,
|
||||||
tip: '越强盯得越紧(刷新越快),越容易触发Torn大流量保护机制<br/>强 ~0.6s<br/>标准 ~1s<br/>弱 ~1.5s',
|
tip: '危险功能:接机时常用,将自动刷新页面直到目标落地',
|
||||||
})
|
});
|
||||||
// 危险行为⚠️
|
// 自动开打和结束
|
||||||
// if (WuhuConfig.get('dangerZone') === true) {
|
list.push({
|
||||||
// // 攻击界面自刷新
|
domType: 'checkbox',
|
||||||
// list.push({
|
domId: 'wh-auto-start-finish',
|
||||||
// domType: 'select',
|
domText: ' ⚠️自动开打和结束',
|
||||||
// domId: 'wh-attack-reload',
|
dictName: 'autoStartFinish',
|
||||||
// domText: '⚠️攻击界面自动刷新 ',
|
tip: '脚本将会自动按下战斗和结束按钮',
|
||||||
// dictName: 'attReload',
|
isHide: true,
|
||||||
// domSelectOpt: [
|
});
|
||||||
// {
|
} else {
|
||||||
// domVal: 'none',
|
WuhuConfig.set('autoStartFinish', false)
|
||||||
// domText: '无间隔',
|
WuhuConfig.set('attReload', 6)
|
||||||
// },
|
}
|
||||||
// {
|
|
||||||
// domVal: '1',
|
|
||||||
// domText: '约1s',
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// domVal: '2',
|
|
||||||
// domText: '约2s',
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// domVal: '3',
|
|
||||||
// domText: '约3s',
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// domVal: '4',
|
|
||||||
// domText: '约4s',
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// domVal: '5',
|
|
||||||
// domText: '约5s',
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// domVal: 'disabled',
|
|
||||||
// domText: '关闭',
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// isHide: true,
|
|
||||||
// tip: '危险功能:接机时常用,将自动刷新页面直到目标落地',
|
|
||||||
// });
|
|
||||||
// // 自动开打和结束
|
|
||||||
// list.push({
|
|
||||||
// domType: 'checkbox',
|
|
||||||
// domId: 'wh-auto-start-finish',
|
|
||||||
// domText: ' ⚠️自动开打和结束',
|
|
||||||
// dictName: 'autoStartFinish',
|
|
||||||
// tip: '脚本将会自动按下战斗和结束按钮',
|
|
||||||
// isHide: true,
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// WuhuConfig.set('autoStartFinish', false)
|
|
||||||
// WuhuConfig.set('attReload', 6)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 飞行
|
// 飞行
|
||||||
list.push({
|
list.push({
|
||||||
@ -308,10 +266,7 @@ class SettingsHandler extends Provider {
|
|||||||
tip: '海外落地后每30秒通知警告',
|
tip: '海外落地后每30秒通知警告',
|
||||||
});
|
});
|
||||||
// 落地转跳
|
// 落地转跳
|
||||||
list.push({
|
list.push({ domType: 'button', domId: '', domText: '落地转跳', clickFunc: landedRedirect });
|
||||||
domType: 'button', domId: '',
|
|
||||||
isTornBtn: true, domText: '落地转跳', clickFunc: landedRedirect
|
|
||||||
});
|
|
||||||
|
|
||||||
// 公司
|
// 公司
|
||||||
list.push({
|
list.push({
|
||||||
@ -372,7 +327,7 @@ class SettingsHandler extends Provider {
|
|||||||
list.push({
|
list.push({
|
||||||
domType: 'checkbox',
|
domType: 'checkbox',
|
||||||
domId: 'wh-qua-alarm-check',
|
domId: 'wh-qua-alarm-check',
|
||||||
domText: '<span> 啤酒提醒 </span><button id="wh-qua-alarm-check-btn" class="torn-btn">今日不提醒</button>',
|
domText: '<span> 啤酒提醒 </span><button id="wh-qua-alarm-check-btn">今日不提醒</button>',
|
||||||
dictName: '_15Alarm',
|
dictName: '_15Alarm',
|
||||||
tip: '每小时的整15分钟的倍数时通知提醒抢啤酒或者血包',
|
tip: '每小时的整15分钟的倍数时通知提醒抢啤酒或者血包',
|
||||||
isHide: true,
|
isHide: true,
|
||||||
@ -384,7 +339,6 @@ class SettingsHandler extends Provider {
|
|||||||
list.push({
|
list.push({
|
||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: '',
|
domId: '',
|
||||||
isTornBtn: true,
|
|
||||||
domText: '啤酒提醒状态',
|
domText: '啤酒提醒状态',
|
||||||
clickFunc: function () {
|
clickFunc: function () {
|
||||||
new Alert(`啤酒提醒${ beer.status() }`);
|
new Alert(`啤酒提醒${ beer.status() }`);
|
||||||
@ -395,67 +349,8 @@ class SettingsHandler extends Provider {
|
|||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: '',
|
domId: '',
|
||||||
domText: '啤酒提醒时间设定',
|
domText: '啤酒提醒时间设定',
|
||||||
isTornBtn: true,
|
|
||||||
// tip: '通知提前时间',
|
// tip: '通知提前时间',
|
||||||
clickFunc: () => this.buyBeerHelper.setTimeHandler()
|
clickFunc: () => BuyBeerHelper.getInstance().setTimeHandler()
|
||||||
});
|
|
||||||
|
|
||||||
// 个人资料
|
|
||||||
list.push({
|
|
||||||
domType: 'plain',
|
|
||||||
domId: '',
|
|
||||||
domHTML: '个人资料',
|
|
||||||
tagName: 'h4',
|
|
||||||
});
|
|
||||||
list.push({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domText: '隐藏个人资料头像',
|
|
||||||
dictName: 'HideProfileImg',
|
|
||||||
domId: ''
|
|
||||||
});
|
|
||||||
list.push({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domText: '显示曾用名',
|
|
||||||
dictName: 'ShowNameHistory',
|
|
||||||
domId: ''
|
|
||||||
});
|
|
||||||
list.push({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domText: '迷你资料卡显示上次行动时间',
|
|
||||||
dictName: 'ShowMiniProfLastAct',
|
|
||||||
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({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domId: '',
|
|
||||||
domText: ' 现金变动提醒',
|
|
||||||
dictName: 'CashChangeAlert',
|
|
||||||
tip: '插件图标下方显示现金、现金变动时通知提醒<br/>注: 刷新页面生效、系统级通知需要浏览器权限'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 其他
|
// 其他
|
||||||
@ -510,28 +405,13 @@ class SettingsHandler extends Provider {
|
|||||||
tip: 'PT市场页面购买时跳过确认',
|
tip: 'PT市场页面购买时跳过确认',
|
||||||
isHide: true,
|
isHide: true,
|
||||||
});
|
});
|
||||||
// 搜索页空白占位区
|
// 4条转跳
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'checkbox',
|
domType: 'checkbox',
|
||||||
domId: null,
|
domId: '',
|
||||||
domText: ' 搜索页空白占位区',
|
domText: ' 4条转跳',
|
||||||
dictName: 'SearchPagePlaceholder',
|
dictName: 'barsRedirect',
|
||||||
});
|
tip: '点击4条时转跳对应页面',
|
||||||
// 解决一直转圈(加载中)的问题
|
|
||||||
list.push({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domId: null,
|
|
||||||
domText: ' 解决一直转圈(加载中)的问题',
|
|
||||||
dictName: 'SolveGoogleScriptPendingIssue',
|
|
||||||
tip: 'Torn引入Google登陆后可能会出现这种问题<br/>启用功能影响:<br/>页面加载速度变慢,与其他插件冲突,如遇到问题请关闭<br/>并使用其他更科学的方法解决'
|
|
||||||
});
|
|
||||||
// 记住图标位置
|
|
||||||
list.push({
|
|
||||||
domType: 'checkbox',
|
|
||||||
domId: null,
|
|
||||||
domText: ' 记住图标位置',
|
|
||||||
dictName: 'SaveIconPosition',
|
|
||||||
tip: '记住图标移动后的位置'
|
|
||||||
});
|
});
|
||||||
// 清除多余的脚本
|
// 清除多余的脚本
|
||||||
// list.push({
|
// list.push({
|
||||||
@ -541,7 +421,6 @@ class SettingsHandler extends Provider {
|
|||||||
// dictName: 'removeScripts',
|
// dictName: 'removeScripts',
|
||||||
// tip: '清除Google相关脚本、顶部横幅等',
|
// tip: '清除Google相关脚本、顶部横幅等',
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// dev
|
// dev
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'checkbox',
|
domType: 'checkbox',
|
||||||
@ -550,36 +429,20 @@ class SettingsHandler extends Provider {
|
|||||||
dictName: 'isDev',
|
dictName: 'isDev',
|
||||||
isHide: true,
|
isHide: true,
|
||||||
});
|
});
|
||||||
// 自定义CSS
|
|
||||||
list.push({
|
|
||||||
domType: 'button',
|
|
||||||
domId: null,
|
|
||||||
domText: '自定义CSS',
|
|
||||||
isTornBtn: true,
|
|
||||||
clickFunc: () => this.customCssHandler.handle()
|
|
||||||
});
|
|
||||||
// 查看logs
|
// 查看logs
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'button',
|
domType: 'button',
|
||||||
domId: null,
|
domId: null,
|
||||||
domText: '查看日志',
|
domText: '查看日志',
|
||||||
isTornBtn: true,
|
clickFunc: () => ViewLogsHandler.getInstance().handle()
|
||||||
clickFunc: () => this.viewLogsHandler.handle()
|
|
||||||
});
|
});
|
||||||
// 更多设定
|
// 更多设定
|
||||||
list.push({
|
list.push({
|
||||||
domType: 'button', domId: 'wh-otherBtn', domText: '更多设定',
|
domType: 'button', domId: 'wh-otherBtn', domText: '更多设定',
|
||||||
isTornBtn: true,
|
clickFunc: () => AdditionalSettingsHandler.getInstance().handle()
|
||||||
clickFunc: () => this.additionalSettingsHandler.show()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.info('构造设置列表结束' + timer.getTimeMs());
|
Log.info('构造设置列表结束' + timer.getTimeMs());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
|
||||||
domType: MENU_ITEM_TYPE.BUTTON,
|
|
||||||
domText: '⚙️ 助手设置',
|
|
||||||
clickFunc: () => Container.factory(SettingsHandler).show()
|
|
||||||
};
|
|
||||||
10
src/class/handler/UpdateTranslateDict.ts
Normal file
10
src/class/handler/UpdateTranslateDict.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Alert from "../utils/Alert";
|
||||||
|
|
||||||
|
export default class UpdateTranslateDict extends WuhuBase {
|
||||||
|
className = 'UpdateTranslateDict';
|
||||||
|
|
||||||
|
public handle(): void {
|
||||||
|
new Alert('计划中');
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/class/handler/ViewLogsHandler.ts
Normal file
19
src/class/handler/ViewLogsHandler.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Log from "../Log";
|
||||||
|
import Popup from "../utils/Popup";
|
||||||
|
|
||||||
|
export default class ViewLogsHandler extends WuhuBase {
|
||||||
|
className = 'ViewLogsHandler';
|
||||||
|
|
||||||
|
public handle(): void {
|
||||||
|
let logCounter = Log.getCounter();
|
||||||
|
let pop = new Popup('<textarea readonly style="width:100%;height:340px;"></textarea>', '查看日志');
|
||||||
|
let text = pop.getElement().querySelector('textarea');
|
||||||
|
text.innerHTML = Log.getLogs();
|
||||||
|
text.onclick = () => text.select();
|
||||||
|
pop.getElement().insertAdjacentHTML(
|
||||||
|
'afterbegin',
|
||||||
|
`<p>${ logCounter.info }信息 ${ logCounter.warning }警告 ${ logCounter.error }错误</p>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/class/provider/Provider.ts
Normal file
32
src/class/provider/Provider.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import Log from "../Log";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基类、单例
|
||||||
|
*/
|
||||||
|
export default class Provider {
|
||||||
|
protected readonly className: string = 'Provider';
|
||||||
|
private static instance;
|
||||||
|
|
||||||
|
private static readonly pool = {};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> {
|
||||||
|
// return this.instance ||= new this();
|
||||||
|
if (!this.instance) {
|
||||||
|
let startTime = performance.now();
|
||||||
|
this.instance = new this();
|
||||||
|
let thatName = this.instance.getClassName() || this.name;
|
||||||
|
Log.info('实例已创建,', thatName, this.instance, '耗时' + ((performance.now() - startTime) | 0) + 'ms');
|
||||||
|
Provider.pool[thatName] = this.instance;
|
||||||
|
}
|
||||||
|
return this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getPool() {
|
||||||
|
return {
|
||||||
|
pool: Provider.pool,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/class/provider/Starter.ts
Normal file
22
src/class/provider/Starter.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import Log from "../Log";
|
||||||
|
import ZhongIcon from "../ZhongIcon";
|
||||||
|
|
||||||
|
export default class Starter {
|
||||||
|
public static run(T): void {
|
||||||
|
|
||||||
|
if (window.WHTRANS) throw '退出, 已运行次数' + window.WHTRANS;
|
||||||
|
window.WHTRANS = window.WHTRANS === undefined ? 1 : window.WHTRANS++;
|
||||||
|
|
||||||
|
let started = performance.now();
|
||||||
|
try {
|
||||||
|
T.main();
|
||||||
|
} catch (e) {
|
||||||
|
Log.error('[Starter]加载出错信息: ' + e.message);
|
||||||
|
Log.info('错误堆栈: ', e.stack);
|
||||||
|
}
|
||||||
|
let runTime: number = (performance.now() - started) | 0;
|
||||||
|
Log.info(`芜湖脚本完成加载, 耗时${ runTime }ms`);
|
||||||
|
if (ZhongIcon.ZhongNode && ZhongIcon.ZhongNode.initTimer)
|
||||||
|
ZhongIcon.ZhongNode.initTimer.innerHTML = `加载时间 ${ runTime }ms`;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/class/utils/ActionButtonUtils.ts
Normal file
25
src/class/utils/ActionButtonUtils.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Log from "../Log";
|
||||||
|
import ZhongIcon from "../ZhongIcon";
|
||||||
|
|
||||||
|
export default class ActionButtonUtils extends WuhuBase {
|
||||||
|
className = 'ActionButtonUtils';
|
||||||
|
private hasAdded: boolean = false;
|
||||||
|
|
||||||
|
public add(txt: string, func: (ev: Event) => void = () => null): void {
|
||||||
|
if (!this.hasAdded) this.handle(txt, func);
|
||||||
|
else Log.warn('ActionButton已存在');
|
||||||
|
}
|
||||||
|
|
||||||
|
private handle(txt, func): void {
|
||||||
|
let btn = document.createElement('button');
|
||||||
|
btn.style.padding = '8px 13px 8px 0';
|
||||||
|
btn.style.verticalAlign = 'bottom';
|
||||||
|
btn.style.color = '#4CAF50';
|
||||||
|
btn.innerHTML = txt;
|
||||||
|
btn.addEventListener('click', func);
|
||||||
|
ZhongIcon.ZhongNode.querySelector('button').after(btn);
|
||||||
|
this.hasAdded = true;
|
||||||
|
Log.info('ActionButton已添加', { txt, func, btn });
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,56 +1,46 @@
|
|||||||
|
import Log from "../Log";
|
||||||
import IWHNotify from "../../interface/IWHNotify";
|
import IWHNotify from "../../interface/IWHNotify";
|
||||||
import NotificationUtils from "./NotificationUtils";
|
import NotificationUtils from "./NotificationUtils";
|
||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
import MathUtils from "./MathUtils";
|
import MathUtils from "./MathUtils";
|
||||||
import NOTIFY_HTML from "../../../static/html/notify.html";
|
import NOTIFY_HTML from "../../static/html/notify.html";
|
||||||
import WindowActiveState from "../action/WindowActiveState";
|
import WindowActiveState from "../action/WindowActiveState";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
import Logger from "../Logger";
|
|
||||||
import ClassName from "../../container/ClassName";
|
|
||||||
|
|
||||||
@ClassName('Alert')
|
export default class Alert extends WuhuBase {
|
||||||
export default class Alert {
|
className = 'Alert';
|
||||||
private static container: HTMLElement = null;
|
private static container: HTMLElement = null;
|
||||||
private static totalCounter: number = 0;
|
|
||||||
|
|
||||||
private notify: MyHTMLElement = null;
|
private notify: MyHTMLElement = null;
|
||||||
private intervalID = -1;
|
private intervalID = -1;
|
||||||
private readonly callback: Function;
|
private readonly callback: Function;
|
||||||
|
|
||||||
public constructor(
|
public constructor(msg: string, options: IWHNotify = {}) {
|
||||||
msg: string,
|
super();
|
||||||
options: IWHNotify = {},
|
|
||||||
private readonly mathUtils: MathUtils = Container.factory(MathUtils),
|
|
||||||
private readonly windowActiveState: WindowActiveState = Container.factory(WindowActiveState),
|
|
||||||
private readonly notificationUtils: NotificationUtils = Container.factory(NotificationUtils),
|
|
||||||
private readonly logger: Logger = Container.factory(Logger),
|
|
||||||
) {
|
|
||||||
|
|
||||||
let { timeout, callback, sysNotify, force } = options;
|
let { timeout, callback, sysNotify, force } = options;
|
||||||
|
|
||||||
// 后台窗口、iframe内判断
|
// 后台窗口、iframe内判断
|
||||||
if (!this.windowActiveState.get() || (self !== top)) {
|
if (!WindowActiveState.getInstance().get() || (self !== top)) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
this.logger.warn('后台通知已被屏蔽');
|
Log.warn('后台通知已被屏蔽');
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
this.logger.info('强制后台通知');
|
Log.info('强制后台通知');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知的容器
|
// 通知的容器
|
||||||
this.logger.info('通知的容器', Alert.container);
|
if (Alert.container === null) Alert.initContainer();
|
||||||
if (!Alert.container || !document.contains(Alert.container)) Alert.initContainer();
|
|
||||||
|
|
||||||
this.callback = callback || (() => null);
|
this.callback = callback || (() => null);
|
||||||
Alert.create(this, msg, timeout || 3);
|
Alert.create(this, msg, timeout || 3);
|
||||||
Alert.totalCounter++;
|
Log.info('创建新通知:', this, msg);
|
||||||
this.logger.info('创建新通知:', this, msg);
|
if (sysNotify) NotificationUtils.getInstance().push(msg, options);
|
||||||
if (sysNotify) this.notificationUtils.push(msg, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static create(that: Alert, msg, timeout): void {
|
private static create(that: Alert, msg, timeout): void {
|
||||||
// 通知的唯一id
|
// 通知的唯一id
|
||||||
const uid = '' + that.mathUtils.getRandomInt(1000, 9999);
|
const uid = '' + MathUtils.getInstance().getRandomInt(1000, 9999);
|
||||||
// 每条通知
|
// 每条通知
|
||||||
const element: MyHTMLElement = document.createElement('div');
|
const element: MyHTMLElement = document.createElement('div');
|
||||||
element.id = `wh-notify-${ uid }`;
|
element.id = `wh-notify-${ uid }`;
|
||||||
@ -63,7 +53,7 @@ export default class Alert {
|
|||||||
let mouse_enter = false;
|
let mouse_enter = false;
|
||||||
element.addEventListener('mouseenter', () => mouse_enter = true, true);
|
element.addEventListener('mouseenter', () => mouse_enter = true, true);
|
||||||
element.addEventListener('mouseleave', () => mouse_enter = false);
|
element.addEventListener('mouseleave', () => mouse_enter = false);
|
||||||
// 通知进度条 TODO 改进
|
// 通知进度条
|
||||||
let progressCount = 101;
|
let progressCount = 101;
|
||||||
// 计时器
|
// 计时器
|
||||||
that.intervalID = window.setInterval(() => {
|
that.intervalID = window.setInterval(() => {
|
||||||
@ -93,7 +83,6 @@ export default class Alert {
|
|||||||
this.notify = null;
|
this.notify = null;
|
||||||
this.callback();
|
this.callback();
|
||||||
window.clearInterval(this.intervalID);
|
window.clearInterval(this.intervalID);
|
||||||
Alert.totalCounter--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getElement() {
|
public getElement() {
|
||||||
@ -1,53 +1,32 @@
|
|||||||
import UserScriptEngine from "../../enum/UserScriptEngine";
|
import UserScriptEngine from "../../enum/UserScriptEngine";
|
||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Log from "../Log";
|
||||||
import Device from "../../enum/Device";
|
import Device from "../../enum/Device";
|
||||||
import LOADING_IMG_HTML from "../../../static/html/loading_img.html";
|
import AjaxFetchOption from "../../interface/AjaxFetchOption";
|
||||||
|
import LOADING_IMG_HTML from "../../static/html/loading_img.html";
|
||||||
import Timer from "./Timer";
|
import Timer from "./Timer";
|
||||||
import FetchUtils from "./FetchUtils";
|
import FetchUtils from "./FetchUtils";
|
||||||
import TornStyleSwitch from "./TornStyleSwitch";
|
import TornStyleSwitch from "./TornStyleSwitch";
|
||||||
|
import WuhuConfig from "../WuhuConfig";
|
||||||
import { MenuItemConfig } from "../ZhongIcon";
|
import { MenuItemConfig } from "../ZhongIcon";
|
||||||
import TRAVEL_STATE from "../../enum/TravelState";
|
|
||||||
import InventoryItemInfo from "../../interface/responseType/InventoryItemInfo";
|
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
import ClassName from "../../container/ClassName";
|
|
||||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
|
||||||
import Logger from "../Logger";
|
|
||||||
import Global from "../Global";
|
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
import TornPDAUtils from "./TornPDAUtils";
|
|
||||||
import { InjectionKey } from "vue";
|
|
||||||
|
|
||||||
@Injectable()
|
export default class CommonUtils extends WuhuBase {
|
||||||
@ClassName('CommonUtils')
|
className = 'CommonUtils';
|
||||||
export default class CommonUtils {
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
|
||||||
private readonly fetchUtils: FetchUtils,
|
|
||||||
private readonly logger: Logger,
|
|
||||||
private readonly global: Global,
|
|
||||||
private readonly tornPDAUtils: TornPDAUtils,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
static getScriptEngine() {
|
static getScriptEngine() {
|
||||||
let glob = Container.factory(Global);
|
let glob = CommonUtils.glob;
|
||||||
let tornPDAUtils = Container.factory(TornPDAUtils);
|
return glob.GM_xmlhttpRequest ? UserScriptEngine.GM : glob.isPDA
|
||||||
return glob.GM_xmlhttpRequest ? UserScriptEngine.GM : tornPDAUtils.isPDA()
|
|
||||||
? UserScriptEngine.PDA : UserScriptEngine.RAW;
|
? UserScriptEngine.PDA : UserScriptEngine.RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static COFetch(url: URL | string, method: 'get' | 'post' | string = 'get', body: any = null): Promise<string> {
|
static COFetch(url: URL | string, method: 'get' | 'post' = 'get', body: any = null): Promise<string> {
|
||||||
let logger = Container.factory(Logger);
|
|
||||||
let start = new Timer();
|
|
||||||
const engine = this.getScriptEngine();
|
const engine = this.getScriptEngine();
|
||||||
logger.info(`跨域请求 -> ${url}, 脚本引擎: ${engine}`);
|
let start = performance.now();
|
||||||
|
Log.info('跨域获取数据开始, 脚本引擎: ' + engine);
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
switch (engine) {
|
switch (engine) {
|
||||||
case UserScriptEngine.RAW: {
|
case UserScriptEngine.RAW: {
|
||||||
logger.error(`跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
Log.error(`跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
||||||
reject(`错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
reject(`错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -56,38 +35,38 @@ export default class CommonUtils {
|
|||||||
// get
|
// get
|
||||||
if (method === 'get') {
|
if (method === 'get') {
|
||||||
if (typeof PDA_httpGet !== 'function') {
|
if (typeof PDA_httpGet !== 'function') {
|
||||||
logger.error('COFetch网络错误:PDA版本不支持');
|
Log.error('COFetch网络错误:PDA版本不支持');
|
||||||
reject('COFetch网络错误:PDA版本不支持');
|
reject('COFetch网络错误:PDA版本不支持');
|
||||||
}
|
}
|
||||||
PDA_httpGet(url)
|
PDA_httpGet(url)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
logger.info('跨域获取数据成功, 耗时' + start.getTimeMs());
|
Log.info('跨域获取数据成功, 耗时' + (performance.now() - start | 0) + 'ms');
|
||||||
resolve(res.responseText);
|
resolve(res.responseText);
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
logger.error('COFetch网络错误', e);
|
Log.error('COFetch网络错误', e);
|
||||||
reject(`COFetch网络错误 ${ e }`);
|
reject(`COFetch网络错误 ${ e }`);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// post
|
// post
|
||||||
else {
|
else {
|
||||||
if (typeof PDA_httpPost !== 'function') {
|
if (typeof PDA_httpPost !== 'function') {
|
||||||
logger.error('COFetch网络错误:PDA版本不支持');
|
Log.error('COFetch网络错误:PDA版本不支持');
|
||||||
reject('COFetch网络错误:PDA版本不支持');
|
reject('COFetch网络错误:PDA版本不支持');
|
||||||
}
|
}
|
||||||
PDA_httpPost(url, { 'content-type': 'application/json' }, body)
|
PDA_httpPost(url, { 'content-type': 'application/json' }, body)
|
||||||
.then(res => resolve(res.responseText))
|
.then(res => resolve(res.responseText))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
logger.error('COFetch网络错误', e);
|
Log.error('COFetch网络错误', e);
|
||||||
reject(`COFetch网络错误 ${ e }`);
|
reject(`COFetch网络错误 ${ e }`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UserScriptEngine.GM: {
|
case UserScriptEngine.GM: {
|
||||||
let { GM_xmlhttpRequest } = Container.factory(Global);
|
let { GM_xmlhttpRequest } = CommonUtils.glob;
|
||||||
if (typeof GM_xmlhttpRequest !== 'function') {
|
if (typeof GM_xmlhttpRequest !== 'function') {
|
||||||
logger.error('COFetch网络错误:用户脚本扩展API错误');
|
Log.error('COFetch网络错误:用户脚本扩展API错误');
|
||||||
reject('错误:用户脚本扩展API错误');
|
reject('错误:用户脚本扩展API错误');
|
||||||
}
|
}
|
||||||
GM_xmlhttpRequest({
|
GM_xmlhttpRequest({
|
||||||
@ -96,7 +75,7 @@ export default class CommonUtils {
|
|||||||
data: method === 'get' ? null : body,
|
data: method === 'get' ? null : body,
|
||||||
headers: method === 'get' ? null : { 'content-type': 'application/json' },
|
headers: method === 'get' ? null : { 'content-type': 'application/json' },
|
||||||
onload: res => {
|
onload: res => {
|
||||||
logger.info('跨域获取数据成功,耗时' + start.getTimeMs());
|
Log.info('跨域获取数据成功,耗时' + (performance.now() - start | 0) + 'ms');
|
||||||
resolve(res.response);
|
resolve(res.response);
|
||||||
},
|
},
|
||||||
onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`),
|
onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`),
|
||||||
@ -107,13 +86,6 @@ export default class CommonUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getScriptEngine() {
|
|
||||||
// let glob = Container.factory(Global);
|
|
||||||
// let tornPDAUtils = Container.factory(TornPDAUtils);
|
|
||||||
return this.global.GM_xmlhttpRequest ? UserScriptEngine.GM : this.tornPDAUtils.isPDA()
|
|
||||||
? UserScriptEngine.PDA : UserScriptEngine.RAW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * 返回玩家信息的对象 { playername: string, userID: number }
|
// * 返回玩家信息的对象 { playername: string, userID: number }
|
||||||
// * @return {PlayerInfo} rs
|
// * @return {PlayerInfo} rs
|
||||||
@ -153,19 +125,19 @@ export default class CommonUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static ajaxFetch(opt: AjaxFetchOption) {
|
public static ajaxFetch(opt: AjaxFetchOption) {
|
||||||
// let { url, referrer = '/', method, body = null } = opt;
|
let { url, referrer = '/', method, body = null } = opt;
|
||||||
// let req_params: RequestInit = {
|
let req_params: RequestInit = {
|
||||||
// headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
||||||
// referrer,
|
referrer,
|
||||||
// method,
|
method,
|
||||||
// };
|
};
|
||||||
// if (method === 'POST') {
|
if (method === 'POST') {
|
||||||
// req_params.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
req_params.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||||
// req_params.body = body;
|
req_params.body = body;
|
||||||
// }
|
}
|
||||||
// return window.fetch(url, req_params);
|
return window.fetch(url, req_params);
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过 mutation.observe 方法异步返回元素
|
* 通过 mutation.observe 方法异步返回元素
|
||||||
@ -175,27 +147,26 @@ export default class CommonUtils {
|
|||||||
* @returns {Promise<HTMLElement|null>}
|
* @returns {Promise<HTMLElement|null>}
|
||||||
*/
|
*/
|
||||||
public static elementReady(selectors: string, content: Document = document, timeout: number = 30000): Promise<HTMLElement> {
|
public static elementReady(selectors: string, content: Document = document, timeout: number = 30000): Promise<HTMLElement> {
|
||||||
const logger = Container.factory(Logger);
|
Log.info('等待元素:' + selectors);
|
||||||
logger.info('等待元素:' + selectors);
|
|
||||||
let timer = new Timer();
|
let timer = new Timer();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let el = content.querySelector(selectors) as HTMLElement;
|
let el = content.querySelector(selectors) as HTMLElement;
|
||||||
if (el) {
|
if (el) {
|
||||||
logger.info('已获取元素, 耗时' + timer.getTimeMs(), el);
|
Log.info('已获取元素, 耗时' + timer.getTimeMs(), el);
|
||||||
resolve(el);
|
resolve(el);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let observer = new MutationObserver((_, observer) => {
|
let observer = new MutationObserver((_, observer) => {
|
||||||
content.querySelectorAll(selectors).forEach((element) => {
|
content.querySelectorAll(selectors).forEach((element) => {
|
||||||
logger.info({ innerHTML: element.innerHTML, element });
|
Log.info({ innerHTML: element.innerHTML, element });
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
logger.info('已获取元素, 耗时' + timer.getTimeMs(), element);
|
Log.info('已获取元素, 耗时' + timer.getTimeMs(), element);
|
||||||
resolve(element as HTMLElement);
|
resolve(element as HTMLElement);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
window.setTimeout(() => {
|
setTimeout(() => {
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
logger.error(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());
|
Log.error(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());
|
||||||
reject(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());
|
reject(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());
|
||||||
}, timeout);
|
}, timeout);
|
||||||
observer.observe(content.documentElement, { childList: true, subtree: true });
|
observer.observe(content.documentElement, { childList: true, subtree: true });
|
||||||
@ -212,12 +183,7 @@ export default class CommonUtils {
|
|||||||
return CommonUtils.elementReady(selectors, content, timeout);
|
return CommonUtils.elementReady(selectors, content, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public querySelector(selectors: string, content: Document = document, timeout: number = 30000): Promise<HTMLElement> {
|
|
||||||
return CommonUtils.elementReady(selectors, content, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static addStyle(rules: string): void {
|
public static addStyle(rules: string): void {
|
||||||
const logger = Container.factory(Logger);
|
|
||||||
let element = document.querySelector('style#wh-trans-gStyle');
|
let element = document.querySelector('style#wh-trans-gStyle');
|
||||||
if (element) {
|
if (element) {
|
||||||
element.innerHTML += rules;
|
element.innerHTML += rules;
|
||||||
@ -227,14 +193,7 @@ export default class CommonUtils {
|
|||||||
element.innerHTML = rules;
|
element.innerHTML = rules;
|
||||||
document.head.appendChild(element);
|
document.head.appendChild(element);
|
||||||
}
|
}
|
||||||
logger.info('CSS规则已添加', element);
|
Log.info('CSS规则已添加', element);
|
||||||
}
|
|
||||||
|
|
||||||
public styleInject(rules: string): void {
|
|
||||||
const element = document.createElement("style");
|
|
||||||
element.setAttribute('type', 'text/css');
|
|
||||||
element.innerHTML = rules;
|
|
||||||
document.head.appendChild(element);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static loading_gif_html(): string {
|
public static loading_gif_html(): string {
|
||||||
@ -246,19 +205,12 @@ export default class CommonUtils {
|
|||||||
* @param {string} url 播放的音频URL
|
* @param {string} url 播放的音频URL
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
public audioPlay(url: string = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3'): Promise<void> {
|
public audioPlay(url: string = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3') {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const audio = new Audio(url);
|
const audio = new Audio(url);
|
||||||
audio.addEventListener("canplaythrough", () => {
|
audio.addEventListener("canplaythrough", () => {
|
||||||
audio.play()
|
audio.play()
|
||||||
.catch(err => {
|
.catch(err => Log.error(err))
|
||||||
this.logger.error('播放音频出错', err.message, err.stack);
|
.then();
|
||||||
reject();
|
|
||||||
})
|
|
||||||
.then(
|
|
||||||
() => resolve()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,6 +221,7 @@ export default class CommonUtils {
|
|||||||
*/
|
*/
|
||||||
public isNewDay(target: number | Date, offsetHours: number = 0): boolean {
|
public isNewDay(target: number | Date, offsetHours: number = 0): boolean {
|
||||||
let tar: Date = typeof target === "number" ? new Date(target) : target;
|
let tar: Date = typeof target === "number" ? new Date(target) : target;
|
||||||
|
Log.info(tar.toLocaleString());
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
let utcNewDay = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate()));
|
let utcNewDay = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate()));
|
||||||
utcNewDay.setHours(utcNewDay.getHours() + offsetHours);
|
utcNewDay.setHours(utcNewDay.getHours() + offsetHours);
|
||||||
@ -276,11 +229,11 @@ export default class CommonUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public jQueryReady(): Promise<null> {
|
public jQueryReady(): Promise<null> {
|
||||||
this.logger.info('等待jQuery加载中...');
|
Log.info('等待jQuery加载中...');
|
||||||
this.fetchUtils.fetchText('/js/script/lib/jquery-1.8.2.js?v=f9128651g')
|
FetchUtils.getInstance().fetchText('/js/script/lib/jquery-1.8.2.js?v=f9128651g')
|
||||||
.then(res => window.eval(res));
|
.then(res => window.eval(res));
|
||||||
let intervalId = window.setInterval(() => {
|
let intervalId = window.setInterval(() => {
|
||||||
this.logger.info('仍在等待jQuery加载中...');
|
Log.info('仍在等待jQuery加载中...');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -288,7 +241,7 @@ export default class CommonUtils {
|
|||||||
await this.sleep(100);
|
await this.sleep(100);
|
||||||
}
|
}
|
||||||
window.clearInterval(intervalId);
|
window.clearInterval(intervalId);
|
||||||
this.logger.info('jQuery已加载');
|
Log.info('jQuery已加载');
|
||||||
resolve(null);
|
resolve(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -315,9 +268,9 @@ export default class CommonUtils {
|
|||||||
let _input = switcher.getInput();
|
let _input = switcher.getInput();
|
||||||
switcher.getBase().id = domId;
|
switcher.getBase().id = domId;
|
||||||
(tip) && (switcher.getBase().setAttribute('title', tip));
|
(tip) && (switcher.getBase().setAttribute('title', tip));
|
||||||
_input.checked = this.localConfigWrapper.config[dictName];
|
_input.checked = WuhuConfig.get(dictName);
|
||||||
_input.onchange = e => {
|
_input.onchange = e => {
|
||||||
this.localConfigWrapper.config[dictName] = _input.checked;
|
WuhuConfig.set(dictName, _input.checked, true);
|
||||||
if (changeEv) changeEv(e);
|
if (changeEv) changeEv(e);
|
||||||
};
|
};
|
||||||
new_node.appendChild(switcher.getBase());
|
new_node.appendChild(switcher.getBase());
|
||||||
@ -325,12 +278,11 @@ export default class CommonUtils {
|
|||||||
}
|
}
|
||||||
case 'button': {
|
case 'button': {
|
||||||
new_node = document.createElement('div');
|
new_node = document.createElement('div');
|
||||||
let { domId, domText, isTornBtn, clickFunc } = setting;
|
let { domId, domText, clickFunc } = setting;
|
||||||
let btn = document.createElement('button');
|
let btn = document.createElement('button');
|
||||||
(tip) && (btn.setAttribute('title', tip));
|
(tip) && (btn.setAttribute('title', tip));
|
||||||
btn.id = domId;
|
btn.id = domId;
|
||||||
btn.innerHTML = domText;
|
btn.innerHTML = domText;
|
||||||
if (isTornBtn) btn.classList.add('torn-btn');
|
|
||||||
btn.addEventListener('click', clickFunc);
|
btn.addEventListener('click', clickFunc);
|
||||||
new_node.appendChild(btn);
|
new_node.appendChild(btn);
|
||||||
break;
|
break;
|
||||||
@ -348,11 +300,11 @@ export default class CommonUtils {
|
|||||||
let option = document.createElement('option');
|
let option = document.createElement('option');
|
||||||
option.value = domVal;
|
option.value = domVal;
|
||||||
option.innerHTML = domText;
|
option.innerHTML = domText;
|
||||||
option.selected = i === this.localConfigWrapper.config[dictName];
|
option.selected = i === WuhuConfig.get(dictName);
|
||||||
option.innerHTML = domText;
|
option.innerHTML = domText;
|
||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
});
|
});
|
||||||
select.onchange = e => this.localConfigWrapper.config[dictName] = (<HTMLSelectElement>e.target).selectedIndex;
|
select.onchange = e => WuhuConfig.set(dictName, (<HTMLSelectElement>e.target).selectedIndex);
|
||||||
label.appendChild(text);
|
label.appendChild(text);
|
||||||
label.appendChild(select);
|
label.appendChild(select);
|
||||||
new_node.appendChild(label);
|
new_node.appendChild(label);
|
||||||
@ -369,87 +321,4 @@ export default class CommonUtils {
|
|||||||
// 移动节点
|
// 移动节点
|
||||||
return root_node.appendChild(new_node);
|
return root_node.appendChild(new_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public exportTextFile(filename, content) {
|
|
||||||
const tmp = document.createElement('a');
|
|
||||||
tmp.href = URL.createObjectURL(new Blob(content, { type: 'text/plain', endings: 'transparent' }));
|
|
||||||
tmp.download = filename;
|
|
||||||
tmp.click();
|
|
||||||
tmp.remove();
|
|
||||||
URL.revokeObjectURL(tmp.href);
|
|
||||||
}
|
|
||||||
|
|
||||||
public isValidUid(id: string | number): boolean {
|
|
||||||
if (typeof id === 'string') {
|
|
||||||
return /^[0-9]{1,7}$/.test(id);
|
|
||||||
} else {
|
|
||||||
return /^[0-9]{1,7}$/.test(id.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public getTravelStage(): TRAVEL_STATE {
|
|
||||||
let global = Container.factory(Global);
|
|
||||||
if (global.bodyAttrs["data-abroad"] === 'false') {
|
|
||||||
return TRAVEL_STATE.IN_TORN;
|
|
||||||
}
|
|
||||||
// 海外落地:abroad
|
|
||||||
else if (global.bodyAttrs["data-traveling"] === 'false') {
|
|
||||||
return TRAVEL_STATE.ABROAD;
|
|
||||||
}
|
|
||||||
// 飞行中:traveling+abroad
|
|
||||||
else {
|
|
||||||
return TRAVEL_STATE.FLYING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public matchOne(src: string, reg: string | RegExp): string {
|
|
||||||
let regExp = typeof reg === 'string' ? new RegExp(reg) : reg,
|
|
||||||
ret = null;
|
|
||||||
let match = src.match(regExp);
|
|
||||||
if (match.length > 0) ret = match[0];
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 把秒数字格式化为
|
|
||||||
*
|
|
||||||
* `日 时 分 秒`
|
|
||||||
* @param s
|
|
||||||
*/
|
|
||||||
public secondsFormat(s: number): string {
|
|
||||||
let gap = '日 时 分 秒'.split(' ');
|
|
||||||
let last = s;
|
|
||||||
let formatDate = [];
|
|
||||||
let days = last / 86400 | 0;
|
|
||||||
formatDate.push(days);
|
|
||||||
last -= days * 86400;
|
|
||||||
let hours = last / 3600 | 0;
|
|
||||||
formatDate.push(hours);
|
|
||||||
last -= hours * 3600;
|
|
||||||
let mins = last / 60 | 0;
|
|
||||||
formatDate.push(mins);
|
|
||||||
last -= mins * 60;
|
|
||||||
formatDate.push(last);
|
|
||||||
let ret = '';
|
|
||||||
formatDate.forEach((num, i) => {
|
|
||||||
if (num > 0) {
|
|
||||||
let twoDig = i === 0 ? num : ('0' + num).slice(-2);
|
|
||||||
ret += twoDig + gap[i];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key id或物品名
|
|
||||||
* @param m1 id->name map
|
|
||||||
* @param m2 name->item map
|
|
||||||
*/
|
|
||||||
public getItemByIdOrName(key: string, m1, m2: {
|
|
||||||
[k: string]: Partial<InventoryItemInfo>
|
|
||||||
}): Partial<InventoryItemInfo> {
|
|
||||||
return m1[key] ? m2[m1[key]] : m2[key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CommonUtilsKey = Symbol('CommonUtilsKey') as InjectionKey<CommonUtils>;
|
|
||||||
@ -1,33 +1,30 @@
|
|||||||
import DIALOG_MSG_BOX_HTML from "../../../static/html/dialog_msg_box.html";
|
import Log from "../Log";
|
||||||
import Logger from "../Logger";
|
import DIALOG_MSG_BOX_HTML from "../../static/html/dialog_msg_box.html";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
|
|
||||||
export default class DialogMsgBox {
|
export default class DialogMsgBox {
|
||||||
private static existed = false;
|
private static existed = false;
|
||||||
private readonly container: HTMLElement;
|
private readonly container: HTMLElement;
|
||||||
|
|
||||||
constructor(msg: string, opt: DialogMsgBoxOptions,
|
constructor(msg: string, opt: DialogMsgBoxOptions) {
|
||||||
private readonly logger: Logger = Container.factory(Logger)) {
|
Log.info('创建DialogMsgBox', { msg, opt });
|
||||||
logger.info('创建DialogMsgBox', { msg, opt });
|
let { title = '提示', callback } = opt;
|
||||||
let { title = '提示', callback, cancel } = opt;
|
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
logger.error('无callback');
|
Log.error('无callback');
|
||||||
throw new Error('无callback');
|
throw new Error('无callback');
|
||||||
}
|
}
|
||||||
if (DialogMsgBox.existed) {
|
if (DialogMsgBox.existed) {
|
||||||
logger.error('无法创建DialogMsgBox:已存在');
|
Log.error('无法创建DialogMsgBox:已存在');
|
||||||
throw new Error('无法创建DialogMsgBox:已存在');
|
throw new Error('无法创建DialogMsgBox:已存在');
|
||||||
}
|
}
|
||||||
this.container = document.createElement('div');
|
this.container = document.createElement('div');
|
||||||
this.container.id = 'wh-dialog';
|
this.container.id = 'wh-dialog';
|
||||||
this.container.innerHTML = DIALOG_MSG_BOX_HTML.replace('{{}}', title).replace('{{}}', msg);
|
this.container.innerHTML = DIALOG_MSG_BOX_HTML.replace('{{}}', title).replace('{{}}', msg);
|
||||||
let [confirm, cancelBtn] = Array.from(this.container.querySelectorAll('button'));
|
let [confirm, cancel] = Array.from(this.container.querySelectorAll('button'));
|
||||||
confirm.addEventListener('click', () => {
|
confirm.addEventListener('click', () => {
|
||||||
callback(this.container);
|
callback(this.container);
|
||||||
this.destroy();
|
this.destroy();
|
||||||
});
|
});
|
||||||
cancelBtn.addEventListener('click', () => {
|
cancel.addEventListener('click', () => {
|
||||||
cancel ? cancel() : null;
|
|
||||||
this.destroy();
|
this.destroy();
|
||||||
});
|
});
|
||||||
document.body.append(this.container);
|
document.body.append(this.container);
|
||||||
@ -53,5 +50,4 @@ export default class DialogMsgBox {
|
|||||||
interface DialogMsgBoxOptions {
|
interface DialogMsgBoxOptions {
|
||||||
title?: string;
|
title?: string;
|
||||||
callback: Function;
|
callback: Function;
|
||||||
cancel?: Function;
|
|
||||||
}
|
}
|
||||||
38
src/class/utils/FetchUtils.ts
Normal file
38
src/class/utils/FetchUtils.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Log from "../Log";
|
||||||
|
|
||||||
|
export default class FetchUtils extends WuhuBase {
|
||||||
|
className = 'FetchUtils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包装jquery ajax 异步返回string
|
||||||
|
* @param url
|
||||||
|
* @param method
|
||||||
|
*/
|
||||||
|
public ajax(url: string, method: 'GET' | 'POST'): Promise<string> {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
$.ajax({
|
||||||
|
method: method,
|
||||||
|
url: url,
|
||||||
|
success: function (data) {
|
||||||
|
res(data)
|
||||||
|
},
|
||||||
|
error: function (e) {
|
||||||
|
rej(e)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public fetchText(url: string, init: RequestInit = null): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) =>
|
||||||
|
window.fetch(url, init)
|
||||||
|
.then(res => res.text())
|
||||||
|
.then(t => resolve(t))
|
||||||
|
.catch(err => {
|
||||||
|
Log.error('fetchText出错了', err);
|
||||||
|
reject(err);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/class/utils/InfoUtils.ts
Normal file
58
src/class/utils/InfoUtils.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import Alert from "./Alert";
|
||||||
|
import ISidebarData from "../../interface/ISidebarData";
|
||||||
|
import Log from "../Log";
|
||||||
|
import CommonUtils from "./CommonUtils";
|
||||||
|
|
||||||
|
export default class InfoUtils extends WuhuBase {
|
||||||
|
className = 'InfoUtils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回玩家信息的对象 { playername: string, userID: number }
|
||||||
|
* @return {PlayerInfo} rs
|
||||||
|
*/
|
||||||
|
public getPlayerInfo(): PlayerInfo {
|
||||||
|
const node = document.querySelector('script[uid]');
|
||||||
|
if (node) {
|
||||||
|
return {
|
||||||
|
playername: node.getAttribute('name'),
|
||||||
|
userID: parseInt(node.getAttribute('uid')),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new Alert('严重错误:芜湖助手无法获取用户数据,已退出');
|
||||||
|
throw '芜湖助手无法获取用户数据';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getSessionData(): Promise<ISidebarData> {
|
||||||
|
let field: string = 'sidebarData' + this.getPlayerInfo().userID;
|
||||||
|
let ret: ISidebarData = {};
|
||||||
|
return new Promise(async resolve => {
|
||||||
|
let c = 0;
|
||||||
|
while (!sessionStorage.getItem(field) && c < 50) {
|
||||||
|
c++;
|
||||||
|
await CommonUtils.getInstance().sleep(10);
|
||||||
|
}
|
||||||
|
if (sessionStorage.getItem(field)) {
|
||||||
|
ret = JSON.parse(sessionStorage.getItem(field));
|
||||||
|
} else {
|
||||||
|
Log.info('无法从sessionStorage获取数据')
|
||||||
|
ret = await (await CommonUtils.ajaxFetch({
|
||||||
|
url: window.addRFC('/sidebarAjaxAction.php?q=getSidebarData'),
|
||||||
|
method: 'POST',
|
||||||
|
})).json();
|
||||||
|
sessionStorage.setItem(field, JSON.stringify(ret));
|
||||||
|
}
|
||||||
|
ret.headerData = JSON.parse(sessionStorage.getItem('headerData'));
|
||||||
|
resolve(ret);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getSidebarData() {
|
||||||
|
return (await this.getSessionData()).areas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getUserState() {
|
||||||
|
return (await this.getSessionData()).headerData.user.state;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,7 @@
|
|||||||
import ClassName from "../../container/ClassName";
|
import WuhuBase from "../WuhuBase";
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
|
|
||||||
@ClassName('MDUtils')
|
export default class MDUtils extends WuhuBase {
|
||||||
@Injectable()
|
className = 'MDUtils';
|
||||||
export default class MDUtils {
|
|
||||||
/**
|
/**
|
||||||
* 解析 Markdown 内容
|
* 解析 Markdown 内容
|
||||||
* @param {String} from
|
* @param {String} from
|
||||||
@ -1,12 +1,7 @@
|
|||||||
import ClassName from "../../container/ClassName";
|
import WuhuBase from "../WuhuBase";
|
||||||
import { Injectable } from "../../container/Injectable";
|
|
||||||
import { InjectionKey } from "vue";
|
|
||||||
|
|
||||||
@ClassName('MathUtils')
|
export default class MathUtils extends WuhuBase {
|
||||||
@Injectable()
|
|
||||||
export default class MathUtils {
|
|
||||||
className = 'MathUtils';
|
className = 'MathUtils';
|
||||||
|
|
||||||
// 得到一个两数之间的随机整数
|
// 得到一个两数之间的随机整数
|
||||||
public getRandomInt(min: number, max: number): number {
|
public getRandomInt(min: number, max: number): number {
|
||||||
min = Math.ceil(min);
|
min = Math.ceil(min);
|
||||||
@ -15,5 +10,3 @@ export default class MathUtils {
|
|||||||
return Math.floor(Math.random() * (max - min)) + min;
|
return Math.floor(Math.random() * (max - min)) + min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MathUtilsKey = Symbol('MathUtilsKey') as InjectionKey<MathUtils>
|
|
||||||
45
src/class/utils/NotificationUtils.ts
Normal file
45
src/class/utils/NotificationUtils.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import IWHNotify from "../../interface/IWHNotify";
|
||||||
|
import Log from "../Log";
|
||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
|
||||||
|
export default class NotificationUtils extends WuhuBase {
|
||||||
|
className = 'NotificationUtils';
|
||||||
|
private permission: boolean = window.Notification && window.Notification.permission === 'granted';
|
||||||
|
|
||||||
|
public push(msg: string, options: IWHNotify = {}): void {
|
||||||
|
let { notifies } = NotificationUtils.glob;
|
||||||
|
|
||||||
|
if (options.sysNotify && this.permission) {
|
||||||
|
let tmpNode = document.createElement('p');
|
||||||
|
tmpNode.innerHTML = msg;
|
||||||
|
let notify = new Notification('芜湖助手', {
|
||||||
|
body: Log.getTime() + '\r\n' + tmpNode.innerText,
|
||||||
|
// requireInteraction: true,
|
||||||
|
// renotify: true,
|
||||||
|
// tag: '芜湖助手' + Utils.getRandomInt(0, 99),
|
||||||
|
});
|
||||||
|
let id = notifies.count++;
|
||||||
|
notifies[id] = notify;
|
||||||
|
notify.addEventListener(
|
||||||
|
'close',
|
||||||
|
() => {
|
||||||
|
notifies[id] = null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
notify.addEventListener(
|
||||||
|
'click',
|
||||||
|
() => {
|
||||||
|
options.sysNotifyClick ? options.sysNotifyClick() : null;
|
||||||
|
window.focus();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
notify.addEventListener(
|
||||||
|
'show',
|
||||||
|
() => {
|
||||||
|
// setTimeout(() => notify.close(), (options.timeout || 3) * 1000);
|
||||||
|
Log.info('通知id: ', id)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/class/utils/Popup.ts
Normal file
54
src/class/utils/Popup.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import POPUP_HTML from "../../static/html/popup.html";
|
||||||
|
import Log from "../Log";
|
||||||
|
|
||||||
|
export default class Popup extends WuhuBase {
|
||||||
|
className = 'Popup';
|
||||||
|
private readonly container: HTMLElement = null;
|
||||||
|
private readonly node: HTMLElement = null;
|
||||||
|
|
||||||
|
constructor(innerHTML: string, title: string = '芜湖助手') {
|
||||||
|
super();
|
||||||
|
if (Popup.glob.popup_node) {
|
||||||
|
Log.info('关闭前一个弹窗');
|
||||||
|
Popup.glob.popup_node.close();
|
||||||
|
}
|
||||||
|
Log.info('新建弹窗', { innerHTML, title });
|
||||||
|
const popup = document.createElement('div');
|
||||||
|
popup.id = 'wh-popup';
|
||||||
|
popup.innerHTML = POPUP_HTML.replace('{{}}', title).replace('{{}}', innerHTML);
|
||||||
|
document.body.append(popup);
|
||||||
|
popup.addEventListener('click', e => {
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
if (e.target === popup) this.close();
|
||||||
|
});
|
||||||
|
this.container = popup;
|
||||||
|
this.node = popup.querySelector('#wh-popup-cont');
|
||||||
|
this.hideChat();
|
||||||
|
Popup.glob.popup_node = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public close() {
|
||||||
|
this.container.remove();
|
||||||
|
this.showChat();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {HTMLElement} id=wh-popup-cont
|
||||||
|
*/
|
||||||
|
public getElement(): HTMLElement {
|
||||||
|
return this.node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private hideChat() {
|
||||||
|
document.querySelector('#chatRoot').classList.add('wh-hide');
|
||||||
|
}
|
||||||
|
|
||||||
|
private showChat() {
|
||||||
|
document.querySelector('#chatRoot').classList.remove('wh-hide');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 禁止单例调用
|
||||||
|
private getInstance() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,17 +1,12 @@
|
|||||||
/**
|
|
||||||
* 基于performance.now()包装的计时器
|
|
||||||
*/
|
|
||||||
export default class Timer {
|
export default class Timer {
|
||||||
private readonly startTime: number;
|
private readonly startTime: number;
|
||||||
|
|
||||||
public constructor() {
|
constructor() {
|
||||||
this.startTime = performance.now();
|
this.startTime = performance.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回计时器计数,毫秒、以ms结束
|
* 返回计时毫秒数以ms结束
|
||||||
*
|
|
||||||
* `'99ms'`
|
|
||||||
*/
|
*/
|
||||||
public getTimeMs(): string {
|
public getTimeMs(): string {
|
||||||
return ((performance.now() - this.startTime) | 0) + 'ms';
|
return ((performance.now() - this.startTime) | 0) + 'ms';
|
||||||
@ -1,16 +1,12 @@
|
|||||||
import Log from "../Log";
|
import Log from "../Log";
|
||||||
import MathUtils from "./MathUtils";
|
import MathUtils from "./MathUtils";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
|
|
||||||
export default class TornStyleBlock {
|
export default class TornStyleBlock {
|
||||||
private readonly baseElement: HTMLElement;
|
private readonly baseElement: HTMLElement;
|
||||||
private readonly headElement: HTMLElement;
|
private readonly headElement: HTMLElement;
|
||||||
private readonly elem: HTMLElement;
|
private readonly elem: HTMLElement;
|
||||||
|
|
||||||
public constructor(
|
public constructor(title: string) {
|
||||||
private readonly title: string,
|
|
||||||
private readonly mathUtils: MathUtils = Container.factory(MathUtils),
|
|
||||||
) {
|
|
||||||
this.baseElement = document.createElement('div');
|
this.baseElement = document.createElement('div');
|
||||||
this.headElement = document.createElement('div');
|
this.headElement = document.createElement('div');
|
||||||
this.elem = document.createElement('div');
|
this.elem = document.createElement('div');
|
||||||
@ -23,7 +19,7 @@ export default class TornStyleBlock {
|
|||||||
// hr.classList.add('delimiter-999', 'm-top10', 'm-bottom10');
|
// hr.classList.add('delimiter-999', 'm-top10', 'm-bottom10');
|
||||||
|
|
||||||
this.baseElement.append(this.headElement, this.elem);
|
this.baseElement.append(this.headElement, this.elem);
|
||||||
this.baseElement.id = 'WHTornStyleBlock' + mathUtils.getRandomInt(0, 100);
|
this.baseElement.id = 'WHTornStyleBlock' + MathUtils.getInstance().getRandomInt(0, 100);
|
||||||
this.baseElement.insertAdjacentHTML('beforeend', '<hr class="delimiter-999 m-top10 m-bottom10" />');
|
this.baseElement.insertAdjacentHTML('beforeend', '<hr class="delimiter-999 m-top10 m-bottom10" />');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,30 +1,23 @@
|
|||||||
import MathUtils from "./MathUtils";
|
import MathUtils from "./MathUtils";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
|
|
||||||
export default class TornStyleSwitch {
|
export default class TornStyleSwitch {
|
||||||
private readonly baseElement;
|
private readonly baseElement;
|
||||||
private readonly randomId;
|
private readonly randomId;
|
||||||
private readonly input;
|
|
||||||
|
|
||||||
constructor(
|
constructor(label: string, checked: boolean = false) {
|
||||||
private readonly label: string,
|
this.randomId = MathUtils.getInstance().getRandomInt(100, 2000);
|
||||||
private readonly checked: boolean = false,
|
|
||||||
private readonly mathUtils: MathUtils = Container.factory(MathUtils),
|
|
||||||
) {
|
|
||||||
this.randomId = mathUtils.getRandomInt(100, 2000);
|
|
||||||
this.baseElement = document.createElement('span');
|
this.baseElement = document.createElement('span');
|
||||||
this.baseElement.id = 'WHSwitch' + this.randomId;
|
this.baseElement.id = 'WHSwitch' + this.randomId;
|
||||||
this.baseElement.innerHTML = `<input class="checkbox-css" type="checkbox" id="WHCheck${ this.randomId }" ${ checked ? 'checked' : '' }/>
|
this.baseElement.innerHTML = `<input class="checkbox-css" type="checkbox" id="WHCheck${ this.randomId }" ${ checked ? 'checked' : '' }/>
|
||||||
<label for="WHCheck${ this.randomId }" class="non-selection marker-css">${ label }</label>`;
|
<label for="WHCheck${ this.randomId }" class="non-selection marker-css">${ label }</label>`;
|
||||||
this.input = this.baseElement.querySelector('input') as HTMLInputElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBase(): HTMLElement {
|
public getBase() {
|
||||||
return this.baseElement
|
return this.baseElement
|
||||||
};
|
};
|
||||||
|
|
||||||
public getInput(): HTMLInputElement {
|
public getInput(): HTMLInputElement {
|
||||||
return this.input;
|
return this.baseElement.querySelector('input');
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHtml(): string {
|
public getHtml(): string {
|
||||||
2699
src/dictionary/translation.ts
Normal file
2699
src/dictionary/translation.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,7 @@
|
|||||||
import Popup from "../../class/utils/Popup";
|
import Popup from "../../class/utils/Popup";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
import Logger from "../../class/Logger";
|
|
||||||
|
|
||||||
// 传单助手
|
// 传单助手
|
||||||
export default function adHelper() {
|
export default function adHelper() {
|
||||||
Container.factory(Logger).error('adHelper')
|
|
||||||
let popup = new Popup('', '传单助手').getElement();
|
let popup = new Popup('', '传单助手').getElement();
|
||||||
document.querySelector('#chatRoot').classList.remove('wh-hide');
|
document.querySelector('#chatRoot').classList.remove('wh-hide');
|
||||||
let info = document.createElement('p');
|
let info = document.createElement('p');
|
||||||
290
src/func/module/attackHelper.ts
Normal file
290
src/func/module/attackHelper.ts
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
import Device from "../../enum/Device";
|
||||||
|
import WuhuBase from "../../class/WuhuBase";
|
||||||
|
import WuhuConfig from "../../class/WuhuConfig";
|
||||||
|
import CommonUtils from "../../class/utils/CommonUtils";
|
||||||
|
import Log from "../../class/Log";
|
||||||
|
import Alert from "../../class/utils/Alert";
|
||||||
|
import MathUtils from "../../class/utils/MathUtils";
|
||||||
|
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
|
||||||
|
import ATTACK_HELPER_CSS from "../../static/css/attack_helper.css";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO class重构、各功能联动
|
||||||
|
*/
|
||||||
|
export default async function attackHelper(): Promise<null> {
|
||||||
|
let { href, device } = WuhuBase.glob;
|
||||||
|
// 攻击页面
|
||||||
|
if (href.contains(/loader\.php\?sid=attack/)) {
|
||||||
|
let stop_reload = false;
|
||||||
|
const quickAttIndex = WuhuConfig.get('quickAttIndex');
|
||||||
|
const quickFinishAtt = WuhuConfig.get('quickFinishAtt');
|
||||||
|
const attReload = WuhuConfig.get('attReload');
|
||||||
|
|
||||||
|
// 光速刷新按钮
|
||||||
|
ActionButtonUtils.getInstance().add('光速刷新', doAttackReload);
|
||||||
|
|
||||||
|
// 自刷新
|
||||||
|
let audio_played_flag;
|
||||||
|
// @ts-ignore TODO
|
||||||
|
if (attReload !== 6 && stop_reload !== true) {
|
||||||
|
const selector_device_map = {
|
||||||
|
'pc': '#defender div[class^="modal___"]',
|
||||||
|
'mobile': '#attacker div[class^="modal___"]',
|
||||||
|
'tablet': '',
|
||||||
|
};
|
||||||
|
const selector = selector_device_map[device];
|
||||||
|
CommonUtils.elementReady(selector).then(elem => {
|
||||||
|
if (!elem.querySelector('button')) {
|
||||||
|
if (WuhuConfig.get('attReload') === 0 && stop_reload !== true) {
|
||||||
|
doAttackReload();
|
||||||
|
} else {
|
||||||
|
let reload_flag;
|
||||||
|
const timeout = WuhuConfig.get('attReload') * 1000 + MathUtils.getInstance().getRandomInt(-500, 500);
|
||||||
|
Log.info(`[WH] ${ timeout / 1000 }s 后自动刷新`);
|
||||||
|
window.setInterval(() => {
|
||||||
|
if (reload_flag === undefined) {
|
||||||
|
reload_flag = true;
|
||||||
|
} else if (stop_reload !== true) {
|
||||||
|
// window.location.reload();
|
||||||
|
doAttackReload();
|
||||||
|
}
|
||||||
|
}, timeout);
|
||||||
|
}
|
||||||
|
} else if (audio_played_flag === undefined) {
|
||||||
|
audio_played_flag = true;
|
||||||
|
let play_time = 0;
|
||||||
|
const audio_play_id = window.setInterval(() => {
|
||||||
|
const $audio = document.createElement('audio');
|
||||||
|
$audio.src = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3';
|
||||||
|
$audio.play().then();
|
||||||
|
play_time++;
|
||||||
|
if (play_time === 3) clearInterval(audio_play_id);
|
||||||
|
}, 600);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 光速拔刀
|
||||||
|
if (quickAttIndex !== 6) {
|
||||||
|
// await CommonUtils.querySelector('#react-root div[class^="players___"]'); // pc 可用
|
||||||
|
await CommonUtils.querySelector('#react-root div[class^="playersModelWrap___"]');
|
||||||
|
Log.info('响应式内容已加载, 查找攻击按钮');
|
||||||
|
// const btn = await CommonUtils.elementReady('div[class^="modal___"] button');
|
||||||
|
/**
|
||||||
|
* pc #defender
|
||||||
|
* mobile #attacker
|
||||||
|
*/
|
||||||
|
const btn = <HTMLInputElement>(document.querySelector('#attacker button') || document.querySelector('#defender button'));
|
||||||
|
Log.info('操作按钮按钮', { btn });
|
||||||
|
if (!btn.innerText.toLowerCase().includes('fight')) {
|
||||||
|
Log.info('未找到攻击按钮, 退出');
|
||||||
|
} else {
|
||||||
|
// 判断是否存在脚踢
|
||||||
|
const hasKick = !!document.querySelector('#weapon_boots');
|
||||||
|
// modal层
|
||||||
|
// const modal: HTMLElement = document.querySelector('div[class^="modal___"]');
|
||||||
|
Log.info(`当前设备类型是${ device }`);
|
||||||
|
// 区分设备
|
||||||
|
switch (device) {
|
||||||
|
case Device.PC: {
|
||||||
|
Log.info(`开始调整按钮位置`);
|
||||||
|
// 隐藏modal层
|
||||||
|
// modal.style.display = 'none';
|
||||||
|
// 根据选择的武器调整css
|
||||||
|
let css_top = '0';
|
||||||
|
switch (WuhuConfig.get('quickAttIndex')) {
|
||||||
|
// weapon_second
|
||||||
|
case 1: {
|
||||||
|
css_top = '97px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// weapon_melee
|
||||||
|
case 2: {
|
||||||
|
css_top = '194px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// weapon_temp
|
||||||
|
case 3: {
|
||||||
|
css_top = '291px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// weapon_fists
|
||||||
|
case 4:
|
||||||
|
// weapon_boots
|
||||||
|
case 5: {
|
||||||
|
css_top = '375px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CommonUtils.addStyle(ATTACK_HELPER_CSS);
|
||||||
|
CommonUtils.addStyle(`.wh-move-btn #defender div[class^="modal___"]{top: ${ css_top };}`);
|
||||||
|
document.body.classList.add('wh-move-btn');
|
||||||
|
// 绑定点击事件 联动【光速跑路】
|
||||||
|
btn.onclick = () => {
|
||||||
|
if (quickFinishAtt !== 3) {
|
||||||
|
btn.remove();
|
||||||
|
// 停止自动刷新
|
||||||
|
stop_reload = true;
|
||||||
|
} else {
|
||||||
|
document.body.classList.remove('wh-move-btn');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Device.MOBILE: {
|
||||||
|
Log.info(`开始调整按钮位置`);
|
||||||
|
// 加入css
|
||||||
|
let css_top = '0';
|
||||||
|
let slot_height = '76px';
|
||||||
|
// 判断有没有脚踢
|
||||||
|
if (hasKick) {
|
||||||
|
// 根据选择的武器调整
|
||||||
|
switch (WuhuConfig.get('quickAttIndex')) {
|
||||||
|
case 1: { // weapon_second
|
||||||
|
css_top = '76px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: { // weapon_melee
|
||||||
|
css_top = '152px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: { // weapon_temp
|
||||||
|
css_top = '228px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: { // weapon_fists
|
||||||
|
css_top = '304px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 5: { // weapon_boots
|
||||||
|
css_top = '380px';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const slot = document.querySelector('#weapon_main') as HTMLElement;
|
||||||
|
const height = slot.offsetHeight + 1;
|
||||||
|
// TODO 待验证
|
||||||
|
slot_height = height + 'px';
|
||||||
|
// 根据选择的武器调整
|
||||||
|
switch (WuhuConfig.get('quickAttIndex')) {
|
||||||
|
case 1: { // weapon_second
|
||||||
|
css_top = `${ height }px`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: { // weapon_melee
|
||||||
|
css_top = `${ height * 2 }px`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: { // weapon_temp
|
||||||
|
css_top = `${ height * 3 }px`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: { // weapon_fists
|
||||||
|
css_top = `${ height * 4 }px`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 5: { // weapon_boots
|
||||||
|
css_top = `${ height * 5 }px`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const css_rule = ATTACK_HELPER_CSS.replace('CSSVAR', css_top).replace('CSSVAR', slot_height);
|
||||||
|
// `
|
||||||
|
// .wh-move-btn #attacker div[class^="modal___"]{display: block;width: 0;top: ${ css_top };left:0;height:0;}
|
||||||
|
// .wh-move-btn #attacker div[class^="dialog___"]{border:0;width:80px;height:${ slot_height };}
|
||||||
|
// .wh-move-btn #attacker div[class^="colored___"]{display:block;padding:0;}
|
||||||
|
// .wh-move-btn #attacker div[class^="title___"]{height:0;}
|
||||||
|
// .wh-move-btn #attacker button{width:100%;margin:0;height:63px;white-space:normal;}
|
||||||
|
// `;
|
||||||
|
CommonUtils.addStyle(css_rule);
|
||||||
|
document.body.classList.toggle('wh-move-btn');
|
||||||
|
btn.onclick = () => {
|
||||||
|
if (WuhuConfig.get('quickFinishAtt') !== 3) {
|
||||||
|
btn.remove();
|
||||||
|
// 停止自动刷新
|
||||||
|
stop_reload = true;
|
||||||
|
} else {
|
||||||
|
document.body.classList.toggle('wh-move-btn');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Device.TABLET: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 自动开打
|
||||||
|
if (WuhuConfig.get('autoStartFinish') === true) {
|
||||||
|
if (btn.innerText.includes('(')) {
|
||||||
|
let interval_id = window.setInterval(() => {
|
||||||
|
if (!btn) {
|
||||||
|
clearInterval(interval_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
btn.click();
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
} else {
|
||||||
|
btn.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 光速跑路 TODO 暂时关闭
|
||||||
|
// if (quickFinishAtt !== 3) {
|
||||||
|
// const user_btn_select = ['leave', 'mug', 'hosp'][WuhuConfig.get('quickFinishAtt')];
|
||||||
|
// const wrap = document.querySelector('#react-root');
|
||||||
|
// Log.info('光速跑路选项选中:', user_btn_select);
|
||||||
|
// new MutationObserver(() => {
|
||||||
|
// const btn_arr = document.querySelectorAll('div[class^="dialogButtons___"] button') as unknown as HTMLButtonElement[];
|
||||||
|
// if (btn_arr.length > 1) btn_arr.forEach(btn => {
|
||||||
|
// btn = btn as HTMLButtonElement;
|
||||||
|
// const flag = btn.innerText.toLowerCase().includes(user_btn_select);
|
||||||
|
// Log.info('按钮内容:', btn.innerText, ',是否包含选中:', flag);
|
||||||
|
// if (!flag) btn.style.display = 'none';
|
||||||
|
// // 自动结束
|
||||||
|
// else if (WuhuConfig.get('autoStartFinish') === true) {
|
||||||
|
// try {
|
||||||
|
// btn.click();
|
||||||
|
// } catch {
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }).observe(wrap, { subtree: true, attributes: true, childList: true });
|
||||||
|
// }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 错误的攻击页面
|
||||||
|
if (WuhuConfig.get('attRelocate') && href.includes('loader2.php')) {
|
||||||
|
const spl = window.location.href.trim().split('=');
|
||||||
|
const uid = spl[spl.length - 1];
|
||||||
|
if (!/^\d+$/.test(uid)) return;
|
||||||
|
window.location.href = `https://www.torn.com/loader.php?sid=attack&user2ID=${ uid }`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 战斗页面快速刷新
|
||||||
|
function doAttackReload() {
|
||||||
|
if (!window.ReactDOM) {
|
||||||
|
new Alert('光速刷新失败:未找到React对象');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let react_root = document.querySelector('#react-root');
|
||||||
|
if (!react_root.querySelector('#attacker')) return;
|
||||||
|
let script = document.querySelector('script[src*="/builds/attack/"]');
|
||||||
|
let url = script.src;
|
||||||
|
if (!url.contains('app.js')) return;
|
||||||
|
window.ReactDOM.unmountComponentAtNode(react_root);
|
||||||
|
script.remove();
|
||||||
|
let node = document.createElement('script');
|
||||||
|
node.src = url;
|
||||||
|
node.type = 'text/javascript';
|
||||||
|
document.head.appendChild(node);
|
||||||
|
}
|
||||||
@ -1,26 +1,22 @@
|
|||||||
import WT_HTML from "../../../static/html/xmasTown/wt.html";
|
import WuhuConfig from "../../class/WuhuConfig";
|
||||||
import WT_XMAS_TOWN_HTML from "../../../static/html/xmasTown/wt_xmas_town.html";
|
import WT_HTML from "../../static/html/xmasTown/wt.html";
|
||||||
import WT_MALTESE_SNOW_GLOBE_HTML from "../../../static/html/xmasTown/wt_maltese_snow_globe.html";
|
import WT_XMAS_TOWN_HTML from "../../static/html/xmasTown/wt_xmas_town.html";
|
||||||
import WT_LONG_WAY_FROM_HOME_HTML from "../../../static/html/xmasTown/wt_long_way_from_home.html";
|
import WT_MALTESE_SNOW_GLOBE_HTML from "../../static/html/xmasTown/wt_maltese_snow_globe.html";
|
||||||
import WT_CHEDBURN_TOWERS_HTML from "../../../static/html/xmasTown/wt_chedburn_towers.html";
|
import WT_LONG_WAY_FROM_HOME_HTML from "../../static/html/xmasTown/wt_long_way_from_home.html";
|
||||||
import WT_KIDNAPPED_SANTA_HTML from "../../../static/html/xmasTown/wt_kidnapped_santa.html";
|
import WT_CHEDBURN_TOWERS_HTML from "../../static/html/xmasTown/wt_chedburn_towers.html";
|
||||||
import WT_HOLIDAY_TERROR_HTML from "../../../static/html/xmasTown/wt_holiday_terror.html";
|
import WT_KIDNAPPED_SANTA_HTML from "../../static/html/xmasTown/wt_kidnapped_santa.html";
|
||||||
import WT_AMONG_US_HTML from "../../../static/html/xmasTown/wt_among_us.html";
|
import WT_HOLIDAY_TERROR_HTML from "../../static/html/xmasTown/wt_holiday_terror.html";
|
||||||
import WT_KISS_MY_FESTIVUS_HTML from "../../../static/html/xmasTown/wt_kiss_my_festivus.html";
|
import WT_AMONG_US_HTML from "../../static/html/xmasTown/wt_among_us.html";
|
||||||
import WT_STANLEY_HOTEL_HTML from "../../../static/html/xmasTown/wt_stanley_hotel.html";
|
import WT_KISS_MY_FESTIVUS_HTML from "../../static/html/xmasTown/wt_kiss_my_festivus.html";
|
||||||
import WT_DOGGOQUEST_HTML from "../../../static/html/xmasTown/wt_doggoQuest.html";
|
import WT_STANLEY_HOTEL_HTML from "../../static/html/xmasTown/wt_stanley_hotel.html";
|
||||||
import WT_POKEMON_CT_HTML from "../../../static/html/xmasTown/wt_pokemon_ct.html";
|
import WT_DOGGOQUEST_HTML from "../../static/html/xmasTown/wt_doggoQuest.html";
|
||||||
import WT_WINTER_IN_GATLIN_HTML from "../../../static/html/xmasTown/wt_winter_in_gatlin.html";
|
import WT_POKEMON_CT_HTML from "../../static/html/xmasTown/wt_pokemon_ct.html";
|
||||||
import XMAS_TOWN_NOTIFY_HTML from "../../../static/html/xmasTown/xmas_town_notify.html";
|
import WT_WINTER_IN_GATLIN_HTML from "../../static/html/xmasTown/wt_winter_in_gatlin.html";
|
||||||
import { Container } from "../../container/Container";
|
import XMAS_TOWN_NOTIFY_HTML from "../../static/html/xmasTown/xmas_town_notify.html";
|
||||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
|
||||||
|
|
||||||
export default function christmasTownHelper() {
|
export default function christmasTownHelper() {
|
||||||
const localConfigWrapper = Container.factory(LocalConfigWrapper);
|
|
||||||
|
|
||||||
let $root = document.querySelector('#christmastownroot');
|
let $root = document.querySelector('#christmastownroot');
|
||||||
const xmasTownWT = localConfigWrapper.config.xmasTownWT;
|
const [xmasTownWT, xmasTownNotify] = WuhuConfig.get(['xmasTownWT', 'xmasTownNotify']);
|
||||||
const xmasTownNotify = localConfigWrapper.config.xmasTownNotify;
|
|
||||||
// 解密攻略
|
// 解密攻略
|
||||||
if (xmasTownWT) {
|
if (xmasTownWT) {
|
||||||
const insert_html = WT_HTML;
|
const insert_html = WT_HTML;
|
||||||
@ -257,7 +253,7 @@ export default function christmasTownHelper() {
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
dropHist[hist_key] = {
|
dropHist[hist_key] = {
|
||||||
pos: `[${ nearby_item.x },${ nearby_item.y }]`,
|
pos: `[${ nearby_item.x },${ nearby_item.y }]`,
|
||||||
data: $ct_title.firstChild.nodeValue.trim(),
|
map: $ct_title.firstChild.nodeValue.trim(),
|
||||||
last: `${ now.getFullYear() }-${ now.getMonth() + 1 }-${ now.getDate() } ${ now.getHours() }:${ now.getMinutes() }:${ now.getSeconds() }`,
|
last: `${ now.getFullYear() }-${ now.getMonth() + 1 }-${ now.getDate() } ${ now.getHours() }:${ now.getMinutes() }:${ now.getSeconds() }`,
|
||||||
name: item_name,
|
name: item_name,
|
||||||
id: Object.keys(dropHist).length,
|
id: Object.keys(dropHist).length,
|
||||||
@ -280,7 +276,7 @@ export default function christmasTownHelper() {
|
|||||||
const history = Object.keys(dropHist).map(key => dropHist[key]).sort((a, b) => a.id - b.id);
|
const history = Object.keys(dropHist).map(key => dropHist[key]).sort((a, b) => a.id - b.id);
|
||||||
let table_html = '';
|
let table_html = '';
|
||||||
history.forEach(e => {
|
history.forEach(e => {
|
||||||
table_html += `<tr><td>${ e.pos }</td><td>${ e.map ?? e.data }</td><td>${ e.name }</td><td>${ e.last }</td><td>${ e.isPassed ? '已取得' : '不确定' }</td></tr>`;
|
table_html += `<tr><td>${ e.pos }</td><td>${ e.map }</td><td>${ e.name }</td><td>${ e.last }</td><td>${ e.isPassed ? '已取得' : '不确定' }</td></tr>`;
|
||||||
});
|
});
|
||||||
$tbody.innerHTML = table_html;
|
$tbody.innerHTML = table_html;
|
||||||
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
|
localStorage.setItem('wh-loot-store', JSON.stringify(dropHist));
|
||||||
99
src/func/module/cityFinder.ts
Normal file
99
src/func/module/cityFinder.ts
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
import toThousands from "../utils/toThousands";
|
||||||
|
import CommonUtils from "../../class/utils/CommonUtils";
|
||||||
|
import Log from "../../class/Log";
|
||||||
|
import CITY_FINDER_CSS from "../../static/css/city_finder.css";
|
||||||
|
import TornStyleBlock from "../../class/utils/TornStyleBlock";
|
||||||
|
|
||||||
|
export default function cityFinder(): void {
|
||||||
|
CommonUtils.addStyle(CITY_FINDER_CSS);
|
||||||
|
// 物品名与价格
|
||||||
|
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);
|
||||||
|
|
||||||
|
let _base = new TornStyleBlock('捡垃圾助手').insert2Dom().append(info);
|
||||||
|
document.body.classList.add('wh-city-finds');
|
||||||
|
|
||||||
|
CommonUtils.COFetch('https://jjins.github.io/item_price_raw.json')
|
||||||
|
.then(r => items = JSON.parse(r))
|
||||||
|
.catch(err => {
|
||||||
|
Log.error(err);
|
||||||
|
items = undefined
|
||||||
|
});
|
||||||
|
CommonUtils.elementReady('div.leaflet-marker-pane').then(elem => {
|
||||||
|
// 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);
|
||||||
|
_base.append(finder_item);
|
||||||
|
});
|
||||||
|
// 未发现物品 返回
|
||||||
|
if (founds.length === 0) {
|
||||||
|
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';
|
||||||
|
// 橙色 449m以下
|
||||||
|
else if (value < 449000000) el.node.style.backgroundColor = '#ffc107';
|
||||||
|
// 红色 >449m
|
||||||
|
else if (value >= 449000000) el.node.style.backgroundColor = '#f44336';
|
||||||
|
total += items[el.id]['price'];
|
||||||
|
});
|
||||||
|
// header.innerHTML = `捡垃圾助手 - ${ founds.length } 个物品,总价值 $${ toThousands(total) }`;
|
||||||
|
_base.setTitle(`捡垃圾助手 - ${ founds.length } 个物品,总价值 $${ toThousands(total) }`);
|
||||||
|
};
|
||||||
|
// 未取到数据时添加循环来调用函数
|
||||||
|
if (items === null) {
|
||||||
|
// 15s超时
|
||||||
|
let timeout = 30;
|
||||||
|
const interval = window.setInterval(() => {
|
||||||
|
timeout--;
|
||||||
|
if (items !== null) {
|
||||||
|
displayNamePrice();
|
||||||
|
window.clearInterval(interval);
|
||||||
|
}
|
||||||
|
if (0 === timeout) {
|
||||||
|
Log.info('获取物品名称与价格信息超时')
|
||||||
|
window.clearInterval(interval)
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
// 无法跨域获取数据时
|
||||||
|
else if (items === undefined) {
|
||||||
|
info.innerHTML += '(当前平台暂不支持查询价格)';
|
||||||
|
}
|
||||||
|
// 调用函数
|
||||||
|
else {
|
||||||
|
displayNamePrice();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -1,36 +1,31 @@
|
|||||||
|
import WuhuBase from "../../class/WuhuBase";
|
||||||
import CommonUtils from "../../class/utils/CommonUtils";
|
import CommonUtils from "../../class/utils/CommonUtils";
|
||||||
|
import Log from "../../class/Log";
|
||||||
import Alert from "../../class/utils/Alert";
|
import Alert from "../../class/utils/Alert";
|
||||||
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
|
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
|
||||||
|
import WuhuConfig from "../../class/WuhuConfig";
|
||||||
import FetchUtils from "../../class/utils/FetchUtils";
|
import FetchUtils from "../../class/utils/FetchUtils";
|
||||||
import DEPO_CSS from "../../../static/css/depo.module.css";
|
import DEPO_CSS from "../../static/css/depo.css";
|
||||||
import TornStyleBlock from "../../class/utils/TornStyleBlock";
|
import TornStyleBlock from "../../class/utils/TornStyleBlock";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
|
||||||
import Logger from "../../class/Logger";
|
|
||||||
|
|
||||||
const fetchUtils = Container.factory(FetchUtils);
|
|
||||||
|
|
||||||
export default function depoHelper() {
|
export default function depoHelper() {
|
||||||
let logger: Logger = Container.factory(Logger);
|
let actionButtonUtils: ActionButtonUtils = ActionButtonUtils.getInstance();
|
||||||
let actionButtonUtils: ActionButtonUtils = Container.factory(ActionButtonUtils);
|
let { href } = WuhuBase.glob;
|
||||||
let localConfigWrapper: LocalConfigWrapper = Container.factory(LocalConfigWrapper);
|
|
||||||
let commonUtils: CommonUtils = Container.factory(CommonUtils);
|
|
||||||
let href = window.location.href;
|
|
||||||
let channel: 'CMPY' | 'FAC';
|
let channel: 'CMPY' | 'FAC';
|
||||||
const selector = { 'CMPY': "div#funds div.deposit", 'FAC': "div#armoury-donate div.cash" };
|
const selector = { 'CMPY': "div#funds div.deposit", 'FAC': "div#armoury-donate div.cash" };
|
||||||
// 公司
|
// 公司
|
||||||
if (href.includes('companies.php')) {
|
if (href.includes('companies.php')) {
|
||||||
channel = "CMPY";
|
channel = "CMPY";
|
||||||
// 公司转跳存钱
|
// 公司转跳存钱
|
||||||
if (!href.includes('funds') && localConfigWrapper.config.companyRedirect) {
|
if (!href.includes('funds') && WuhuConfig.get('companyRedirect')) {
|
||||||
const btn = document.getElementById('ui-id-9');
|
const btn = document.getElementById('ui-id-9');
|
||||||
if (btn) {
|
if (btn) {
|
||||||
btn.click();
|
btn.click();
|
||||||
logger.info('已自动打开存钱页面');
|
Log.info('已自动打开存钱页面');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 收起冰蛙表格
|
// 收起冰蛙表格
|
||||||
if (localConfigWrapper.config.companyBWCollapse) {
|
if (WuhuConfig.get('companyBWCollapse')) {
|
||||||
CommonUtils.elementReady('#effectiveness-wrap').then(BWTable_node => {
|
CommonUtils.elementReady('#effectiveness-wrap').then(BWTable_node => {
|
||||||
document.body.classList.add('wh-bwtable-ctrl');
|
document.body.classList.add('wh-bwtable-ctrl');
|
||||||
CommonUtils.addStyle(`.wh-bwtable-ctrl #effectiveness-wrap {display:none !important;}`);
|
CommonUtils.addStyle(`.wh-bwtable-ctrl #effectiveness-wrap {display:none !important;}`);
|
||||||
@ -53,9 +48,9 @@ export default function depoHelper() {
|
|||||||
actionButtonUtils.add('一键存钱', factionDeposit);
|
actionButtonUtils.add('一键存钱', factionDeposit);
|
||||||
}
|
}
|
||||||
// 存钱框浮动
|
// 存钱框浮动
|
||||||
if (localConfigWrapper.config.floatDepo && channel) {
|
if (WuhuConfig.get('floatDepo') && channel) {
|
||||||
document.body.classList.add('wh-depo-helper');
|
document.body.classList.add('wh-depo-helper');
|
||||||
commonUtils.styleInject(DEPO_CSS);
|
CommonUtils.addStyle(DEPO_CSS);
|
||||||
CommonUtils.elementReady(selector[channel]).then(node => {
|
CommonUtils.elementReady(selector[channel]).then(node => {
|
||||||
const close_btn = document.createElement('button');
|
const close_btn = document.createElement('button');
|
||||||
close_btn.addEventListener('click', () => {
|
close_btn.addEventListener('click', () => {
|
||||||
@ -81,28 +76,24 @@ export default function depoHelper() {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.info('已添加GT助手');
|
Log.info('已添加GT助手');
|
||||||
// 获取交易id
|
// 获取交易id
|
||||||
let query_params = location.hash.slice(1);
|
let query_params = location.hash.slice(1);
|
||||||
let traceId = id;
|
let traceId = id;
|
||||||
if (!traceId) query_params.split('&').forEach(param =>
|
if (!traceId) query_params.split('&').forEach(param =>
|
||||||
(param.startsWith('ID=')) && (traceId = param.slice(3))
|
(param.startsWith('ID=')) && (traceId = param.slice(3))
|
||||||
);
|
);
|
||||||
logger.info('交易id为', traceId);
|
Log.info('交易id为', traceId);
|
||||||
|
|
||||||
// 获取全部的钱数
|
// 获取全部的钱数
|
||||||
let getTraceMoney = async () => {
|
let getTraceMoney = async () => {
|
||||||
if (typeof addRFC === 'function') {
|
if (typeof addRFC === 'function') {
|
||||||
let url = addRFC('/trade.php?step=getFullMoney&ID=' + traceId);
|
let url = addRFC('/trade.php?step=getFullMoney&ID=' + traceId);
|
||||||
return (await fetchUtils.ajaxFetch({
|
return (await CommonUtils.ajaxFetch({ url: url, method: 'GET', referrer: 'trade.php' })).text();
|
||||||
url: url,
|
|
||||||
method: 'GET',
|
|
||||||
referrer: 'trade.php'
|
|
||||||
})).text();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 监听jquery ajax请求
|
// 监听jquery ajax请求
|
||||||
if (logger.debug()) $(document).ajaxComplete((_, xhr, settings) => logger.info({ xhr, settings }));
|
if (Log.debug()) $(document).ajaxComplete((_, xhr, settings) => Log.info({ xhr, settings }));
|
||||||
// react 加载完成后将节点加入视图中
|
// react 加载完成后将节点加入视图中
|
||||||
CommonUtils.elementReady('#trade-container').then(() =>
|
CommonUtils.elementReady('#trade-container').then(() =>
|
||||||
document.querySelector('#trade-container').before(_node.getBase())
|
document.querySelector('#trade-container').before(_node.getBase())
|
||||||
@ -157,7 +148,7 @@ export default function depoHelper() {
|
|||||||
new Alert('无法定额取钱,原因:数不对');
|
new Alert('无法定额取钱,原因:数不对');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fetchUtils.ajaxFetch({
|
await CommonUtils.ajaxFetch({
|
||||||
url: addRFC('/trade.php'),
|
url: addRFC('/trade.php'),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
referrer: 'trade.php',
|
referrer: 'trade.php',
|
||||||
@ -169,7 +160,7 @@ export default function depoHelper() {
|
|||||||
buttonDepositAll.addEventListener('click', async () => {
|
buttonDepositAll.addEventListener('click', async () => {
|
||||||
let money = await getTraceMoney();
|
let money = await getTraceMoney();
|
||||||
if (money === '0') return;
|
if (money === '0') return;
|
||||||
await fetchUtils.ajaxFetch({
|
await CommonUtils.ajaxFetch({
|
||||||
url: addRFC('/trade.php'),
|
url: addRFC('/trade.php'),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
referrer: 'trade.php',
|
referrer: 'trade.php',
|
||||||
@ -179,7 +170,7 @@ export default function depoHelper() {
|
|||||||
});
|
});
|
||||||
// 全取
|
// 全取
|
||||||
buttonWithdrawAll.addEventListener('click', async () => {
|
buttonWithdrawAll.addEventListener('click', async () => {
|
||||||
await fetchUtils.ajaxFetch({
|
await CommonUtils.ajaxFetch({
|
||||||
url: addRFC('/trade.php'),
|
url: addRFC('/trade.php'),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
referrer: 'trade.php',
|
referrer: 'trade.php',
|
||||||
@ -198,20 +189,20 @@ export default function depoHelper() {
|
|||||||
} else {
|
} else {
|
||||||
if (node_link) node_link.remove();
|
if (node_link) node_link.remove();
|
||||||
node_link = null;
|
node_link = null;
|
||||||
logger.info('已移除GT助手');
|
Log.info('已移除GT助手');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 任何位置公司一键存钱
|
// 任何位置公司一键存钱
|
||||||
if (localConfigWrapper.config.companyDepositAnywhere) {
|
if (WuhuConfig.get('companyDepositAnywhere')) {
|
||||||
actionButtonUtils.add('公司存钱', () => companyDepositAnywhere());
|
actionButtonUtils.add('公司存钱', companyDepositAnywhere);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 公司一键存钱
|
// 公司一键存钱
|
||||||
async function companyDeposit() {
|
async function companyDeposit() {
|
||||||
// let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||||
if (!location.href.contains('option=funds')) {
|
if (!location.href.contains('option=funds')) {
|
||||||
new Alert('请先打开公司金库');
|
new Alert('请先打开公司金库');
|
||||||
return;
|
return;
|
||||||
@ -233,7 +224,7 @@ async function companyDeposit() {
|
|||||||
|
|
||||||
// 帮派一键存钱
|
// 帮派一键存钱
|
||||||
async function factionDeposit() {
|
async function factionDeposit() {
|
||||||
// let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||||
let form = document.querySelector('#armoury-donate form');
|
let form = document.querySelector('#armoury-donate form');
|
||||||
if (!location.hash.includes('tab=armoury') || !form) {
|
if (!location.hash.includes('tab=armoury') || !form) {
|
||||||
new Alert('请先打开金库');
|
new Alert('请先打开金库');
|
||||||
@ -263,7 +254,7 @@ async function factionDeposit() {
|
|||||||
|
|
||||||
// 所有页面公司一键存钱
|
// 所有页面公司一键存钱
|
||||||
async function companyDepositAnywhere() {
|
async function companyDepositAnywhere() {
|
||||||
const logger: Logger = Container.factory(Logger);
|
let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||||
let { addRFC } = window;
|
let { addRFC } = window;
|
||||||
if (typeof addRFC !== 'function') return;
|
if (typeof addRFC !== 'function') return;
|
||||||
let url = addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction');
|
let url = addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction');
|
||||||
@ -275,7 +266,7 @@ async function companyDepositAnywhere() {
|
|||||||
body: 'deposit=' + money,
|
body: 'deposit=' + money,
|
||||||
headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded' }
|
headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})).text();
|
})).text();
|
||||||
logger.info(res);
|
Log.info(res);
|
||||||
let node = document.createElement('div');
|
let node = document.createElement('div');
|
||||||
node.innerHTML = res;
|
node.innerHTML = res;
|
||||||
let success = node.querySelector('.success-message');
|
let success = node.querySelector('.success-message');
|
||||||
@ -1,11 +1,8 @@
|
|||||||
|
import WuhuConfig from "../../class/WuhuConfig";
|
||||||
import Popup from "../../class/utils/Popup";
|
import Popup from "../../class/utils/Popup";
|
||||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
|
|
||||||
// 落地转跳设置
|
// 落地转跳设置
|
||||||
export default function landedRedirect() {
|
export default function landedRedirect() {
|
||||||
let localConfigWrapper: LocalConfigWrapper = Container.factory(LocalConfigWrapper);
|
|
||||||
|
|
||||||
let p = document.createElement('p');
|
let p = document.createElement('p');
|
||||||
let input = document.createElement('input');
|
let input = document.createElement('input');
|
||||||
let buttonSave = document.createElement('button');
|
let buttonSave = document.createElement('button');
|
||||||
@ -16,7 +13,7 @@ export default function landedRedirect() {
|
|||||||
|
|
||||||
p.innerHTML = '飞机落地后转跳的页面,关闭功能请置空:';
|
p.innerHTML = '飞机落地后转跳的页面,关闭功能请置空:';
|
||||||
input.placeholder = 'URL';
|
input.placeholder = 'URL';
|
||||||
input.value = localConfigWrapper.config.landedRedirect ?? '';
|
input.value = WuhuConfig.get('landedRedirect') || '';
|
||||||
input.style.display = 'block';
|
input.style.display = 'block';
|
||||||
input.style.textAlign = 'left';
|
input.style.textAlign = 'left';
|
||||||
input.style.width = '100%';
|
input.style.width = '100%';
|
||||||
@ -27,7 +24,7 @@ export default function landedRedirect() {
|
|||||||
buttonFct.innerHTML = '填入帮派金库金库';
|
buttonFct.innerHTML = '填入帮派金库金库';
|
||||||
buttonTest.innerHTML = '测试链接';
|
buttonTest.innerHTML = '测试链接';
|
||||||
|
|
||||||
buttonSave.addEventListener('click', () => localConfigWrapper.config.landedRedirect = input.value);
|
buttonSave.addEventListener('click', () => WuhuConfig.set('landedRedirect', input.value, true));
|
||||||
buttonCmp.addEventListener('click', () => input.value = 'https://www.torn.com/companies.php#/option=funds');
|
buttonCmp.addEventListener('click', () => input.value = 'https://www.torn.com/companies.php#/option=funds');
|
||||||
buttonFct.addEventListener('click', () => input.value = 'https://www.torn.com/factions.php?step=your#/tab=armoury');
|
buttonFct.addEventListener('click', () => input.value = 'https://www.torn.com/factions.php?step=your#/tab=armoury');
|
||||||
buttonTest.addEventListener('click', () => window.open(input.value));
|
buttonTest.addEventListener('click', () => window.open(input.value));
|
||||||
119
src/func/module/loadGS.ts
Normal file
119
src/func/module/loadGS.ts
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
import UserScriptEngine from "../../enum/UserScriptEngine";
|
||||||
|
import addStyle from "../utils/@deprecated/addStyle";
|
||||||
|
import log from "../utils/@deprecated/log";
|
||||||
|
import CommonUtils from "../../class/utils/CommonUtils";
|
||||||
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
|
// gs loader
|
||||||
|
export default function loadGS(use) {
|
||||||
|
if (use === UserScriptEngine.PDA) {
|
||||||
|
let ifr: HTMLIFrameElement = document.querySelector('#wh-gs-loader-ifr');
|
||||||
|
if (ifr) {
|
||||||
|
new Alert('飞贼小助手已经加载了');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const container = document.createElement('div');
|
||||||
|
container.id = 'wh-gs-loader';
|
||||||
|
ifr = document.createElement('iframe');
|
||||||
|
ifr.id = 'wh-gs-loader-ifr';
|
||||||
|
ifr.src = 'https://www.torn.com/crimes.php';
|
||||||
|
container.append(ifr);
|
||||||
|
document.body.append(container);
|
||||||
|
addStyle(`
|
||||||
|
#wh-gs-loader {
|
||||||
|
position:fixed;
|
||||||
|
top:0;
|
||||||
|
left:0;
|
||||||
|
z-index:100001;
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
let notify = new Alert('加载中');
|
||||||
|
ifr.onload = () => {
|
||||||
|
notify.close();
|
||||||
|
const _window = ifr.contentWindow;
|
||||||
|
const _docu = _window.document;
|
||||||
|
_docu.head.innerHTML = '';
|
||||||
|
_docu.body.innerHTML = '';
|
||||||
|
notify = new Alert('加载依赖');
|
||||||
|
CommonUtils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
|
||||||
|
.then(vuejs => {
|
||||||
|
notify.close();
|
||||||
|
_window.eval(vuejs);
|
||||||
|
_window.GM_getValue = (k, v = undefined) => {
|
||||||
|
const objV = JSON.parse(_window.localStorage.getItem('wh-gs-storage') || '{}')[k];
|
||||||
|
return objV || v;
|
||||||
|
};
|
||||||
|
_window.GM_setValue = (k, v) => {
|
||||||
|
const obj = JSON.parse(_window.localStorage.getItem('wh-gs-storage') || '{}');
|
||||||
|
obj[k] = v;
|
||||||
|
_window.localStorage.setItem('wh-gs-storage', JSON.stringify(obj));
|
||||||
|
};
|
||||||
|
_window.GM_xmlhttpRequest = function (opt) {
|
||||||
|
// 暂不适配pda post
|
||||||
|
if (opt.method.toLowerCase() === 'post') return;
|
||||||
|
CommonUtils.COFetch(opt.url).then(res => {
|
||||||
|
const obj = {
|
||||||
|
responseText: res
|
||||||
|
};
|
||||||
|
opt.onload(obj);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
notify = new Alert('加载飞贼小助手');
|
||||||
|
CommonUtils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
|
||||||
|
.then(res => {
|
||||||
|
_window.eval(res.replace('http://222.160.142.50:8154/mugger', `https://api.ljs-lyt.com/mugger`));
|
||||||
|
_window.GM_setValue("gsp_x", 10);
|
||||||
|
_window.GM_setValue("gsp_y", 10);
|
||||||
|
notify.close();
|
||||||
|
notify = new Alert('飞贼小助手已加载', { timeout: 1 });
|
||||||
|
const gsp: HTMLElement = _docu.querySelector('#gsp');
|
||||||
|
const thisRun = () => {
|
||||||
|
ifr.style.height = `${ gsp.offsetHeight + 10 }px`;
|
||||||
|
ifr.style.width = `${ gsp.offsetWidth + 20 }px`;
|
||||||
|
gsp.style.top = '10px';
|
||||||
|
gsp.style.left = '10px';
|
||||||
|
};
|
||||||
|
new MutationObserver(thisRun).observe(gsp, { childList: true, subtree: true });
|
||||||
|
thisRun();
|
||||||
|
if (log.debug()) _window.GM_setValue("gsp_showContent", true)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (use === UserScriptEngine.GM) {
|
||||||
|
if (typeof window.Vue !== 'function') {
|
||||||
|
let notify = new Alert('正在加载依赖');
|
||||||
|
CommonUtils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
|
||||||
|
.then(VueJS => {
|
||||||
|
window.eval(VueJS);
|
||||||
|
notify.close();
|
||||||
|
notify = new Alert('已载入依赖');
|
||||||
|
window.GM_getValue = (k, v = undefined) => {
|
||||||
|
const objV = JSON.parse(window.localStorage.getItem('wh-gs-storage') || '{}')[k];
|
||||||
|
return objV || v;
|
||||||
|
};
|
||||||
|
window.GM_setValue = (k, v) => {
|
||||||
|
const obj = JSON.parse(window.localStorage.getItem('wh-gs-storage') || '{}');
|
||||||
|
obj[k] = v;
|
||||||
|
window.localStorage.setItem('wh-gs-storage', JSON.stringify(obj));
|
||||||
|
};
|
||||||
|
// TODO
|
||||||
|
// window.GM_xmlhttpRequest = GM_xmlhttpRequest;
|
||||||
|
CommonUtils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
|
||||||
|
.then(GSJS => {
|
||||||
|
window.eval(GSJS);
|
||||||
|
if (log.debug()) window.GM_setValue("gsp_showContent", true);
|
||||||
|
notify.close();
|
||||||
|
notify = new Alert('已载入飞贼助手');
|
||||||
|
})
|
||||||
|
.catch(err => new Alert(`PDA API错误。${ JSON.stringify(err) }`));
|
||||||
|
})
|
||||||
|
.catch(err => new Alert(JSON.stringify(err)));
|
||||||
|
} else {
|
||||||
|
new Alert('飞贼助手已经加载了');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new Alert('暂不支持');
|
||||||
|
}
|
||||||
@ -1,16 +1,13 @@
|
|||||||
import toThousands from "../utils/toThousands";
|
import toThousands from "../utils/toThousands";
|
||||||
import Log from "../../class/Log";
|
import Log from "../../class/Log";
|
||||||
import Alert from "../../class/utils/Alert";
|
import Alert from "../../class/utils/Alert";
|
||||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
import WuhuConfig from "../../class/WuhuConfig";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
|
|
||||||
// 价格监视handle
|
// 价格监视handle
|
||||||
export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) {
|
export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) {
|
||||||
let localConfigWrapper: LocalConfigWrapper = Container.factory(LocalConfigWrapper);
|
|
||||||
|
|
||||||
let priceTemp = {};
|
let priceTemp = {};
|
||||||
let intervalId = window.setInterval(() => {
|
let intervalId = window.setInterval(() => {
|
||||||
const price_conf = localConfigWrapper.config.priceWatcher;
|
const price_conf = WuhuConfig.get('priceWatcher');
|
||||||
const apikey = isPDA ? PDA_APIKey : localStorage.getItem('APIKey');
|
const apikey = isPDA ? PDA_APIKey : localStorage.getItem('APIKey');
|
||||||
if (!apikey || (price_conf['pt'] === -1 && price_conf['xan'] === -1)) {
|
if (!apikey || (price_conf['pt'] === -1 && price_conf['xan'] === -1)) {
|
||||||
Log.warn('价格监视关闭,无apikey或设置未打开');
|
Log.warn('价格监视关闭,无apikey或设置未打开');
|
||||||
@ -1,14 +1,10 @@
|
|||||||
import Alert from "../../class/utils/Alert";
|
import Alert from "../../class/utils/Alert";
|
||||||
import InfoUtils from "../../class/utils/InfoUtils";
|
import InfoUtils from "../../class/utils/InfoUtils";
|
||||||
|
import Log from "../../class/Log";
|
||||||
import Popup from "../../class/utils/Popup";
|
import Popup from "../../class/utils/Popup";
|
||||||
import { Container } from "../../container/Container";
|
|
||||||
import Logger from "../../class/Logger";
|
|
||||||
|
|
||||||
// 守望者
|
// 守望者
|
||||||
export default function safeKeeper() {
|
export default function safeKeeper() {
|
||||||
let infoUtils = Container.factory(InfoUtils);
|
|
||||||
let logger = Container.factory(Logger);
|
|
||||||
|
|
||||||
let url = `https://www.torn.com/loader.php?sid=attackData&mode=json&step=poll&user2ID=`;
|
let url = `https://www.torn.com/loader.php?sid=attackData&mode=json&step=poll&user2ID=`;
|
||||||
let popup = new Popup('<p>监测目标ID玩家的防御状态,找出隐身攻击者</p>', '守望者 (测试中)');
|
let popup = new Popup('<p>监测目标ID玩家的防御状态,找出隐身攻击者</p>', '守望者 (测试中)');
|
||||||
let p = document.createElement('p');
|
let p = document.createElement('p');
|
||||||
@ -52,13 +48,13 @@ export default function safeKeeper() {
|
|||||||
} else new Alert('守望者运行中,请先停止', { timeout: 2 });
|
} else new Alert('守望者运行中,请先停止', { timeout: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
popup.element.appendChild(p);
|
popup.getElement().appendChild(p);
|
||||||
popup.element.appendChild(uid);
|
popup.getElement().appendChild(uid);
|
||||||
popup.element.appendChild(start);
|
popup.getElement().appendChild(start);
|
||||||
popup.element.appendChild(stop);
|
popup.getElement().appendChild(stop);
|
||||||
popup.element.appendChild(self_target);
|
popup.getElement().appendChild(self_target);
|
||||||
popup.element.appendChild(attackers);
|
popup.getElement().appendChild(attackers);
|
||||||
popup.element.appendChild(records);
|
popup.getElement().appendChild(records);
|
||||||
|
|
||||||
start.addEventListener('click', () => {
|
start.addEventListener('click', () => {
|
||||||
if (loop_id !== null || !uid.value) return;
|
if (loop_id !== null || !uid.value) return;
|
||||||
@ -76,7 +72,7 @@ export default function safeKeeper() {
|
|||||||
})).text();
|
})).text();
|
||||||
if (loop_id !== that_id) return;
|
if (loop_id !== that_id) return;
|
||||||
let data = JSON.parse(res.split('<div')[0]);
|
let data = JSON.parse(res.split('<div')[0]);
|
||||||
logger.info(count++, data);
|
Log.info(count++, data);
|
||||||
let { DB, currentFightStatistics, histLog } = data;
|
let { DB, currentFightStatistics, histLog } = data;
|
||||||
// 攻击人
|
// 攻击人
|
||||||
// 格式:currentFightStatistics = {uid: {...}, uid2: {...}}
|
// 格式:currentFightStatistics = {uid: {...}, uid2: {...}}
|
||||||
@ -122,5 +118,5 @@ export default function safeKeeper() {
|
|||||||
loop_id = null;
|
loop_id = null;
|
||||||
p.innerHTML = '状态:已关 ❎';
|
p.innerHTML = '状态:已关 ❎';
|
||||||
});
|
});
|
||||||
self_target.addEventListener('click', () => uid.value = (infoUtils.getPlayerInfo()['userID']) + '');
|
self_target.addEventListener('click', () => uid.value = (InfoUtils.getInstance().getPlayerInfo()['userID']) + '');
|
||||||
}
|
}
|
||||||
318
src/func/module/travelHelper.ts
Normal file
318
src/func/module/travelHelper.ts
Normal file
@ -0,0 +1,318 @@
|
|||||||
|
import titleTrans from "../translate/titleTrans";
|
||||||
|
import contentTitleLinksTrans from "../translate/contentTitleLinksTrans";
|
||||||
|
import Device from "../../enum/Device";
|
||||||
|
import WuhuBase from "../../class/WuhuBase";
|
||||||
|
import Alert from "../../class/utils/Alert";
|
||||||
|
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
|
||||||
|
import WuhuConfig from "../../class/WuhuConfig";
|
||||||
|
import CommonUtils from "../../class/utils/CommonUtils";
|
||||||
|
import TRAVEL_ALARM_CSS from "../../static/css/travel_alarm.css";
|
||||||
|
import TRAVEL_ALARM_HTML from "../../static/html/travel_alarm.html";
|
||||||
|
import TornStyleBlock from "../../class/utils/TornStyleBlock";
|
||||||
|
import QuickFlyBtnHandler from "../../class/handler/QuickFlyBtnHandler";
|
||||||
|
|
||||||
|
export default async function travelHelper(): Promise<null> {
|
||||||
|
let { href, bodyAttrs, device } = WuhuBase.glob;
|
||||||
|
|
||||||
|
// URL判断 + 人不在城内
|
||||||
|
if (href.includes('index.php') && bodyAttrs['data-abroad'] === 'true') {
|
||||||
|
// 飞行中
|
||||||
|
if (bodyAttrs["data-traveling"] === 'true') {
|
||||||
|
// 飞行闹钟
|
||||||
|
if (device === Device.PC && WuhuConfig.get('trvAlarm')) {
|
||||||
|
// 获取目的地
|
||||||
|
let dest_cn;
|
||||||
|
let country = document.body.getAttribute('data-country');
|
||||||
|
if (country === 'torn') {
|
||||||
|
dest_cn = '回城';
|
||||||
|
} else {
|
||||||
|
dest_cn = {
|
||||||
|
'uk': "英国", 'switzerland': "瑞士", 'mexico': '墨西哥', 'canada': '加拿大', 'cayman': '开曼',
|
||||||
|
'hawaii': '夏威夷', 'argentina': '阿根廷',
|
||||||
|
'japan': '日本', 'china': '中国', 'uae': 'UAE', 'south-africa': '南非',
|
||||||
|
}[country] || country;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 剩余时间
|
||||||
|
const remaining_arr = document.querySelector('#countrTravel').getAttribute('data-to');
|
||||||
|
|
||||||
|
const wh_trv_alarm = localStorage.getItem('wh_trv_alarm')
|
||||||
|
? JSON.parse(localStorage.getItem('wh_trv_alarm'))
|
||||||
|
: { 'enable': true, 'alert_time': 30, 'node_pos': [240, 240] };
|
||||||
|
const save_trv_settings = () => localStorage.setItem('wh_trv_alarm', JSON.stringify(wh_trv_alarm));
|
||||||
|
|
||||||
|
const wh_trv_alarm_node = document.createElement('div');
|
||||||
|
wh_trv_alarm_node.id = 'wh-trv-alarm';
|
||||||
|
wh_trv_alarm_node.style.left = `${ wh_trv_alarm.node_pos[0] }px`;
|
||||||
|
wh_trv_alarm_node.style.top = `${ wh_trv_alarm.node_pos[1] }px`;
|
||||||
|
wh_trv_alarm_node.innerHTML = TRAVEL_ALARM_HTML
|
||||||
|
.replace('{{}}', dest_cn === '回城' ? dest_cn : '飞往' + dest_cn)
|
||||||
|
.replace('{{}}', wh_trv_alarm.enable ? 'checked ' : '')
|
||||||
|
.replace('{{}}', wh_trv_alarm.alert_time || 30);
|
||||||
|
CommonUtils.addStyle(TRAVEL_ALARM_CSS);
|
||||||
|
document.body.append(wh_trv_alarm_node);
|
||||||
|
// 报错dom
|
||||||
|
const error_node = wh_trv_alarm_node.querySelector('#wh-trv-error') as HTMLElement;
|
||||||
|
// jquery拖动
|
||||||
|
// @ts-ignore
|
||||||
|
$(wh_trv_alarm_node).draggable({
|
||||||
|
containment: "body",
|
||||||
|
distance: 5,
|
||||||
|
handle: "#wh-trv-alarm-title",
|
||||||
|
stop: () => {
|
||||||
|
wh_trv_alarm.node_pos = [parseInt(wh_trv_alarm_node.style.left), parseInt(wh_trv_alarm_node.style.top)];
|
||||||
|
save_trv_settings();
|
||||||
|
},
|
||||||
|
scroll: false,
|
||||||
|
});
|
||||||
|
// 剩余时间dom
|
||||||
|
const remaining_node = wh_trv_alarm_node.querySelector('#wh-trv-alarm-remaining');
|
||||||
|
// 设定闹钟响的按钮
|
||||||
|
const set_node = wh_trv_alarm_node.querySelectorAll('#wh-trv-alarm-cont button')[0] as HTMLButtonElement;
|
||||||
|
// 落地前响铃时长
|
||||||
|
const cd_time = wh_trv_alarm_node.querySelector('input[type="number"]') as HTMLInputElement;
|
||||||
|
let count_down_notify: MyHTMLElement | { close: Function } = {
|
||||||
|
close: () => {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
set_node.onclick = () => {
|
||||||
|
try {
|
||||||
|
wh_trv_alarm.alert_time = parseInt(cd_time.value);
|
||||||
|
} catch {
|
||||||
|
wh_trv_alarm.alert_time = 30;
|
||||||
|
}
|
||||||
|
save_trv_settings();
|
||||||
|
set_node.value = wh_trv_alarm.alert_time;
|
||||||
|
count_down_notify.close();
|
||||||
|
count_down_notify = new Alert('设置已更新');
|
||||||
|
};
|
||||||
|
// 停止响铃按钮
|
||||||
|
const stop_node = wh_trv_alarm_node.querySelectorAll('#wh-trv-alarm-cont button')[1] as HTMLButtonElement;
|
||||||
|
stop_node.onclick = () => {
|
||||||
|
user_stop_alert = true;
|
||||||
|
stop_node.innerText = '本次已关闭';
|
||||||
|
stop_node.disabled = true;
|
||||||
|
}
|
||||||
|
// 开启闹钟勾选
|
||||||
|
const enable_node = wh_trv_alarm_node.querySelector('#wh-trv-alarm-cont input[type="checkbox"]') as HTMLInputElement;
|
||||||
|
let on_off_notify: MyHTMLElement | { close: Function } = {
|
||||||
|
close: () => {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
enable_node.onchange = ev => {
|
||||||
|
wh_trv_alarm.enable = (<HTMLInputElement>ev.target).checked;
|
||||||
|
save_trv_settings();
|
||||||
|
on_off_notify.close();
|
||||||
|
on_off_notify = new Alert(wh_trv_alarm.enable ? '闹钟已开启' : '闹钟已关闭');
|
||||||
|
};
|
||||||
|
// 剩余时间 秒
|
||||||
|
const remaining_sec = parseInt(remaining_arr);
|
||||||
|
// 落地时timestamp
|
||||||
|
const land_timestamp = Date.now() + remaining_sec * 1000;
|
||||||
|
// 音频dom
|
||||||
|
const audio = document.createElement('audio');
|
||||||
|
audio.src = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3';
|
||||||
|
audio.play()
|
||||||
|
.then(() => audio.pause())
|
||||||
|
.catch(() => {
|
||||||
|
error_node.style.display = 'table';
|
||||||
|
const func = () => {
|
||||||
|
error_node.remove();
|
||||||
|
document.body.removeEventListener('click', func);
|
||||||
|
};
|
||||||
|
document.body.addEventListener('click', func);
|
||||||
|
});
|
||||||
|
// 是否正在响铃
|
||||||
|
let audio_play_flag = false;
|
||||||
|
// 用户是否停止当前响铃
|
||||||
|
let user_stop_alert = false;
|
||||||
|
// 响铃循环id
|
||||||
|
let audio_play_id = null;
|
||||||
|
// 响铃的方法
|
||||||
|
let audio_play_handle = () => {
|
||||||
|
if (user_stop_alert) {
|
||||||
|
clearInterval(audio_play_id);
|
||||||
|
audio_play_id = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!audio_play_flag || !wh_trv_alarm.enable) return;
|
||||||
|
audio.play().then();
|
||||||
|
};
|
||||||
|
// 飞机小动画字符
|
||||||
|
const flying_arr = [
|
||||||
|
'✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
' ✈ ',
|
||||||
|
];
|
||||||
|
// 飞行的状态dom
|
||||||
|
const flying_status = wh_trv_alarm_node.querySelector('#wh-trv-status');
|
||||||
|
// 飞机的小动画dom
|
||||||
|
const flying_ani = flying_status.nextElementSibling;
|
||||||
|
// 飞机的计数
|
||||||
|
let flying_index = 0;
|
||||||
|
const id = window.setInterval(() => {
|
||||||
|
const remaining_time = (land_timestamp - Date.now()) / 1000 | 0;
|
||||||
|
remaining_node.innerText = `${ remaining_time / 3600 | 0 }时${ remaining_time % 3600 / 60 | 0 }分${ remaining_time % 60 }秒`;
|
||||||
|
|
||||||
|
if (remaining_time < wh_trv_alarm.alert_time) {
|
||||||
|
// flying_status.innerHTML = `即将落地...`;
|
||||||
|
if (wh_trv_alarm.enable) {
|
||||||
|
// 播放提示音
|
||||||
|
audio_play_flag = true;
|
||||||
|
if (audio_play_id === null && !user_stop_alert) audio_play_id = window.setInterval(audio_play_handle, 750);
|
||||||
|
stop_node.parentElement.classList.remove('wh-trv-alarm-stop-hide');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// flying_status.innerHTML = `飞行中...`;
|
||||||
|
if (wh_trv_alarm.enable) {
|
||||||
|
clearInterval(audio_play_id);
|
||||||
|
audio_play_id = null;
|
||||||
|
stop_node.parentElement.classList.add('wh-trv-alarm-stop-hide');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flying_ani.innerHTML = `${ flying_arr[flying_index] }`;
|
||||||
|
flying_index = (flying_index + 1) % flying_arr.length;
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 落地转跳 落地前事件
|
||||||
|
if (WuhuConfig.get('landedRedirect') && document.querySelector('#tcLogo[title]') === null) {
|
||||||
|
window.addEventListener('beforeunload', () => {
|
||||||
|
let obj = { url: WuhuConfig.get('landedRedirect'), timestamp: Date.now() };
|
||||||
|
sessionStorage['wh-landed-redirect'] = JSON.stringify(obj);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 不在飞行中 海外落地页面
|
||||||
|
else {
|
||||||
|
// 一键回城
|
||||||
|
ActionButtonUtils.getInstance().add('直接回城', travelBack);
|
||||||
|
// 海外警告
|
||||||
|
if (WuhuConfig.get('abroadWarning')) {
|
||||||
|
let c = 1;
|
||||||
|
setInterval(() => new Alert(`警告:您已海外落地${ c++ * 30 }秒`, {
|
||||||
|
timeout: 30,
|
||||||
|
sysNotify: true
|
||||||
|
}), 30000);
|
||||||
|
}
|
||||||
|
// 解毒提醒
|
||||||
|
if (bodyAttrs['data-country'] === 'switzerland') {
|
||||||
|
let block = new TornStyleBlock('解毒提醒');
|
||||||
|
block.setContent('<p><a href="/index.php?page=rehab">❤️ 点击前往解毒</a></p>');
|
||||||
|
document.querySelector('h4#skip-to-content').before(block.getBase());
|
||||||
|
// let page_title = document.querySelector('h4#skip-to-content');
|
||||||
|
// let msg = document.createElement('div');
|
||||||
|
// msg.innerHTML = `<div class="info-msg border-round">
|
||||||
|
// <i class="info-icon"></i>
|
||||||
|
// <div class="delimiter">
|
||||||
|
// <div class="msg right-round" tabindex="0" role="alert">
|
||||||
|
// <p><a href="/index.php?page=rehab">❤️ 点击前往解毒</a></p>
|
||||||
|
// </div>
|
||||||
|
// </div>
|
||||||
|
// </div>`;
|
||||||
|
// msg.classList.add('info-msg-cont', 'green', 'border-round', 'm-bottom10');
|
||||||
|
// page_title.before(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// URL判断 + 人在城内
|
||||||
|
else if (href.includes('index.php') && bodyAttrs['data-abroad'] === 'false') {
|
||||||
|
// 落地转跳
|
||||||
|
if (sessionStorage['wh-landed-redirect']) {
|
||||||
|
let { url, timestamp } = JSON.parse(sessionStorage['wh-landed-redirect']);
|
||||||
|
if (Date.now() - timestamp < 30000) {
|
||||||
|
sessionStorage.removeItem('wh-landed-redirect');
|
||||||
|
location.href = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 起飞页面
|
||||||
|
if (href.contains(/travelagency\.php/)) {
|
||||||
|
// 起飞提醒
|
||||||
|
if (WuhuConfig.get('energyAlert')) {
|
||||||
|
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 trans = () => {
|
||||||
|
// 当前能量e
|
||||||
|
const energyBarStr = $('#barEnergy p[class^="bar-value__"]').text().trim();
|
||||||
|
const [curE, maxE] = energyBarStr.split('/').length === 2
|
||||||
|
? [parseInt(energyBarStr.split('/')[0]), parseInt(energyBarStr.split('/')[1])]
|
||||||
|
: [NaN, NaN];
|
||||||
|
const incTime = maxE === 150 ? 10 : 15;
|
||||||
|
const fullEnergyTime = !(isNaN(curE) || isNaN(maxE)) ? (maxE - 5 - curE) / 5 * incTime
|
||||||
|
+ (incTime - new Date().getMinutes() % incTime) : NaN;
|
||||||
|
// 起飞前提示
|
||||||
|
$('.travel-confirm .travel-question .q-wrap span:nth-of-type(2)').each((i, e) => {
|
||||||
|
if (isNaN(fullEnergyTime)) return;
|
||||||
|
const spl = e.innerText.trim().split(' ');
|
||||||
|
const [hours, minutes] = spl.length === 5
|
||||||
|
? [parseInt(spl[0]), parseInt(spl[3])]
|
||||||
|
: [0, parseInt(spl[0])];
|
||||||
|
if (fullEnergyTime < (hours * 60 + minutes) * 2) {
|
||||||
|
if (!$(e).parent().hasClass('wh-translated')) {
|
||||||
|
$(e).parent()
|
||||||
|
.prepend(`<div style="color: red">警告:该次飞行往返时间大于体力回复时间,将会爆体!</div>`)
|
||||||
|
.addClass('wh-translated');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
trans();
|
||||||
|
OB.observe($$.get(0), {
|
||||||
|
characterData: true,
|
||||||
|
attributes: true,
|
||||||
|
subtree: true,
|
||||||
|
childList: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 一键起飞
|
||||||
|
if (sessionStorage['wh-quick-fly']) {
|
||||||
|
QuickFlyBtnHandler.doQuickFly();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function travelBack(): Promise<null> {
|
||||||
|
if (typeof window['getAction'] !== 'function') return;
|
||||||
|
let backHomeAction = function (): Promise<string> {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
window.getAction({
|
||||||
|
type: "post",
|
||||||
|
action: 'travelagency.php',
|
||||||
|
data: {
|
||||||
|
step: 'backHomeAction'
|
||||||
|
},
|
||||||
|
success: function (msg) {
|
||||||
|
resolve(msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
let res = await backHomeAction();
|
||||||
|
new Alert(res);
|
||||||
|
if (!res.includes('error')) {
|
||||||
|
new Alert('成功,即将刷新');
|
||||||
|
window.setTimeout(() => location.reload(), 3000);
|
||||||
|
} else {
|
||||||
|
new Alert('出错了');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
import { eventsDict, gymList, ocList } from "../../dictionary/translation";
|
import { eventsDict, gymList, ocList } from "../../dictionary/translation";
|
||||||
|
import log from "../utils/@deprecated/log";
|
||||||
let log = { info: (args) => null };
|
|
||||||
|
|
||||||
export default function eventsTrans(events: JQuery = $('span.mail-link')) {
|
export default function eventsTrans(events: JQuery = $('span.mail-link')) {
|
||||||
const index = window.location.href.indexOf('events.php#/step=received') >= 0 ? 1 : 0;
|
const index = window.location.href.indexOf('events.php#/step=received') >= 0 ? 1 : 0;
|
||||||
@ -554,9 +553,9 @@ export default function eventsTrans(events: JQuery = $('span.mail-link')) {
|
|||||||
const num = spl[3] === 'a' ? '1' : spl[3];
|
const num = spl[3] === 'a' ? '1' : spl[3];
|
||||||
const price = reasonSpl[0].split(' ').slice(-1)[0];
|
const price = reasonSpl[0].split(' ').slice(-1)[0];
|
||||||
const reason = reasonSpl[1] ? reasonSpl[1] : null;
|
const reason = reasonSpl[1] ? reasonSpl[1] : null;
|
||||||
const trans = `${ someone ?? '某人1' }对你进行了 ${ num } 次赏金为 ${ price } 的悬赏${ reason ? ',原因:' + reason : '' }`;
|
const trans = `${ someone ? '某人' : ' ' }对你进行了 ${ num } 次赏金为 ${ price } 的悬赏${ reason ? ',原因:' + reason : '' }`;
|
||||||
// 匿名悬赏
|
// 匿名悬赏
|
||||||
if (!!someone) {
|
if (someone) {
|
||||||
$(e).text(trans);
|
$(e).text(trans);
|
||||||
}
|
}
|
||||||
// 实名悬赏
|
// 实名悬赏
|
||||||
@ -1,4 +1,4 @@
|
|||||||
let log = { info: (args) => null };
|
import log from "../utils/@deprecated/log";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* observe 包装
|
* observe 包装
|
||||||
@ -34,16 +34,11 @@ import initOB from "./initOB";
|
|||||||
import titleTrans from "./titleTrans";
|
import titleTrans from "./titleTrans";
|
||||||
import contentTitleLinksTrans from "./contentTitleLinksTrans";
|
import contentTitleLinksTrans from "./contentTitleLinksTrans";
|
||||||
import showItemInfoTrans from "./showItemInfoTrans";
|
import showItemInfoTrans from "./showItemInfoTrans";
|
||||||
|
import log from "../utils/@deprecated/log";
|
||||||
import contentTitleLinksTransReact from "./contentTitleLinksTransReact";
|
import contentTitleLinksTransReact from "./contentTitleLinksTransReact";
|
||||||
import titleTransReact from "./titleTransReact";
|
import titleTransReact from "./titleTransReact";
|
||||||
import Log from "../../class/Log";
|
import Log from "../../class/Log";
|
||||||
|
|
||||||
let log = { info: (args) => null };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @param href
|
|
||||||
*/
|
|
||||||
export default function translateMain(href: string): void {
|
export default function translateMain(href: string): void {
|
||||||
// 时分秒转换
|
// 时分秒转换
|
||||||
String.prototype.replaceHMS = function replaceHMS() {
|
String.prototype.replaceHMS = function replaceHMS() {
|
||||||
@ -67,57 +62,57 @@ export default function translateMain(href: string): void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 边栏
|
// 边栏
|
||||||
// let sidebarTimeOut = 60;
|
let sidebarTimeOut = 60;
|
||||||
// const sidebarInterval = setInterval(() => {
|
const sidebarInterval = setInterval(() => {
|
||||||
// // 60秒后取消定时
|
// 60秒后取消定时
|
||||||
// if ($('div[class^="sidebar"]').length === 0) {
|
if ($('div[class^="sidebar"]').length === 0) {
|
||||||
// sidebarTimeOut--;
|
sidebarTimeOut--;
|
||||||
// if (sidebarTimeOut < 0) {
|
if (sidebarTimeOut < 0) {
|
||||||
// clearInterval(sidebarInterval);
|
clearInterval(sidebarInterval);
|
||||||
// }
|
}
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// // 边栏块标题
|
// 边栏块标题
|
||||||
// $('h2[class^="header"]').each((i, e) => {
|
$('h2[class^="header"]').each((i, e) => {
|
||||||
// if (!sidebarDict[e.firstChild.nodeValue]) return;
|
if (!sidebarDict[e.firstChild.nodeValue]) return;
|
||||||
// e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue];
|
e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue];
|
||||||
// });
|
});
|
||||||
// // 边栏人物名字
|
// 边栏人物名字
|
||||||
// $('span[class^="menu-name"]').each((i, e) => {
|
$('span[class^="menu-name"]').each((i, e) => {
|
||||||
// e.firstChild.nodeValue = '名字:';
|
e.firstChild.nodeValue = '名字:';
|
||||||
// });
|
});
|
||||||
// // 钱 等级 pt 天赋点
|
// 钱 等级 pt 天赋点
|
||||||
// $('p[class^="point-block"]').each((i, e) => {
|
$('p[class^="point-block"]').each((i, e) => {
|
||||||
// if (sidebarDict[e.firstChild.firstChild.nodeValue])
|
if (sidebarDict[e.firstChild.firstChild.nodeValue])
|
||||||
// e.firstChild.firstChild.nodeValue = sidebarDict[e.firstChild.firstChild.nodeValue];
|
e.firstChild.firstChild.nodeValue = sidebarDict[e.firstChild.firstChild.nodeValue];
|
||||||
// });
|
});
|
||||||
// // 4条 状态条
|
// 4条 状态条
|
||||||
// $('p[class^="bar-name"]').each((i, e) => {
|
$('p[class^="bar-name"]').each((i, e) => {
|
||||||
// if (sidebarDict[e.firstChild.nodeValue])
|
if (sidebarDict[e.firstChild.nodeValue])
|
||||||
// e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue];
|
e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue];
|
||||||
// });
|
});
|
||||||
// // 边栏菜单
|
// 边栏菜单
|
||||||
// $('span[class^="linkName"]').each((i, e) => {
|
$('span[class^="linkName"]').each((i, e) => {
|
||||||
// if (sidebarDict[e.firstChild.nodeValue])
|
if (sidebarDict[e.firstChild.nodeValue])
|
||||||
// e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue];
|
e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue];
|
||||||
// });
|
});
|
||||||
// // [use]按钮
|
// [use]按钮
|
||||||
// if (document.querySelector('#pointsMerits'))
|
if (document.querySelector('#pointsMerits'))
|
||||||
// $('#pointsMerits')[0].firstChild.nodeValue = '[使用]';
|
$('#pointsMerits')[0].firstChild.nodeValue = '[使用]';
|
||||||
// if (document.querySelector('#pointsPoints'))
|
if (document.querySelector('#pointsPoints'))
|
||||||
// $('#pointsPoints')[0].firstChild.nodeValue = '[使用]';
|
$('#pointsPoints')[0].firstChild.nodeValue = '[使用]';
|
||||||
// if (document.querySelector('#pointsLevel'))
|
if (document.querySelector('#pointsLevel'))
|
||||||
// $('#pointsLevel')[0].firstChild.nodeValue = '[升级]';
|
$('#pointsLevel')[0].firstChild.nodeValue = '[升级]';
|
||||||
//
|
|
||||||
// // 手机 区域菜单
|
// 手机 区域菜单
|
||||||
// $('div[class*="areas-mobile"] span:nth-child(2)').contents().each((i, e) => {
|
$('div[class*="areas-mobile"] span:nth-child(2)').contents().each((i, e) => {
|
||||||
// //log(e);
|
//log(e);
|
||||||
// if (sidebarDict[e.nodeValue])
|
if (sidebarDict[e.nodeValue])
|
||||||
// e.nodeValue = sidebarDict[e.nodeValue];
|
e.nodeValue = sidebarDict[e.nodeValue];
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// clearInterval(sidebarInterval);
|
clearInterval(sidebarInterval);
|
||||||
// }, 1000);
|
}, 1000);
|
||||||
|
|
||||||
// header
|
// header
|
||||||
if (document.querySelector('div#header-root')) {
|
if (document.querySelector('div#header-root')) {
|
||||||
@ -1113,7 +1108,7 @@ export default function translateMain(href: string): void {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($('.wh-translated').length <= 0) {
|
if ($('.wh-translated').length <= 0) {
|
||||||
log.info(`未找到翻译: 「${ action_desc.text().trim() }」`);
|
log.info(`未找到翻译: “${ action_desc.text().trim() }”`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 添加敌人或朋友的界面
|
// 添加敌人或朋友的界面
|
||||||
98
src/func/utils/@deprecated/BuyBeer.ts
Normal file
98
src/func/utils/@deprecated/BuyBeer.ts
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import audioPlay from "./audioPlay";
|
||||||
|
import MathUtils from "../../../class/utils/MathUtils";
|
||||||
|
import Alert from "../../../class/utils/Alert";
|
||||||
|
import InfoUtils from "../../../class/utils/InfoUtils";
|
||||||
|
import WuhuConfig from "../../../class/WuhuConfig";
|
||||||
|
import Log from "../../../class/Log";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export default function BuyBeer() {
|
||||||
|
// 正在通知
|
||||||
|
let is_notified = false;
|
||||||
|
let time: number = WuhuConfig.get('_15AlarmTime') || 30;
|
||||||
|
let loop: BeerMonitorLoop = {};
|
||||||
|
// 循环id
|
||||||
|
let started = null;
|
||||||
|
loop.start = () => {
|
||||||
|
if (started) {
|
||||||
|
Log.info('啤酒助手已在运行');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
started = setInterval(async () => {
|
||||||
|
// 海外取消提醒
|
||||||
|
let { isTravelling, isAbroad } = await InfoUtils.getInstance().getUserState();
|
||||||
|
if (isTravelling || isAbroad) {
|
||||||
|
loop.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let dt = new Date();
|
||||||
|
// 已选当天不提醒
|
||||||
|
const now = [dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate()];
|
||||||
|
const ignore_date = WuhuConfig.get('_15_alarm_ignore') || '{}';
|
||||||
|
if (JSON.stringify(now) === JSON.stringify(ignore_date)) return;
|
||||||
|
// 正常提醒
|
||||||
|
let m = 14 - (dt.getMinutes() % 15);
|
||||||
|
let s = 60 - dt.getSeconds();
|
||||||
|
if (m === 0 && s < time) {
|
||||||
|
// 如从通知点开,则本次通知跳过
|
||||||
|
if (location.href.includes('#clickfromnotify')) {
|
||||||
|
is_notified = true;
|
||||||
|
location.hash = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 本次已通知
|
||||||
|
if (is_notified) return;
|
||||||
|
is_notified = true;
|
||||||
|
// 发送通知
|
||||||
|
const notify = new Alert(notify_html, {
|
||||||
|
timeout: 30,
|
||||||
|
sysNotify: true,
|
||||||
|
});
|
||||||
|
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => loop.skip_today);
|
||||||
|
notify.getElement().addEventListener('click', ev => {
|
||||||
|
if ((ev.target as HTMLElement).tagName.toLowerCase() === 'a') {
|
||||||
|
// notify.sys_notify.close();
|
||||||
|
notify.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.setTimeout(audioPlay, 800);
|
||||||
|
window.setTimeout(audioPlay, 800 * 2);
|
||||||
|
window.setTimeout(audioPlay, 800 * 3);
|
||||||
|
} else {
|
||||||
|
is_notified = false;
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
loop.stop = () => {
|
||||||
|
if (started) {
|
||||||
|
clearInterval(started);
|
||||||
|
started = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
loop.set_time = (t) => time = t;
|
||||||
|
loop.status = () => started ? '已启动' : '未启动';
|
||||||
|
loop.is_running = () => !!started;
|
||||||
|
|
||||||
|
let mathUtils: MathUtils = MathUtils.getInstance();
|
||||||
|
let notify_html = `<span style="background-color:green;color:white;border-radius:3px;font-size:14px;line-height:21px;padding:2px 4px;">啤酒小助手</span><br/>提醒您:还有不到 50 秒 NPC 的商品就要刷新了,啤酒血包要抢的可以准备咯。<button id="wh-rd-btn-${ mathUtils.getRandomInt(0, 100) }">【今日不再提醒】</button><br/><a href="/shops.php?step=bitsnbobs#clickfromnotify" target="_blank">【啤酒店】</a> <a href="/shops.php?step=pharmacy#clickfromnotify" target="_blank">【血包店】</a>`
|
||||||
|
loop.skip_today = () => {
|
||||||
|
const date = new Date();
|
||||||
|
WuhuConfig.set('_15_alarm_ignore', [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()], false);
|
||||||
|
// 通知
|
||||||
|
const notify = new Alert(`明早8点前将不再提醒 <button id="wh-rd-btn-${ mathUtils.getRandomInt(0, 100) }">取消</button>`);
|
||||||
|
// 通知中的取消按钮
|
||||||
|
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => WuhuConfig.set('_15_alarm_ignore', undefined));
|
||||||
|
};
|
||||||
|
return loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BeerMonitorLoop {
|
||||||
|
start?: Function;
|
||||||
|
stop?: Function;
|
||||||
|
set_time?: Function;
|
||||||
|
status?: Function;
|
||||||
|
is_running?: Function;
|
||||||
|
skip_today?: Function;
|
||||||
|
}
|
||||||
65
src/func/utils/@deprecated/COFetch.ts
Normal file
65
src/func/utils/@deprecated/COFetch.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import UserScriptEngine from "../../../enum/UserScriptEngine";
|
||||||
|
import getScriptEngine from "./getScriptEngine";
|
||||||
|
import Log from "../../../class/Log";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export default function COFetch(url: URL | string, method: 'get' | 'post' = 'get', body: any = null): Promise<string> {
|
||||||
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
const engine = getScriptEngine();
|
||||||
|
switch (engine) {
|
||||||
|
case UserScriptEngine.RAW: {
|
||||||
|
console.error(`[wh] 跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
||||||
|
reject(`错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UserScriptEngine.PDA: {
|
||||||
|
const { PDA_httpGet, PDA_httpPost } = window;
|
||||||
|
// get
|
||||||
|
if (method === 'get') {
|
||||||
|
if (typeof PDA_httpGet !== 'function') {
|
||||||
|
Log.error('COFetch网络错误:PDA版本不支持');
|
||||||
|
reject('COFetch网络错误:PDA版本不支持');
|
||||||
|
}
|
||||||
|
PDA_httpGet(url)
|
||||||
|
.then(res => resolve(res.responseText))
|
||||||
|
.catch(e => {
|
||||||
|
Log.error('COFetch网络错误', e);
|
||||||
|
reject(`COFetch网络错误 ${ e }`);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// post
|
||||||
|
else {
|
||||||
|
if (typeof PDA_httpPost !== 'function') {
|
||||||
|
Log.error('COFetch网络错误:PDA版本不支持');
|
||||||
|
reject('COFetch网络错误:PDA版本不支持');
|
||||||
|
}
|
||||||
|
PDA_httpPost(url, { 'content-type': 'application/json' }, body)
|
||||||
|
.then(res => resolve(res.responseText))
|
||||||
|
.catch(e => {
|
||||||
|
Log.error('COFetch网络错误', e);
|
||||||
|
reject(`COFetch网络错误 ${ e }`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UserScriptEngine.GM: {
|
||||||
|
let { GM_xmlhttpRequest } = window;
|
||||||
|
if (typeof GM_xmlhttpRequest !== 'function') {
|
||||||
|
Log.error('COFetch网络错误:用户脚本扩展API错误');
|
||||||
|
reject('错误:用户脚本扩展API错误');
|
||||||
|
}
|
||||||
|
GM_xmlhttpRequest({
|
||||||
|
method: method,
|
||||||
|
url: url,
|
||||||
|
data: method === 'get' ? null : body,
|
||||||
|
headers: method === 'get' ? null : { 'content-type': 'application/json' },
|
||||||
|
onload: res => resolve(res.response),
|
||||||
|
onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`),
|
||||||
|
ontimeout: res => reject(`连接超时 ${ JSON.stringify(res) }`),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
56
src/func/utils/@deprecated/MarkdownParser.ts
Normal file
56
src/func/utils/@deprecated/MarkdownParser.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* 解析 Markdown 内容
|
||||||
|
* @param {String} from
|
||||||
|
* @param {Number} max_line 最大行数,默认500
|
||||||
|
* @returns {HTMLDivElement}
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export default function mdParse(from: string, max_line?: number): HTMLElement {
|
||||||
|
max_line = max_line || 500;
|
||||||
|
const base = document.createElement('div');
|
||||||
|
let lines = from.split('\n');
|
||||||
|
if (lines.length > max_line) {
|
||||||
|
lines = lines.slice(0, max_line);
|
||||||
|
lines.push("...");
|
||||||
|
}
|
||||||
|
|
||||||
|
let prev = '';
|
||||||
|
let child_cont;
|
||||||
|
lines.forEach(line => {
|
||||||
|
if (line.trim() === '') return;
|
||||||
|
let node;
|
||||||
|
let spl = line.split(' ');
|
||||||
|
let md_flag = spl[0];
|
||||||
|
|
||||||
|
switch (md_flag) {
|
||||||
|
// 标题
|
||||||
|
case '#':
|
||||||
|
case '##':
|
||||||
|
case '###':
|
||||||
|
if (prev === 'li') {
|
||||||
|
child_cont = null;
|
||||||
|
}
|
||||||
|
prev = 'h' + (md_flag.length + 1);
|
||||||
|
node = document.createElement(prev);
|
||||||
|
node.innerText = line.slice(md_flag.length + 1);
|
||||||
|
base.append(node);
|
||||||
|
return;
|
||||||
|
// 列表
|
||||||
|
case '-':
|
||||||
|
if (prev !== 'li') {
|
||||||
|
child_cont = document.createElement('ul');
|
||||||
|
if (!base.contains(child_cont)) base.append(child_cont);
|
||||||
|
}
|
||||||
|
prev = 'li';
|
||||||
|
node = document.createElement(prev);
|
||||||
|
node.innerText = line.slice(2);
|
||||||
|
child_cont.append(node);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
prev = 'p';
|
||||||
|
node = document.createElement(prev);
|
||||||
|
node.innerText = line.trim();
|
||||||
|
base.append(node);
|
||||||
|
})
|
||||||
|
return base;
|
||||||
|
}
|
||||||
151
src/func/utils/@deprecated/WHNotify.ts
Normal file
151
src/func/utils/@deprecated/WHNotify.ts
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
import addStyle from "./addStyle";
|
||||||
|
import WuhuBase from "../../../class/WuhuBase";
|
||||||
|
import MathUtils from "../../../class/utils/MathUtils";
|
||||||
|
import WindowActiveState from "../../../class/action/WindowActiveState";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知方法
|
||||||
|
* @param {string} msg - 通知内容
|
||||||
|
* @param {Object} [options] - 通知选项
|
||||||
|
* @param {number} [options.timeout] - 通知超时时间
|
||||||
|
* @param {function} [options.callback] - 通知回调
|
||||||
|
* @param {boolean} [options.sysNotify] - 是否开启系统通知
|
||||||
|
* @param {string} [options.sysNotifyTag] - 系统通知标记
|
||||||
|
* @param {function} [options.sysNotifyClick] - 系统通知点击事件
|
||||||
|
* @return {HTMLElement}
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTMLElement {
|
||||||
|
let { notifies } = WuhuBase.glob;
|
||||||
|
let mathUtils: MathUtils = MathUtils.getInstance();
|
||||||
|
|
||||||
|
let {
|
||||||
|
timeout = 3,
|
||||||
|
callback = function () {
|
||||||
|
},
|
||||||
|
sysNotify = false,
|
||||||
|
sysNotifyTag = '芜湖助手',
|
||||||
|
sysNotifyClick = () => window.focus()
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
if (!WindowActiveState.getInstance().get() || (self !== top)) return null;
|
||||||
|
const date = new Date();
|
||||||
|
// 通知的唯一id
|
||||||
|
const uid = `${ date.getHours() }${ date.getSeconds() }${ date.getMilliseconds() }${ mathUtils.getRandomInt(1000, 9999) }`;
|
||||||
|
// 通知容器id
|
||||||
|
// 通知的容器
|
||||||
|
let notify_contain: MyHTMLElement = document.querySelector(`#wh-notify`);
|
||||||
|
// 添加通知到容器
|
||||||
|
const add_notify = () => {
|
||||||
|
// 每条通知
|
||||||
|
const new_node: MyHTMLElement = document.createElement('div');
|
||||||
|
new_node.id = `wh-notify-${ uid }`;
|
||||||
|
new_node.classList.add('wh-notify-item');
|
||||||
|
new_node.innerHTML = `<div class="wh-notify-bar"></div>
|
||||||
|
<div class="wh-notify-cont">
|
||||||
|
<div class="wh-notify-close"></div>
|
||||||
|
<div class="wh-notify-msg"><p>${ msg }</p></div>
|
||||||
|
</div>`;
|
||||||
|
notify_contain.append(new_node);
|
||||||
|
notify_contain['msgInnerText'] = new_node.querySelector('.wh-notify-msg').innerText;
|
||||||
|
// 进度条node
|
||||||
|
const progressBar: HTMLElement = new_node.querySelector('.wh-notify-bar');
|
||||||
|
// 是否hover
|
||||||
|
let mouse_enter = false;
|
||||||
|
new_node.addEventListener('mouseenter', () => mouse_enter = true, true);
|
||||||
|
new_node.addEventListener('mouseleave', () => mouse_enter = false);
|
||||||
|
// 通知进度条
|
||||||
|
let progressCount = 101;
|
||||||
|
// 删除通知
|
||||||
|
new_node.close = () => {
|
||||||
|
clearInterval(intervalID);
|
||||||
|
new_node.remove();
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
// 计时器
|
||||||
|
let intervalID = window.setInterval(() => {
|
||||||
|
if (mouse_enter) {
|
||||||
|
progressCount = 101;
|
||||||
|
progressBar.style.width = '100%';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
progressCount--;
|
||||||
|
progressBar.style.width = `${ progressCount }%`;
|
||||||
|
if (progressCount === 0) new_node.remove();
|
||||||
|
}, timeout * 1000 / 100);
|
||||||
|
new_node.querySelector('.wh-notify-close').addEventListener('click', new_node.close);
|
||||||
|
return new_node;
|
||||||
|
};
|
||||||
|
// 不存在容器 创建
|
||||||
|
if (!notify_contain) {
|
||||||
|
notify_contain = document.createElement('div');
|
||||||
|
notify_contain.id = 'wh-notify';
|
||||||
|
addStyle(`
|
||||||
|
#wh-notify {
|
||||||
|
display: inline-block;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: calc(50% - 180px);
|
||||||
|
width: 360px;
|
||||||
|
z-index: 9999990;
|
||||||
|
color:#333;
|
||||||
|
}
|
||||||
|
#wh-notify a{
|
||||||
|
color:red;
|
||||||
|
text-decoration:none;
|
||||||
|
}
|
||||||
|
#wh-notify .wh-notify-item {
|
||||||
|
/*height: 50px;*/
|
||||||
|
background: rgb(239 249 255 / 90%);
|
||||||
|
border-radius: 2px;
|
||||||
|
margin: 0.5em 0 0 0;
|
||||||
|
box-shadow: 0 0 5px 0px #959595;
|
||||||
|
}
|
||||||
|
#wh-notify .wh-notify-item:hover {
|
||||||
|
background: rgb(239 249 255 / 98%);
|
||||||
|
}
|
||||||
|
#wh-notify .wh-notify-item .wh-notify-bar {
|
||||||
|
height:2px;
|
||||||
|
background:#2196f3;
|
||||||
|
}
|
||||||
|
#wh-notify .wh-notify-item .wh-notify-close {
|
||||||
|
float:right;
|
||||||
|
padding:0;
|
||||||
|
width:16px;height:16px;
|
||||||
|
background:url('data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%201024%201024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M923%20571H130.7c-27.6%200-50-22.4-50-50s22.4-50%2050-50H923c27.6%200%2050%2022.4%2050%2050s-22.4%2050-50%2050z%22%20fill%3D%22%232196f3%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E') no-repeat center;
|
||||||
|
background-size:100%;
|
||||||
|
margin: 6px 6px 0 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
#wh-notify .wh-notify-item .wh-notify-msg {
|
||||||
|
padding:12px;
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
document.body.append(notify_contain);
|
||||||
|
}
|
||||||
|
const notify_obj = add_notify();
|
||||||
|
// 浏览器通知
|
||||||
|
if (window.Notification && Notification.permission === 'granted' && sysNotify) {
|
||||||
|
const date_local_string = `[${ date.getHours() }:${ date.getMinutes() }:${ date.getSeconds() }]\r`;
|
||||||
|
notify_obj.sys_notify = new Notification('芜湖助手', {
|
||||||
|
body: date_local_string + notify_contain.msgInnerText,
|
||||||
|
requireInteraction: true,
|
||||||
|
renotify: true,
|
||||||
|
tag: sysNotifyTag + mathUtils.getRandomInt(0, 99),
|
||||||
|
});
|
||||||
|
notify_obj.sys_notify.addEventListener('close', () => sysNotifyClick());
|
||||||
|
notify_obj.sys_notify.onshow = () => setTimeout(() => notify_obj.sys_notify.close(), timeout * 1000);
|
||||||
|
notify_obj.sys_notify.id = notifies.count++;
|
||||||
|
notifies[notify_obj.sys_notify.id] = notify_obj.sys_notify;
|
||||||
|
notify_obj.sys_notify.addEventListener('close', () => notifies[notify_obj.sys_notify.id] = null);
|
||||||
|
}
|
||||||
|
return notify_obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WHNotifyOpt {
|
||||||
|
timeout?: number;
|
||||||
|
callback?: Function;
|
||||||
|
sysNotify?: boolean;
|
||||||
|
sysNotifyTag?: string;
|
||||||
|
sysNotifyClick?: Function;
|
||||||
|
}
|
||||||
22
src/func/utils/@deprecated/addActionBtn.ts
Normal file
22
src/func/utils/@deprecated/addActionBtn.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import Log from "../../../class/Log";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export default function addActionBtn(txt: string, func: (ev: Event) => void, mainBtnNode: Element): void {
|
||||||
|
addActionBtn.proxy(txt, func, mainBtnNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
addActionBtn.proxy = (txt: string, func: (ev: Event) => void, mainBtnNode: Element) => {
|
||||||
|
if (mainBtnNode.querySelector('#wh-trans-icon-btn').nextSibling !== null) return;
|
||||||
|
let btn = document.createElement('button');
|
||||||
|
btn.style.padding = '8px 13px 8px 0';
|
||||||
|
btn.style.verticalAlign = 'bottom';
|
||||||
|
btn.style.color = '#4CAF50';
|
||||||
|
btn.innerHTML = txt;
|
||||||
|
btn.addEventListener('click', func);
|
||||||
|
mainBtnNode.querySelector('button').after(btn);
|
||||||
|
addActionBtn.proxy = () => {
|
||||||
|
Log.error('错误:附加按钮已存在')
|
||||||
|
};
|
||||||
|
}
|
||||||
17
src/func/utils/@deprecated/addStyle.ts
Normal file
17
src/func/utils/@deprecated/addStyle.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import log from "./log";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export default function addStyle(css: string) {
|
||||||
|
let wh_gStyle = document.querySelector('style#wh-trans-gStyle');
|
||||||
|
if (wh_gStyle) {
|
||||||
|
wh_gStyle.innerHTML += css;
|
||||||
|
} else {
|
||||||
|
wh_gStyle = document.createElement("style");
|
||||||
|
wh_gStyle.id = 'wh-trans-gStyle';
|
||||||
|
wh_gStyle.innerHTML = css;
|
||||||
|
document.head.append(wh_gStyle);
|
||||||
|
}
|
||||||
|
log.info('CSS规则已添加', wh_gStyle);
|
||||||
|
}
|
||||||
23
src/func/utils/@deprecated/ajaxFetch.ts
Normal file
23
src/func/utils/@deprecated/ajaxFetch.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export default function ajaxFetch(opt) {
|
||||||
|
let { url, referrer, method, body = null } = opt;
|
||||||
|
let req_params: AjaxFetchOpt = {
|
||||||
|
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
||||||
|
referrer,
|
||||||
|
method,
|
||||||
|
};
|
||||||
|
if (method === 'POST') {
|
||||||
|
req_params.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||||
|
req_params.body = body;
|
||||||
|
}
|
||||||
|
return window.fetch(url, req_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AjaxFetchOpt {
|
||||||
|
headers: { 'X-Requested-With'?: string, 'Content-Type'?: string };
|
||||||
|
referrer: string;
|
||||||
|
method: string;
|
||||||
|
body?: any;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user