This commit is contained in:
Liwanyi 2022-09-21 18:47:52 +08:00
parent c1ba5c04ec
commit 42827f9a52
42 changed files with 455 additions and 185 deletions

View File

@ -2,6 +2,7 @@
<dictionary name="Liwanyi">
<words>
<w>wuhu</w>
<w>zhong</w>
</words>
</dictionary>
</component>

2
global.d.ts vendored
View File

@ -27,7 +27,7 @@ declare interface Window {
getAction(opt: TornGetActionParams): void;
initMiniProf(selector: string): void;
// initMiniProf(selector: string): void;
initializeTooltip(selector: string, elemId: string): void;

133
package-lock.json generated
View File

@ -4,6 +4,32 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@babel/code-frame": {
"version": "7.18.6",
"resolved": "https://registry.npmmirror.com/@babel/code-frame/-/code-frame-7.18.6.tgz",
"integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==",
"dev": true,
"requires": {
"@babel/highlight": "^7.18.6"
}
},
"@babel/helper-validator-identifier": {
"version": "7.19.1",
"resolved": "https://registry.npmmirror.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz",
"integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==",
"dev": true
},
"@babel/highlight": {
"version": "7.18.6",
"resolved": "https://registry.npmmirror.com/@babel/highlight/-/highlight-7.18.6.tgz",
"integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==",
"dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.18.6",
"chalk": "^2.0.0",
"js-tokens": "^4.0.0"
}
},
"@rollup/plugin-typescript": {
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-8.5.0.tgz",
@ -52,6 +78,47 @@
"integrity": "sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ==",
"dev": true
},
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmmirror.com/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmmirror.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true
},
"estree-walker": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz",
@ -80,6 +147,12 @@
"function-bind": "^1.1.1"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true
},
"is-core-module": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.10.0.tgz",
@ -89,6 +162,39 @@
"has": "^1.0.3"
}
},
"jest-worker": {
"version": "24.9.0",
"resolved": "https://registry.npmmirror.com/jest-worker/-/jest-worker-24.9.0.tgz",
"integrity": "sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw==",
"dev": true,
"requires": {
"merge-stream": "^2.0.0",
"supports-color": "^6.1.0"
},
"dependencies": {
"supports-color": {
"version": "6.1.0",
"resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-6.1.0.tgz",
"integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"merge-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/merge-stream/-/merge-stream-2.0.0.tgz",
"integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==",
"dev": true
},
"mime": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz",
@ -143,6 +249,33 @@
"opener": "1"
}
},
"rollup-plugin-uglify": {
"version": "6.0.4",
"resolved": "https://registry.npmmirror.com/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.4.tgz",
"integrity": "sha512-ddgqkH02klveu34TF0JqygPwZnsbhHVI6t8+hGTcYHngPkQb5MIHI0XiztXIN/d6V9j+efwHAqEL7LspSxQXGw==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
"jest-worker": "^24.0.0",
"serialize-javascript": "^2.1.2",
"uglify-js": "^3.4.9"
}
},
"serialize-javascript": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/serialize-javascript/-/serialize-javascript-2.1.2.tgz",
"integrity": "sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
},
"supports-preserve-symlinks-flag": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",

View File

@ -2,7 +2,6 @@
"name": "wuhu-torn-helper",
"version": "0.5.1",
"dependencies": {
"uglify-js": "^3.16.1"
},
"scripts": {
"release": "npm run minify && node build.js",
@ -18,6 +17,8 @@
"rollup": "^2.79.0",
"rollup-plugin-serve": "^2.0.1",
"tslib": "^2.4.0",
"typescript": "^4.8.3"
"typescript": "^4.8.3",
"rollup-plugin-uglify": "^6.0.4",
"uglify-js": "^3.16.1"
}
}

View File

@ -1,4 +1,5 @@
import typescript from "@rollup/plugin-typescript";
import { uglify } from "rollup-plugin-uglify";
export default {
input: 'src/main.ts',
@ -7,5 +8,6 @@ export default {
},
plugins: [
typescript(),
// uglify(),
],
};

View File

