diff --git a/global.d.ts b/global.d.ts index c9d69dd..fdcab28 100644 --- a/global.d.ts +++ b/global.d.ts @@ -43,9 +43,12 @@ declare interface Window { GM_xmlhttpRequest(init: GM_RequestParams); - GM_getValue(k: string, def: any): any; + GM_getValue(k: string, def: any): unknown; GM_setValue(k: string, v: any): void; + + // TODO 临时测试用 + [key: string]: unknown; } declare interface GM_RequestParams { diff --git a/src/class/Global.ts b/src/class/Global.ts index 8406599..958ab22 100644 --- a/src/class/Global.ts +++ b/src/class/Global.ts @@ -66,7 +66,22 @@ export default class Global extends WuhuBase implements IGlobal { if (this.unsafeWindow) { try { - window = this.unsafeWindow; + window.whtest = '原window'; + this.unsafeWindow.whtest = 'unsafeWindow'; + window = this.unsafeWindow || this.window; + Log.info('替换window上下文'); + Log.info({ + setInterval, clearInterval, + 'window.setInterval': window.setInterval, + 'window.clearInterval': window.clearInterval, + 'this.unsafeWindow.setInterval': this.unsafeWindow.setInterval, + 'this.unsafeWindow.clearInterval': this.unsafeWindow.clearInterval, + 'this.window.setInterval': this.window.setInterval, + 'this.window.clearInterval': this.window.clearInterval, + }) + // Log.info(window.whtest) + // Log.info(this.unsafeWindow.whtest) + // Log.info(this.window.whtest) } catch { this.unsafeWindow = null; this.GM_xmlhttpRequest = null; diff --git a/src/class/Log.ts b/src/class/Log.ts index 371bd60..541ab92 100644 --- a/src/class/Log.ts +++ b/src/class/Log.ts @@ -1,6 +1,8 @@ -export default class Log{ - static info(this, ...o) { - (this.debug()) && (console.log('[WH]', this.getTime(), ...o)) +export default class Log { + static info(...o) { + if (this.debug()) { + console.log('[WH]', this.getTime(), ...o) + } } static error(...o) { @@ -30,7 +32,4 @@ export default class Log{ let ms = ('00' + d.getMilliseconds()).slice(-3); return `[${ year }-${ month }-${ date } ${ hours }:${ minutes }:${ seconds }.${ ms }]`; } - - private constructor() { - } } \ No newline at end of file diff --git a/src/class/ZhongIcon.ts b/src/class/ZhongIcon.ts index 58504e0..160d0c9 100644 --- a/src/class/ZhongIcon.ts +++ b/src/class/ZhongIcon.ts @@ -16,6 +16,7 @@ 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; @@ -967,8 +968,7 @@ color:black; // Log.info(await Utils.getSidebarData()) // Log.info(await Utils.getUserState()) - Log.info(ZhongIcon.getGlob()); - Log.info(ZhongIcon.glob); + new Alert('123', { sysNotify: true }); Log.info('测试结束'); }, diff --git a/src/class/utils/Alert.ts b/src/class/utils/Alert.ts index 82449de..d4df0bd 100644 --- a/src/class/utils/Alert.ts +++ b/src/class/utils/Alert.ts @@ -1,13 +1,15 @@ import Utils from "./Utils"; import addStyle from "../../func/utils/addStyle"; +import Log from "../Log"; +import IWHNotify from "../../interface/IWHNotify"; +import NotificationUtils from "./NotificationUtils"; export default class Alert extends Utils { - // static hasContainer: boolean = false; static container: HTMLElement = null; notify: MyHTMLElement = null; intervalID = -1; - constructor(msg: string, options: WHNotifyOpt = {}) { + constructor(msg: string, options: IWHNotify = {}) { super(); let { isWindowActive, notifies } = Alert.glob; @@ -24,14 +26,15 @@ export default class Alert extends Utils { if (!Alert.glob.isWindowActive.get() || (self !== top)) return null; // 通知的容器 - if (!Alert.container) Alert.initContainer(); - this.notify = Alert.create(msg, timeout); - this.intervalID = this.notify.loopId; + if (Alert.container === null) Alert.initContainer(); + this.callback = callback; + Alert.create(this, msg, timeout); + Log.info('创建新通知:', this); + NotificationUtils.push(msg, options); } - static create(msg, timeout) { - const date = new Date(); + static create(that: Alert, msg, timeout): void { // 通知的唯一id const uid = '' + Utils.getRandomInt(1000, 9999); // 每条通知 @@ -44,6 +47,7 @@ export default class Alert extends Utils {
${ msg }