@ -3,7 +3,8 @@ import Device from "../enum/Device";
import WindowActiveState from "../func/utils/WindowActiveState";
import WuhuBase from "./WuhuBase";
import IGlobal from "../interface/IGlobal";
import Utils from "./Utils";
import Utils from "./utils/Utils";
import Log from "./Log";
export default class Global extends WuhuBase implements IGlobal {
GM_xmlhttpRequest: Function = null;
@ -45,6 +46,7 @@ export default class Global extends WuhuBase implements IGlobal {
isWindowActive = null;
private constructor() {
Log.info('Global初始化');
super();
this.window = window;
this.unsafeWindow = window.unsafeWindow || null;
@ -69,6 +71,8 @@ export default class Global extends WuhuBase implements IGlobal {
this.GM_xmlhttpRequest = null;
}
}
let initializeTooltip = window;
Log.info({ initializeTooltip })
for (let i = 0; i < document.body.attributes.length; i++) {
let item = document.body.attributes.item(i);
@ -86,6 +90,8 @@ export default class Global extends WuhuBase implements IGlobal {
}
}
);
Log.info('Global初始化结束');
}
static getInstance(this): Global {

View File

@ -1,18 +1,36 @@
import WuhuBase from "./WuhuBase";
import getWhSettingObj from "../func/utils/getWhSettingObj";
export default class Log{
static info(this, ...o) {
(this.debug()) && (console.log('[WH]', this.getTime(), ...o))
}
export default class Log extends WuhuBase{
static info(...o) {
return (this.debug()) && (console.log('[WH]', ...o))
}
static error(...o) {
return (this.debug()) && (console.error('[WH]', ...o))
(this.debug()) && (console.error('[WH]', this.getTime(), ...o))
}
static debug() {
let ret: boolean;
try {
return getWhSettingObj()['isDev'] || false;
let local = JSON.parse(localStorage.getItem('wh_trans_settings'));
if (local) ret = local['isDev'];
else ret = false;
} catch {
return false;
ret = false;
}
return ret;
}
static getTime() {
let d = new Date();
let year = d.getFullYear();
let month = ('0' + (d.getMonth() + 1)).slice(-2);
let date = ('0' + d.getDate()).slice(-2);
let hours = ('0' + d.getHours()).slice(-2);
let minutes = ('0' + d.getMinutes()).slice(-2);
let seconds = ('0' + d.getSeconds()).slice(-2);
let ms = ('00' + d.getMilliseconds()).slice(-3);
return `[${ year }-${ month }-${ date } ${ hours }:${ minutes }:${ seconds }.${ ms }]`;
}
private constructor() {
}
}

View File

@ -1,18 +1,10 @@
import Utils from "./Utils";
import Utils from "./utils/Utils";
import WuhuBase from "./WuhuBase";
export default class TravelItem extends WuhuBase{
export default class TravelItem extends WuhuBase {
obj: any = null;
res: any = null;
async get() {
if (!this.obj) {
const str = await this.res
this.obj = JSON.parse(str);
}
return this.obj;
}
constructor(destination: string) {
super();
setInterval(async () => {
@ -21,4 +13,12 @@ export default class TravelItem extends WuhuBase{
this.obj = JSON.parse(res);
}, 30 * 1000);
}
async get() {
if (!this.obj) {
const str = await this.res
this.obj = JSON.parse(str);
}
return this.obj;
}
}

View File

@ -1,5 +1,23 @@
import IGlobal from "../interface/IGlobal";
import IWHSettings from "../interface/IWHSettings";
import Log from "./Log";
export default class WuhuBase {
static glob: IGlobal = null;
static getLocal(): IWHSettings {
return JSON.parse(localStorage.getItem('wh_trans_settings'));
}
static conditionInterrupt() {
if (
document.title.toLowerCase().includes('just a moment') ||
document.querySelector('#skip-to-content').innerText.toLowerCase().includes('please validate')
)
throw '芜湖';
}
constructor() {
Log.info('创建对象:' + this.constructor.name)
}
}

18
src/class/WuhuConfig.ts Normal file
View File

@ -0,0 +1,18 @@
import WuhuBase from "./WuhuBase";
export default class WuhuConfig extends WuhuBase {
static get(key: string) {
return WuhuBase.getLocal()[key];
}
static set(key: string, val: any, callback: Function = () => {
}) {
let config = WuhuBase.getLocal();
config[key] = val;
localStorage.setItem('wh_trans_settings', JSON.stringify(config));
// if (isNotify) WHNotify('已保存设置')
new Promise(() => callback()).then();
return val;
}
}

View File

@ -1,24 +1,26 @@
import log from "../func/utils/log";
import getWhSettingObj from "../func/utils/getWhSettingObj";
import miniprofTrans from "../func/translate/miniprofTrans";
import addStyle from "../func/utils/addStyle";
import Utils from "./Utils";
import Utils from "./utils/Utils";
import WuhuBase from "./WuhuBase";
import TravelItem from "./TravelItemFetchLoop";
import Global from "./Global";
import Log from "./Log";
export default class WuHuTornHelper extends WuhuBase{
export default class WuHuTornHelper extends WuhuBase {
init() {
Log.info('WuHuTornHelper初始化');
WuhuBase.glob = Global.getInstance();
let glob = WuhuBase.glob;
glob.fStock = new TravelItem('https://yata.yt/api/v1/travel/export/');
Log.info(glob.fStock)
// 请求通知权限
if (window.Notification && Notification.permission !== 'granted') {
Notification.requestPermission().then();
} else {
log.info({ Notification });
Log.info({ Notification });
}
// 扩展正则方法
@ -45,7 +47,7 @@ export default class WuHuTornHelper extends WuhuBase{
}
let clone = res.clone();
let text = await res.text();
log.info({ url, init, text });
Log.info({ url, init, text });
return clone;
};
@ -209,6 +211,7 @@ cursor:pointer;
}
}
Log.info('WuHuTornHelper初始化结束');
return this;
}
}

View File

@ -1,27 +1,26 @@
import getWhSettingObj from "../func/utils/getWhSettingObj";
import setWhSetting from "../func/utils/setWhSetting";
import log from "../func/utils/log";
import popupMsg from "../func/utils/popupMsg";
import COFetch from "../func/utils/COFetch";
import WHNotify from "../func/utils/WHNotify";
import forStock from "../func/utils/forStock";
import addStyle from "../func/utils/addStyle";
import doQuickFly from "../func/module/doQuickFly";
import getYaoCD from "../func/utils/getYaoCD";
import loadGS from "../func/module/loadGS";
import getScriptEngine from "../func/utils/getScriptEngine";
import loading_gif_html from "../func/utils/loading_gif_html";
import elementReady from "../func/utils/elementReady";
import adHelper from "../func/module/adHelper";
import safeKeeper from "../func/module/safeKeeper";
import mdParse from "../func/utils/MarkdownParser";
import getDeviceType from "../func/utils/getDeviceType";
import updateTransDict from "../func/translate/updateTransDict";
import landedRedirect from "../func/module/landedRedirect";
import initMiniProf from "../func/utils/initMiniProf";
import WuhuBase from "./WuhuBase";
import Log from "./Log";
import Utils from "./utils/Utils";
import WuhuConfig from "./WuhuConfig";
import Alert from "./utils/Alert";
export default class ZhongIcon extends WuhuBase {
static ZhongNode: MyHTMLElement = null;
static elemGenerator(setting: MenuItemConfig, root_node: Node) {
let { tip, domType } = setting;
let new_node = null;
@ -34,9 +33,9 @@ export default class ZhongIcon extends WuhuBase {
let input = document.createElement('input');
input.type = 'checkbox';
input.id = domId;
input.checked = getWhSettingObj()[dictName];
input.checked = WuhuConfig.get(dictName);
input.onchange = e => {
setWhSetting(dictName, (e.target as HTMLInputElement).checked);
WuhuConfig.set(dictName, (e.target as HTMLInputElement).checked);
if (setting.changeEv) setting.changeEv(e);
};
label.innerHTML = domText;
@ -68,11 +67,11 @@ export default class ZhongIcon extends WuhuBase {
let option = document.createElement('option');
option.value = domVal;
option.innerHTML = domText;
option.selected = i === getWhSettingObj()[dictName];
option.selected = i === WuhuConfig.get(dictName);
option.innerHTML = domText;
select.appendChild(option);
});
select.onchange = e => setWhSetting(dictName, (<HTMLSelectElement>e.target).selectedIndex);
select.onchange = e => WuhuConfig.set(dictName, (<HTMLSelectElement>e.target).selectedIndex);
label.appendChild(text);
label.appendChild(select);
new_node.appendChild(label);
@ -91,8 +90,12 @@ export default class ZhongIcon extends WuhuBase {
}
static initialize() {
Log.info('ZhongIcon初始化');
ZhongIcon.setDefaultSettings();
ZhongIcon.initIcon(ZhongIcon.getMenuItems())
Log.info('设置图标开始');
ZhongIcon.initIcon(ZhongIcon.getMenuItems());
Log.info('设置图标结束');
Log.info('ZhongIcon初始化结束');
}
/**
@ -129,19 +132,19 @@ export default class ZhongIcon extends WuhuBase {
zhong_node.classList.toggle('wh-icon-expanded');
const click_func = e => {
// e.stopImmediatePropagation();
log.info(e.target);
Log.info(e.target);
if (e.target === zhong_node.querySelector('#wh-trans-icon-btn')) return;
if (!zhong_node.contains(e.target)) {
log.info('移除事件监听器');
Log.info('移除事件监听器');
document.body.removeEventListener('click', click_func);
zhong_node.classList.remove('wh-icon-expanded');
}
};
if (zhong_node.classList.contains('wh-icon-expanded')) {
log.info('添加事件监听器');
Log.info('添加事件监听器');
document.body.addEventListener('click', click_func);
} else {
log.info('移除事件监听器');
Log.info('移除事件监听器');
document.body.removeEventListener('click', click_func);
}
};
@ -164,7 +167,7 @@ export default class ZhongIcon extends WuhuBase {
node.querySelector('button').onclick = async (e) => {
let target = e.target as HTMLButtonElement;
target.innerHTML = '加载中';
const js_text = await COFetch(`https://jjins.github.io/fyfuzhi/release.min.user.js?${ performance.now() }`);
const js_text = await Utils.COFetch(`https://jjins.github.io/fyfuzhi/release.min.user.js?${ performance.now() }`);
target.innerHTML = '点击复制到剪切板';
target.onclick = () => {
const textarea_node = document.createElement('textarea');
@ -201,11 +204,9 @@ export default class ZhongIcon extends WuhuBase {
: el.addEventListener('click', null));
document.body.append(zhong_node);
// 引入torn自带浮动提示
// (window['initializeTooltip']) && (window['initializeTooltip']('.wh-container', 'white-tooltip'));
Log.info(WuhuBase.glob);
WuhuBase.glob.unsafeWindow.initializeTooltip('.wh-container', 'white-tooltip');
(window.initializeTooltip) && (window.initializeTooltip('.wh-container', 'white-tooltip'));
// 加载torn mini profile
WuhuBase.glob.unsafeWindow.initMiniProf('#wh-trans-icon');
initMiniProf('#wh-trans-icon');
ZhongIcon.ZhongNode = zhong_node;
return zhong_node;
}
@ -484,7 +485,7 @@ info{display:block;}
type_node.addEventListener('change', showTime);
document.body.append(node);
showTime();
yaoCD.innerHTML = `药CD剩余${ getYaoCD() }`;
yaoCD.innerHTML = `药CD剩余${ Utils.getYaoCD() }`;
},
});
// NPC LOOT
@ -699,7 +700,7 @@ background-size: 100% auto !important;
domText: '🐏 飞贼小助手',
clickFunc: function (e) {
e.target.blur();
loadGS(getScriptEngine());
loadGS(Utils.getScriptEngine());
},
tip: '加载从PC端移植的伞佬的油猴版飞贼小助手',
});
@ -709,7 +710,7 @@ background-size: 100% auto !important;
domId: 'wh-price-watcher-btn',
domText: '💊 价格监视',
clickFunc: function () {
const watcher_conf = getWhSettingObj()['priceWatcher'];
const watcher_conf = WuhuConfig.get('priceWatcher');
const pre_str = JSON.stringify(watcher_conf);
const html = `<style>
#wh-popup-cont input{width:12em;}
@ -729,7 +730,7 @@ background-size: 100% auto !important;
const [pt_node, xan_node] = Array.from(<NodeListOf<HTMLInputElement>>popup.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) setWhSetting('priceWatcher', watcher_conf);
if (JSON.stringify(watcher_conf) !== pre_str) WuhuConfig.set('priceWatcher', watcher_conf);
popup.close();
};
}
@ -849,14 +850,14 @@ background-size: 100% auto !important;
clickFunc: function (e) {
e.target.blur();
const insert = `<p>即将打开危险功能,使用这些功能可能会造成账号封禁。请自行考虑是否使用。</p>
<p><label><input type="checkbox" ${ getWhSettingObj()['dangerZone'] ? 'checked ' : ' ' }/> </label></p>
<p><label><input type="checkbox" ${ WuhuConfig.get('dangerZone') ? 'checked ' : ' ' }/> </label></p>
<div><button disabled></button></div>`;
const popup = popupMsg(insert, '⚠️警告');
const warning_check = popup.querySelector('input');
const ok_btn = popup.querySelector('button');
warning_check.onchange = () => ok_btn.disabled = false;
ok_btn.onclick = () => {
setWhSetting('dangerZone', warning_check.checked);
WuhuConfig.set('dangerZone', warning_check.checked);
popup['close']();
window.location.reload();
};
@ -885,7 +886,7 @@ background-size: 100% auto !important;
'更新历史:<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/>',
'更新历史'
);
popup.classList.add('wh-changelog');
popup.classList.add('wh-changeLog');
let progressBar = document.createElement('div');
progressBar.style.height = '2px';
progressBar.style.width = '1%';
@ -894,10 +895,10 @@ background-size: 100% auto !important;
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;}`;
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);
let update = await COFetch('https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/CHANGELOG.md?' + Date.now());
let update = await Utils.COFetch('https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/CHANGELOG.md?' + Date.now());
progressBar.style.width = '60%';
progressText.innerText = '解析中……';
let md = mdParse(update);
@ -923,7 +924,7 @@ background-size: 100% auto !important;
// 本日不提醒
$zhongNode.setting_root.querySelector('#wh-qua-alarm-check-btn').addEventListener('click', glob.beer.skip_today);
// 开发详情按钮
if (log.debug()) $zhongNode.setting_root.querySelector('button#wh-devInfo').onclick = () => {
if (Log.debug()) $zhongNode.setting_root.querySelector('button#wh-devInfo').onclick = () => {
const date = new Date();
let os = '未知';
try {
@ -934,8 +935,8 @@ background-size: 100% auto !important;
const insert = `<table id="wh-dev-info-tb">
<tr><td>URL</td><td>${ window.location.href }</td></tr>
<tr><td></td><td>${ window.innerWidth }x${ window.innerHeight }</td></tr>
<tr><td></td><td>${ getDeviceType().toUpperCase() }</td></tr>
<tr><td></td><td>${ { 'gm': '油猴', 'raw': '直接运行', 'pda': 'TornPDA' }[getScriptEngine()] }</td></tr>
<tr><td></td><td>${ Utils.getDeviceType().toUpperCase() }</td></tr>
<tr><td></td><td>${ { 'gm': '油猴', 'raw': '直接运行', 'pda': 'TornPDA' }[Utils.getScriptEngine()] }</td></tr>
<tr><td></td><td>${ date.getFullYear() }/${ date.getMonth() + 1 }/${ date.getDate() } ${ date.getHours() }:${ date.getMinutes() }:${ date.getSeconds() }</td></tr>
<tr><td></td><td>${ glob.version }</td></tr>
<tr><td></td><td>${ os }</td></tr>
@ -956,13 +957,20 @@ color:black;
},
});
// 测试
if (log.debug()) menu_list.push({
if (Log.debug()) menu_list.push({
domType: 'button',
domId: '',
domText: '📐️ 测试',
clickFunc: async function () {
let res = await COFetch('https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/CHANGELOG.md')
log.info(mdParse(res))
Log.info('测试开始');
// sessionStorage.removeItem('sidebarData2687093')
// Log.info(await Utils.getSidebarData())
// Log.info(await Utils.getUserState())
new Alert("123");
Log.info('测试结束');
},
});
@ -1217,17 +1225,17 @@ color:black;
// tip: '通知提前时间',
clickFunc: function () {
glob.popup_node.close();
let popup = popupMsg(`<label>提前提醒时间(秒)<input type="number" value="${ getWhSettingObj()['_15AlarmTime'] }" /></label><p>区间为 1 ~ 60默认 50</p>`, '啤酒提醒时间设定');
let popup = popupMsg(`<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.querySelector('input');
let num = (input.value as any) | 0;
if (num === getWhSettingObj()['_15AlarmTime']) return;
if (num === WuhuConfig.get('_15AlarmTime')) return;
if (num < 1 || num > 60) num = 50;
input.value = num.toString();
setWhSetting('_15AlarmTime', num);
WuhuConfig.set('_15AlarmTime', num);
// 之前的运行状态
let before_state = glob.beer.is_running();
glob.beer.set_time(num);
@ -1307,7 +1315,7 @@ color:black;
tip: '清除Google相关脚本、顶部横幅等',
});
// 危险行为⚠️
if (getWhSettingObj()['dangerZone'] === true) {
if (WuhuConfig.get('dangerZone') === true) {
// 攻击界面自刷新
setting_list.push({
domType: 'select',
@ -1357,22 +1365,22 @@ color:black;
isHide: true,
});
} else {
setWhSetting('autoStartFinish', false, false)
setWhSetting('attReload', 6, false)
WuhuConfig.set('autoStartFinish', false)
WuhuConfig.set('attReload', 6)
}
// dev
setting_list.push({
domType: 'checkbox',
domId: 'wh-dev-mode',
domText: ` 开发者模式${ log.debug() ? ' <button id="wh-devInfo">详情</button>' : '' }`,
domText: ` 开发者模式${ Log.debug() ? ' <button id="wh-devInfo">详情</button>' : '' }`,
dictName: 'isDev',
isHide: true,
});
// 更多设定
if (log.debug()) setting_list.push({
if (Log.debug()) setting_list.push({
domType: 'button', domId: 'wh-otherBtn', domText: '更多设定', clickFunc: () => {
const html = `清空设置数据、请求通知权限、测试跨域请求`;
const popup = popupMsg(html, '更多设定');
popupMsg(html, '更多设定');
},
isHide: true,
});
@ -1382,6 +1390,7 @@ color:black;
// 默认设置
static setDefaultSettings(): void {
Log.info('Wuhu设置默认值');
[
// 开启翻译
{ key: 'transEnable', val: false },
@ -1441,11 +1450,10 @@ color:black;
// 危险行为⚠️
{ key: 'dangerZone', val: false },
].forEach(df => {
if (typeof getWhSettingObj()[df.key] !== typeof df.val) setWhSetting(df.key, df.val);
if (typeof WuhuConfig.get(df.key) !== typeof df.val) WuhuConfig.set(df.key, df.val);
});
Log.info('Wuhu设置默认值结束');
}
static ZhongNode: MyHTMLElement = null;
}
interface MenuItemConfig {

View File

@ -0,0 +1,3 @@
import WuhuBase from "../WuhuBase";
export default class WuhuBaseAction extends WuhuBase {}

30
src/class/utils/Alert.ts Normal file
View File

@ -0,0 +1,30 @@
import WuhuBase from "../WuhuBase";
import Log from "../Log";
export default class Alert extends WuhuBase{
static hasContainer: boolean = false;
constructor(msg: string, options: WHNotifyOpt = {}) {
super();
let { isWindowActive, notifies } = WuhuBase.glob;
let {
timeout = 3,
callback = function () {
},
sysNotify = false,
sysNotifyTag = '芜湖助手',
sysNotifyClick = () => window.focus()
} = options;
if (!isWindowActive() || (self !== top)) return null;
}
}
interface WHNotifyOpt {
timeout?: number;
callback?: Function;
sysNotify?: boolean;
sysNotifyTag?: string;
sysNotifyClick?: Function;
}

View File

@ -1,9 +1,9 @@
import UserScriptEngine from "../enum/UserScriptEngine";
import WuhuBase from "./WuhuBase";
import Log from "./Log";
import Device from "../enum/Device";
import ISidebarData from "../interface/ISidebarData";
import IWHSettings from "../interface/IWHSettings";
import UserScriptEngine from "../../enum/UserScriptEngine";
import WuhuBase from "../WuhuBase";
import Log from "../Log";
import Device from "../../enum/Device";
import ISidebarData from "../../interface/ISidebarData";
import AjaxFetchOption from "../../interface/AjaxFetchOption";
export default class Utils extends WuhuBase {
static getScriptEngine() {
@ -13,11 +13,13 @@ export default class Utils extends WuhuBase {
}
static COFetch(url: URL | string, method: 'get' | 'post' = 'get', body: any = null): Promise<string> {
Log.info('跨域获取数据开始');
return new Promise<string>((resolve, reject) => {
const engine = this.getScriptEngine();
Log.info('脚本引擎:' + engine);
switch (engine) {
case UserScriptEngine.RAW: {
console.error(`[wh] 跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
Log.error(`跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
reject(`错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
break;
}
@ -30,7 +32,10 @@ export default class Utils extends WuhuBase {
reject('COFetch网络错误PDA版本不支持');
}
PDA_httpGet(url)
.then(res => resolve(res.responseText))
.then(res => {
Log.info('跨域获取数据成功');
resolve(res.responseText);
})
.catch(e => {
Log.error('COFetch网络错误', e);
reject(`COFetch网络错误 ${ e }`);
@ -52,7 +57,7 @@ export default class Utils extends WuhuBase {
break;
}
case UserScriptEngine.GM: {
let { GM_xmlhttpRequest } = window;
let { GM_xmlhttpRequest } = WuhuBase.glob;
if (typeof GM_xmlhttpRequest !== 'function') {
Log.error('COFetch网络错误用户脚本扩展API错误');
reject('错误用户脚本扩展API错误');
@ -62,7 +67,10 @@ export default class Utils extends WuhuBase {
url: url,
data: method === 'get' ? null : body,
headers: method === 'get' ? null : { 'content-type': 'application/json' },
onload: res => resolve(res.response),
onload: res => {
Log.info('跨域获取数据成功');
resolve(res.response);
},
onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`),
ontimeout: res => reject(`连接超时 ${ JSON.stringify(res) }`),
});
@ -116,7 +124,16 @@ export default class Utils extends WuhuBase {
c++;
await this.sleep(10);
}
ret = JSON.parse(sessionStorage.getItem(field));
if (sessionStorage.getItem(field)) {
ret = JSON.parse(sessionStorage.getItem(field));
} else {
Log.info('无法从sessionStorage获取数据')
ret = await (await this.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);
});
@ -130,10 +147,6 @@ export default class Utils extends WuhuBase {
return (await this.getSessionData()).headerData.user.state;
}
static getWhSettingObj(): IWHSettings {
return JSON.parse(localStorage.getItem('wh_trans_settings')) || {}
}
static getYaoCD(): string {
if (document.querySelector("#icon49-sidebar")) { // 0-10min
return '<10分'
@ -149,4 +162,18 @@ export default class Utils extends WuhuBase {
return '无效'
}
}
static ajaxFetch(opt: AjaxFetchOption) {
let { url, referrer = '/', method, body = null } = opt;
let req_params: RequestInit = {
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 fetch(url, req_params);
}
}

View File

@ -3,10 +3,12 @@ import elementReady from "../utils/elementReady";
import getWhSettingObj from "../utils/getWhSettingObj";
import addActionBtn from "../utils/addActionBtn";
import addStyle from "../utils/addStyle";
import getRandomInt from "../utils/getRandomInt";
import log from "../utils/log";
import ZhongIcon from "../../class/ZhongIcon";
import WuhuBase from "../../class/WuhuBase";
import WuhuConfig from "../../class/WuhuConfig";
import Utils from "../../class/utils/Utils";
import Log from "../../class/Log";
export default async function attackHelper(): Promise<null> {
let { href, device } = WuhuBase.glob;
@ -36,8 +38,8 @@ export default async function attackHelper(): Promise<null> {
doAttackReload();
} else {
let reload_flag;
const timeout = getWhSettingObj().attReload * 1000 + getRandomInt(-500, 500);
log.info(`[WH] ${ timeout / 1000 }s 后自动刷新`);
const timeout = WuhuConfig.get('attReload') * 1000 + Utils.getRandomInt(-500, 500);
Log.info(`[WH] ${ timeout / 1000 }s 后自动刷新`);
window.setInterval(() => {
if (reload_flag === undefined) {
reload_flag = true;

View File

@ -1,8 +1,8 @@
import elementReady from "../utils/elementReady";
import COFetch from "../utils/COFetch";
import addStyle from "../utils/addStyle";
import toThousands from "../utils/toThousands";
import log from "../utils/log";
import Utils from "../../class/utils/Utils";
export default function cityFinder(): void {
addStyle(`
@ -65,7 +65,7 @@ display:inline-block;
container.append(info);
base.append(header);
base.append(container);
COFetch('https://jjins.github.io/item_price_raw.json')
Utils.COFetch('https://jjins.github.io/item_price_raw.json')
.then(r => items = JSON.parse(r))
.catch(err => {
log.info(err)

View File

@ -1,13 +1,14 @@
import elementReady from "../utils/elementReady";
import getWhSettingObj from "../utils/getWhSettingObj";
import addStyle from "../utils/addStyle";
import log from "../utils/log";
import addActionBtn from "../utils/addActionBtn";
import WHNotify from "../utils/WHNotify";
import jQueryAjax from "../utils/jQueryAjax";
import ajaxFetch from "../utils/ajaxFetch";
import ZhongIcon from "../../class/ZhongIcon";
import WuhuBase from "../../class/WuhuBase";
import Utils from "../../class/utils/Utils";
import Log from "../../class/Log";
export default function depoHelper() {
let { href } = WuhuBase.glob;
@ -22,7 +23,7 @@ export default function depoHelper() {
const btn = document.getElementById('ui-id-9');
if (btn) {
btn.click();
log.info('已自动打开存钱页面');
Log.info('已自动打开存钱页面');
}
}
// 收起冰蛙表格
@ -76,8 +77,8 @@ z-index: 999999;}`);
let handle = () => {
let { addRFC } = window;
// 不重复加载、已关闭的交易不加载
if (node_link !== null || location.hash.includes('logview')) return;
log.info('已添加GT助手');
if (node_link !== null || location.hash.includes('Logview')) return;
Log.info('已添加GT助手');
// 获取交易id
let query_params = location.hash.slice(1);
let traceId;
@ -85,17 +86,17 @@ z-index: 999999;}`);
.forEach(param =>
(param.startsWith('ID=')) && (traceId = param.slice(3))
);
log.info('交易id为', traceId);
Log.info('交易id为', traceId);
// 获取全部的钱数
let getTraceMoney = async () => {
if (typeof addRFC === 'function') {
let url = addRFC('/trade.php?step=getFullMoney&ID=' + traceId);
return (await ajaxFetch({ url: url, method: 'GET', referrer: 'trade.php' })).text();
return (await Utils.ajaxFetch({ url: url, method: 'GET', referrer: 'trade.php' })).text();
}
};
// 监听jquery ajax请求
if (log.debug()) $(document).ajaxComplete((_, xhr, settings) => log.info({ xhr, settings }));
if (Log.debug()) $(document).ajaxComplete((_, xhr, settings) => Log.info({ xhr, settings }));
// react 加载完成后将节点加入视图中
elementReady('#trade-container').then(() =>
document.querySelector('#trade-container').before(node)
@ -181,7 +182,7 @@ z-index: 999999;}`);
else {
node_link.remove();
node_link = null;
log.info('已移除GT助手');
Log.info('已移除GT助手');
}
});
}
@ -255,7 +256,7 @@ async function companyDepositAnywhere() {
body: 'deposit=' + money,
headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded' }
})).text();
log.info(res);
Log.info(res);
let node = document.createElement('div');
node.innerHTML = res;
let success = node.querySelector('.success-message');

View File

@ -1,8 +1,8 @@
import UserScriptEngine from "../../enum/UserScriptEngine";
import WHNotify from "../utils/WHNotify";
import addStyle from "../utils/addStyle";
import COFetch from "../utils/COFetch";
import log from "../utils/log";
import Utils from "../../class/utils/Utils";
// gs loader
export default function loadGS(use) {
@ -35,7 +35,7 @@ z-index:100001;
_docu.head.innerHTML = '';
_docu.body.innerHTML = '';
notify = WHNotify('加载依赖');
COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
.then(vuejs => {
notify.close();
_window.eval(vuejs);
@ -51,7 +51,7 @@ z-index:100001;
_window.GM_xmlhttpRequest = function (opt) {
// 暂不适配pda post
if (opt.method.toLowerCase() === 'post') return;
COFetch(opt.url).then(res => {
Utils.COFetch(opt.url).then(res => {
const obj = {
responseText: res
};
@ -59,7 +59,7 @@ z-index:100001;
});
};
notify = WHNotify('加载飞贼小助手');
COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
Utils.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);
@ -84,7 +84,7 @@ z-index:100001;
if (use === UserScriptEngine.GM) {
if (typeof window.Vue !== 'function') {
let notify = WHNotify('正在加载依赖');
COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
.then(VueJS => {
window.eval(VueJS);
notify.close();
@ -100,7 +100,7 @@ z-index:100001;
};
// TODO
// window.GM_xmlhttpRequest = GM_xmlhttpRequest;
COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
Utils.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);

View File

@ -1,7 +1,7 @@
import popupMsg from "../utils/popupMsg";
import WHNotify from "../utils/WHNotify";
import log from "../utils/log";
import Utils from "../../class/Utils";
import Utils from "../../class/utils/Utils";
// 守望者
export default function safeKeeper() {

View File

@ -7,7 +7,6 @@ import addActionBtn from "../utils/addActionBtn";
import addStyle from "../utils/addStyle";
import log from "../utils/log";
import doQuickFly from "./doQuickFly";
import WuHuTornHelper from "../../class/WuhuTornHelper";
import ZhongIcon from "../../class/ZhongIcon";
import WuhuBase from "../../class/WuhuBase";
@ -27,9 +26,11 @@ export default async function travelHelper(): Promise<null> {
if (country === 'torn') {
dest_cn = '回城';
} else {
dest_cn = {'uk': "英国", 'switzerland': "瑞士", 'mexico': '墨西哥', 'canada': '加拿大', 'cayman': '开曼',
'hawaii': '夏威夷', 'argentina': '阿根廷',
'japan': '日本', 'china': '中国', 'uae': 'UAE', 'sa': '南非',}[country] || country;
dest_cn = {
'uk': "英国", 'switzerland': "瑞士", 'mexico': '墨西哥', 'canada': '加拿大', 'cayman': '开曼',
'hawaii': '夏威夷', 'argentina': '阿根廷',
'japan': '日本', 'china': '中国', 'uae': 'UAE', 'sa': '南非',
}[country] || country;
}
// 剩余时间

View File

@ -734,7 +734,7 @@ export default function translateMain(href: string): void {
$title.forEach(el => {
el.childNodes.forEach(e => {
if (e.nodeType === 1) {
let node = e as HTMLElement;
let node = e as HTMLElement;
if (npcShopDict[node.innerText.trim()]) {
node.innerText = npcShopDict[node.innerText.trim()];
return;

View File

@ -0,0 +1,9 @@
// import Device from "../../enum/Device";
//
// /**
// * @deprecated
// */
// export default function getDeviceType() {
// return window.innerWidth >= 1000
// ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
// }

View File

@ -0,0 +1,12 @@
// /**
// * 返回玩家信息的对象 user
// * @deprecated
// * @return {PlayerInfo} rs
// */
// export default function getPlayerInfo(): PlayerInfo {
// const node = document.querySelector('script[uid]');
// if (node) return {
// playername: node.getAttribute('name'),
// userID: node.getAttribute('uid') as unknown as number,
// }
// }

View File

@ -0,0 +1,9 @@
// /**
// * @deprecated
// */
// export default function getRandomInt(min: number, max: number): number {
// min = Math.ceil(min);
// max = Math.floor(max);
// //不含最大值,含最小值
// return Math.floor(Math.random() * (max - min)) + min;
// }

View File

@ -1,10 +1,9 @@
import getWhSettingObj from "./getWhSettingObj";
import log from "./log";
import WHNotify from "./WHNotify";
import getRandomInt from "./getRandomInt";
import setWhSetting from "./setWhSetting";
import audioPlay from "./audioPlay";
import Utils from "../../class/Utils";
import Utils from "../../class/utils/Utils";
// 啤酒
export default function BuyBeer() {
@ -74,12 +73,12 @@ export default function BuyBeer() {
loop.status = () => started ? '已启动' : '未启动';
loop.is_running = () => !!started;
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-${ 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>`
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-${ Utils.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();
setWhSetting('_15_alarm_ignore', [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()], false);
// 通知
const notify = WHNotify(`明早8点前将不再提醒 <button id="wh-rd-btn-${ getRandomInt(0, 100) }">取消</button>`);
const notify = WHNotify(`明早8点前将不再提醒 <button id="wh-rd-btn-${ Utils.getRandomInt(0, 100) }">取消</button>`);
// 通知中的取消按钮
notify.querySelector('.wh-notify-msg button').addEventListener('click', () => setWhSetting('_15_alarm_ignore', undefined));
};

View File

@ -2,7 +2,9 @@ import UserScriptEngine from "../../enum/UserScriptEngine";
import getScriptEngine from "./getScriptEngine";
import log from "./log";
// 跨域get请求 返回text
/**
* @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();

View File

@ -1,6 +1,6 @@
import getRandomInt from "./getRandomInt";
import addStyle from "./addStyle";
import WuhuBase from "../../class/WuhuBase";
import Utils from "../../class/utils/Utils";
/**
*
@ -28,7 +28,7 @@ export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTML
if (!isWindowActive() || (self !== top)) return null;
const date = new Date();
// 通知的唯一id
const uid = `${ date.getHours() }${ date.getSeconds() }${ date.getMilliseconds() }${ getRandomInt(1000, 9999) }`;
const uid = `${ date.getHours() }${ date.getSeconds() }${ date.getMilliseconds() }${ Utils.getRandomInt(1000, 9999) }`;
// 通知容器id
const node_id = 'wh-notify';
// 通知的容器
@ -129,7 +129,7 @@ cursor: pointer;
body: date_local_string + notify_contain.msgInnerText,
requireInteraction: true,
renotify: true,
tag: sysNotifyTag + getRandomInt(0, 99),
tag: sysNotifyTag + Utils.getRandomInt(0, 99),
});
notify_obj.sys_notify.addEventListener('close', () => sysNotifyClick());
notify_obj.sys_notify.onshow = () => setTimeout(() => notify_obj.sys_notify.close(), timeout * 1000);

View File

@ -1,4 +1,4 @@
import log from "./log";
import Log from "../../class/Log";
// 菜单 附加按钮
export default function addActionBtn(txt: string, func: (ev: Event) => void, mainBtnNode: Element): void {
@ -15,6 +15,6 @@ addActionBtn.proxy = (txt: string, func: (ev: Event) => void, mainBtnNode: Eleme
btn.addEventListener('click', func);
mainBtnNode.querySelector('button').after(btn);
addActionBtn.proxy = () => {
log.error('错误:附加按钮已存在')
Log.error('错误:附加按钮已存在')
};
}

View File

@ -1,11 +1,5 @@
/**
* fetch ajax包装
* @param {Object} opt
* @param {String} opt.url
* @param {String} opt.referrer
* @param {String} opt.method
* @param {String} [opt.body]
* @returns {Promise<Response>}
* @deprecated
*/
export default function ajaxFetch(opt) {
let { url, referrer, method, body = null } = opt;

View File

@ -1,4 +1,4 @@
import Utils from "../../class/Utils";
import Utils from "../../class/utils/Utils";
import WuhuBase from "../../class/WuhuBase";
/**

View File

@ -2,7 +2,6 @@ import UserScriptEngine from "../../enum/UserScriptEngine";
import getScriptEngine from "./getScriptEngine";
import popupMsg from "./popupMsg";
import loading_gif_html from "./loading_gif_html";
import WuHuTornHelper from "../../class/WuhuTornHelper";
import WuhuBase from "../../class/WuhuBase";
// 海外库存

View File

@ -1,9 +0,0 @@
import Device from "../../enum/Device";
/**
* @deprecated
*/
export default function getDeviceType() {
return window.innerWidth >= 1000
? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
}

View File

@ -1,12 +0,0 @@
/**
* user
* @deprecated
* @return {PlayerInfo} rs
*/
export default function getPlayerInfo(): PlayerInfo {
const node = document.querySelector('script[uid]');
if (node) return {
playername: node.getAttribute('name'),
userID: node.getAttribute('uid') as unknown as number,
}
}

View File

@ -1,11 +0,0 @@
/**
* @deprecated
* @param min
* @param max
*/
export default function getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
//不含最大值,含最小值
return Math.floor(Math.random() * (max - min)) + min;
}

View File

@ -1,5 +1,5 @@
// 引入torn miniprofile
function initMiniProf(selector) {
export default function initMiniProf(selector) {
let profileMini = {
timeout: 0,
clickable: false,

View File

@ -1,4 +1,3 @@
import WuHuTornHelper from "../../class/WuhuTornHelper";
import WuhuBase from "../../class/WuhuBase";
/**

View File

@ -1,7 +1,9 @@
import getWhSettingObj from "./getWhSettingObj";
import WHNotify from "./WHNotify";
// 插件的配置 setter
/**
* @deprecated
*/
export default function setWhSetting(key: string, value: any, notify: boolean = true) {
const obj = getWhSettingObj()
obj[key] = value

View File

@ -0,0 +1,7 @@
export default interface AjaxFetchOption {
url: string,
headers?: { 'X-Requested-With'?: string, 'Content-Type'?: string };
referrer?: string;
method?: string;
body?: any;
}

View File

@ -60,7 +60,7 @@ interface Bar {
interface HeaderData {
"user": {
"state": {
"status": "ok"|string,
"status": "ok" | string,
"isLoggedIn": boolean,
"isDonator": boolean,
"isTravelling": boolean,

View File

@ -1,30 +1,30 @@
import getWhSettingObj from "./func/utils/getWhSettingObj";
import translateMain from "./func/translate/translateMain";
import { Common } from "./common";
import WuHuTornHelper from "./class/WuhuTornHelper";
import ZhongIcon from "./class/ZhongIcon";
import WuhuBase from "./class/WuhuBase";
import UrlPattern from "./urlMatch";
import WuhuConfig from "./class/WuhuConfig";
(function main() {
let started = new Date().getTime();
// let started = new Date().getTime();
let started = performance.now();
if (document.title.toLowerCase().includes('just a moment') ||
document.querySelector('#skip-to-content').innerText.toLowerCase().includes('please validate')
) return;
WuhuBase.conditionInterrupt();
let app = new WuHuTornHelper();
app.init();
let glob = WuhuBase.glob;
ZhongIcon.initialize();
if (getWhSettingObj()['transEnable']) translateMain(glob.href);
Common.resolve();
UrlPattern.resolve();
let runTime = new Date().getTime() - started;
if (WuhuConfig.get('transEnable')) translateMain(glob.href);
// let runTime = new Date().getTime() - started;
let runTime = (performance.now() - started) | 0;
ZhongIcon.ZhongNode.initTimer.innerHTML = `助手加载时间 ${ runTime }ms`;
})
();

View File

@ -6,11 +6,9 @@ import setWhSetting from "./func/utils/setWhSetting";
import { missionDict } from "./dictionary/translation";
import getTaskHint from "./func/translate/getTaskHint";
import Device from "./enum/Device";
import getSidebarData from "./func/utils/getSidebarData";
import getDeviceType from "./func/utils/getDeviceType";
import addStyle from "./func/utils/addStyle";
import WuhuBase from "./class/WuhuBase";
import Utils from "./class/Utils";
import Utils from "./class/utils/Utils";
import Log from "./class/Log";
export default class UrlPattern extends WuhuBase {
@ -928,8 +926,8 @@ margin: 0 0 3px;
}
// 特定代码块
if (Utils.getPlayerInfo()['userID'] === 2687093 && getDeviceType() === Device.PC) {
getSidebarData().then(() => {
if (Utils.getPlayerInfo()['userID'] === 2687093 && Utils.getDeviceType() === Device.PC) {
Utils.getSidebarData().then(() => {
let item = document.getElementById('nav-items');
if (item) {
let copy = item.cloneNode(true);