diff --git a/src/class/Global.ts b/src/class/Global.ts index 2c9827a..8406599 100644 --- a/src/class/Global.ts +++ b/src/class/Global.ts @@ -1,6 +1,6 @@ import BuyBeer, { BeerMonitorLoop } from "../func/utils/BuyBeer"; import Device from "../enum/Device"; -import WindowActiveState from "../func/utils/WindowActiveState"; +import WindowActiveState from "./action/WindowActiveState"; import WuhuBase from "./WuhuBase"; import IGlobal from "../interface/IGlobal"; import Utils from "./utils/Utils"; @@ -43,10 +43,11 @@ export default class Global extends WuhuBase implements IGlobal { } = null; // 窗口活动状态 - isWindowActive = null; + // isWindowActive = null; + isWindowActive = WindowActiveState.getInstance(); private constructor() { - Log.info('Global初始化'); + Log.info('WH脚本参数初始化'); super(); this.window = window; this.unsafeWindow = window.unsafeWindow || null; @@ -59,7 +60,7 @@ export default class Global extends WuhuBase implements IGlobal { this.beer = BuyBeer(); this.popup_node = null; this.notifies = { count: 0 }; - this.isWindowActive = WindowActiveState(); + // this.isWindowActive = WindowActiveState.getInstance(); this.href = window.location.href; this.bodyAttrs = {}; @@ -71,8 +72,6 @@ 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); @@ -91,13 +90,13 @@ export default class Global extends WuhuBase implements IGlobal { } ); - Log.info('Global初始化结束'); + Log.info('WH脚本参数初始化结束'); } static getInstance(this): Global { - if (!(this).instance) { - (this).instance = new this(); + if (!this.instance) { + this.instance = new this(); } - return (this).instance; + return this.instance; } } \ No newline at end of file diff --git a/src/class/WuhuBase.ts b/src/class/WuhuBase.ts index d7f0809..a3a629c 100644 --- a/src/class/WuhuBase.ts +++ b/src/class/WuhuBase.ts @@ -6,18 +6,25 @@ export default class WuhuBase { static glob: IGlobal = null; static getLocal(): IWHSettings { - return JSON.parse(localStorage.getItem('wh_trans_settings')); + return JSON.parse(localStorage.getItem('wh_trans_settings')) || {}; } static conditionInterrupt() { - if ( + 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') || - document.querySelector('#skip-to-content').innerText.toLowerCase().includes('please validate') - ) - throw '芜湖'; + title.innerText.toLowerCase().includes('please validate') || + document.querySelector('div.container div.cf .iAmUnderAttack') !== null + ); + if (condition) throw '芜湖'; } constructor() { Log.info('创建对象:' + this.constructor.name) } + + static getGlob(): IGlobal { + return this.glob + } } \ No newline at end of file diff --git a/src/class/WuhuTornHelper.ts b/src/class/WuhuTornHelper.ts index e351d13..3afdc47 100644 --- a/src/class/WuhuTornHelper.ts +++ b/src/class/WuhuTornHelper.ts @@ -3,7 +3,7 @@ import miniprofTrans from "../func/translate/miniprofTrans"; import addStyle from "../func/utils/addStyle"; import Utils from "./utils/Utils"; import WuhuBase from "./WuhuBase"; -import TravelItem from "./TravelItemFetchLoop"; +import TravelItem from "./action/TravelItem"; import Global from "./Global"; import Log from "./Log"; @@ -13,7 +13,7 @@ export default class WuHuTornHelper extends WuhuBase { Log.info('WuHuTornHelper初始化'); WuhuBase.glob = Global.getInstance(); let glob = WuhuBase.glob; - glob.fStock = new TravelItem('https://yata.yt/api/v1/travel/export/'); + glob.fStock = TravelItem.getInstance(); Log.info(glob.fStock) // 请求通知权限 diff --git a/src/class/ZhongIcon.ts b/src/class/ZhongIcon.ts index 15d1b3d..58504e0 100644 --- a/src/class/ZhongIcon.ts +++ b/src/class/ZhongIcon.ts @@ -16,7 +16,6 @@ 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; @@ -968,7 +967,8 @@ color:black; // Log.info(await Utils.getSidebarData()) // Log.info(await Utils.getUserState()) - new Alert("123"); + Log.info(ZhongIcon.getGlob()); + Log.info(ZhongIcon.glob); Log.info('测试结束'); }, diff --git a/src/class/TravelItemFetchLoop.ts b/src/class/action/TravelItem.ts similarity index 50% rename from src/class/TravelItemFetchLoop.ts rename to src/class/action/TravelItem.ts index bf01a3f..385e399 100644 --- a/src/class/TravelItemFetchLoop.ts +++ b/src/class/action/TravelItem.ts @@ -1,15 +1,15 @@ -import Utils from "./utils/Utils"; -import WuhuBase from "./WuhuBase"; +import Utils from "../utils/Utils"; +import WuhuBaseAction from "./WuhuBaseAction"; -export default class TravelItem extends WuhuBase { +export default class TravelItem extends WuhuBaseAction { obj: any = null; res: any = null; - constructor(destination: string) { + private constructor() { super(); setInterval(async () => { - if (!WuhuBase.glob.isWindowActive()) return; - const res = await Utils.COFetch(destination); + if (!TravelItem.glob.isWindowActive.get()) return; + const res = await Utils.COFetch('https://yata.yt/api/v1/travel/export/'); this.obj = JSON.parse(res); }, 30 * 1000); } diff --git a/src/class/action/WindowActiveState.ts b/src/class/action/WindowActiveState.ts new file mode 100644 index 0000000..88666cb --- /dev/null +++ b/src/class/action/WindowActiveState.ts @@ -0,0 +1,47 @@ +import uuidv4 from "../../func/utils/uuidv4"; +import WuhuBaseAction from "./WuhuBaseAction"; + +export default class WindowActiveState extends WuhuBaseAction { + isFocus = false; + uuid = uuidv4(); + + private constructor() { + super(); + if (self !== top) return null; + localStorage.setItem('whuuid', this.uuid); + document.addEventListener('visibilitychange', + () => (document.visibilityState !== 'hidden') && (localStorage.setItem('whuuid', this.uuid)) + ); + addEventListener('focus', () => this.isFocus = true); + addEventListener('blur', () => this.isFocus = false); + } + + get(): boolean { + // 当前窗口获得了焦点 优先级最高 + if (this.isFocus) return true; + // 可视性 + if (!document.hidden) return true; + // 全部在后台,使用唯一id判断 + return this.uuid === localStorage.getItem('whuuid') + } +} + +// export default function WindowActiveState() { +// if (self !== top) return null; +// const uuid = uuidv4(); +// let isFocus = false; +// localStorage.setItem('whuuid', uuid); +// document.addEventListener('visibilitychange', () => +// (document.visibilityState !== 'hidden') && (localStorage.setItem('whuuid', uuid)) +// ); +// addEventListener('focus', () => isFocus = true) +// addEventListener('blur', () => isFocus = false) +// return function (): boolean { +// // 当前窗口获得了焦点 优先级最高 +// if (isFocus) return true; +// // 可视性 +// if (!document.hidden) return true; +// // 全部在后台,使用唯一id判断 +// return uuid === localStorage.getItem('whuuid') +// }; +// } \ No newline at end of file diff --git a/src/class/action/WuhuBaseAction.ts b/src/class/action/WuhuBaseAction.ts index 40c1997..6417687 100644 --- a/src/class/action/WuhuBaseAction.ts +++ b/src/class/action/WuhuBaseAction.ts @@ -1,3 +1,15 @@ import WuhuBase from "../WuhuBase"; -export default class WuhuBaseAction extends WuhuBase {} \ No newline at end of file +export default class WuhuBaseAction extends WuhuBase { + name: string + + protected constructor() { + super(); + } + + static getInstance(this) { + if (!this.instance) + this.instance = new this(); + return this.instance; + } +} \ No newline at end of file diff --git a/src/class/utils/Alert.ts b/src/class/utils/Alert.ts index 4dd1b87..cd1f190 100644 --- a/src/class/utils/Alert.ts +++ b/src/class/utils/Alert.ts @@ -1,12 +1,15 @@ -import WuhuBase from "../WuhuBase"; -import Log from "../Log"; +import Utils from "./Utils"; +import addStyle from "../../func/utils/addStyle"; -export default class Alert extends WuhuBase{ +export default class Alert extends Utils { static hasContainer: boolean = false; + static container: HTMLElement = null; + notify: HTMLElement = null; + callback: Function = null; constructor(msg: string, options: WHNotifyOpt = {}) { super(); - let { isWindowActive, notifies } = WuhuBase.glob; + let { isWindowActive, notifies } = Alert.glob; let { timeout = 3, @@ -17,7 +20,109 @@ export default class Alert extends WuhuBase{ sysNotifyClick = () => window.focus() } = options; - if (!isWindowActive() || (self !== top)) return null; + // 后台窗口、iframe内判断 + if (!Alert.glob.isWindowActive.get() || (self !== top)) return null; + + // 通知的容器 + if (!Alert.container) Alert.initContainer(); + this.notify = Alert.create(msg); + this.callback = callback; + } + + static create(msg) { + const date = new Date(); + // 通知的唯一id + const uid = '' + Utils.getRandomInt(1000, 9999); + // 每条通知 + const new_node: MyHTMLElement = document.createElement('div'); + new_node.id = `wh-notify-${ uid }`; + new_node.classList.add('wh-notify-item'); + new_node.innerHTML = `
+
+
+

${ msg }

+
`; + this.container.append(new_node); + this.container['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; + } + + static initContainer() { + this.container = document.createElement('div'); + this.container.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(this.container); + } + + close() { + this.notify.remove(); + this.notify = null; } } diff --git a/src/class/utils/Utils.ts b/src/class/utils/Utils.ts index 5b485d2..de9b1d9 100644 --- a/src/class/utils/Utils.ts +++ b/src/class/utils/Utils.ts @@ -176,4 +176,36 @@ export default class Utils extends WuhuBase { } return fetch(url, req_params); } + + /** + * 通过 mutation.observe 方法异步返回元素 + * @param {String} selector - CSS规则的HTML元素选择器 + * @param {Document} content - 上下文 + * @param {number} timeout - 超时毫秒数 + * @returns {Promise} + */ + static elementReady(selector: string, content: Document = document, timeout: number = 30000): Promise { + return new Promise((resolve, reject) => { + let el = content.querySelector(selector) as HTMLElement; + if (el) { + resolve(el); + return + } + let observer = new MutationObserver((_, observer) => { + content.querySelectorAll(selector).forEach((element) => { + observer.disconnect(); + resolve(element as HTMLElement); + }); + }); + setTimeout(() => { + observer.disconnect(); + reject(`等待元素超时! [${ selector }]\n${ content.documentElement.tagName }`); + }, timeout); + observer.observe(content.documentElement, { childList: true, subtree: true }); + }); + } + + static createSystemNotify(): Notification { + return null; + } } \ No newline at end of file diff --git a/src/common.ts b/src/common.ts index 842c4b5..52eccb5 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,22 +1,22 @@ -import getWhSettingObj from "./func/utils/getWhSettingObj"; import elementReady from "./func/utils/elementReady"; 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 "./class/WuhuBase"; +import WuhuConfig from "./class/WuhuConfig"; export class Common extends WuhuBase { static resolve() { - let glob = WuhuBase.glob; + let glob = Common.glob; // 价格监控 priceWatcherHandle(glob.isPDA, glob.PDA_APIKey); // 啤酒提醒 - if (getWhSettingObj()['_15Alarm']) glob.beer.start(); + if (WuhuConfig.get('_15Alarm')) glob.beer.start(); // 点击4条转跳对应的页面 - if (getWhSettingObj()['barsRedirect']) { + if (WuhuConfig.get('barsRedirect')) { const eb = document.getElementById('barEnergy') as HTMLAnchorElement; const nb = document.getElementById('barNerve') as HTMLAnchorElement; const hb = document.getElementById('barHappy') as HTMLAnchorElement; @@ -63,7 +63,7 @@ export class Common extends WuhuBase { * 清除多余的脚本 * TODO 无效、弃用 */ - if (getWhSettingObj()['removeScripts']) { + if (WuhuConfig.get('removeScripts')) { 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()); diff --git a/src/func/module/attackHelper.ts b/src/func/module/attackHelper.ts index 6f4b1e6..e6e2908 100644 --- a/src/func/module/attackHelper.ts +++ b/src/func/module/attackHelper.ts @@ -3,7 +3,7 @@ import elementReady from "../utils/elementReady"; import getWhSettingObj from "../utils/getWhSettingObj"; import addActionBtn from "../utils/addActionBtn"; import addStyle from "../utils/addStyle"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; import ZhongIcon from "../../class/ZhongIcon"; import WuhuBase from "../../class/WuhuBase"; import WuhuConfig from "../../class/WuhuConfig"; diff --git a/src/func/module/cityFinder.ts b/src/func/module/cityFinder.ts index 426bb59..31ad6d7 100644 --- a/src/func/module/cityFinder.ts +++ b/src/func/module/cityFinder.ts @@ -1,7 +1,7 @@ import elementReady from "../utils/elementReady"; import addStyle from "../utils/addStyle"; import toThousands from "../utils/toThousands"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; import Utils from "../../class/utils/Utils"; export default function cityFinder(): void { diff --git a/src/func/module/loadGS.ts b/src/func/module/loadGS.ts index e06caf6..c7d3ea2 100644 --- a/src/func/module/loadGS.ts +++ b/src/func/module/loadGS.ts @@ -1,7 +1,7 @@ import UserScriptEngine from "../../enum/UserScriptEngine"; import WHNotify from "../utils/WHNotify"; import addStyle from "../utils/addStyle"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; import Utils from "../../class/utils/Utils"; // gs loader diff --git a/src/func/module/priceWatcherHandle.ts b/src/func/module/priceWatcherHandle.ts index 5f7730c..6490f5e 100644 --- a/src/func/module/priceWatcherHandle.ts +++ b/src/func/module/priceWatcherHandle.ts @@ -1,5 +1,5 @@ import getWhSettingObj from "../utils/getWhSettingObj"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; import toThousands from "../utils/toThousands"; import WHNotify from "../utils/WHNotify"; diff --git a/src/func/module/safeKeeper.ts b/src/func/module/safeKeeper.ts index 284291d..1ac44c9 100644 --- a/src/func/module/safeKeeper.ts +++ b/src/func/module/safeKeeper.ts @@ -1,6 +1,6 @@ import popupMsg from "../utils/popupMsg"; import WHNotify from "../utils/WHNotify"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; import Utils from "../../class/utils/Utils"; // 守望者 diff --git a/src/func/module/travelHelper.ts b/src/func/module/travelHelper.ts index 1f86dec..137688e 100644 --- a/src/func/module/travelHelper.ts +++ b/src/func/module/travelHelper.ts @@ -5,7 +5,7 @@ import WHNotify from "../utils/WHNotify"; import getWhSettingObj from "../utils/getWhSettingObj"; import addActionBtn from "../utils/addActionBtn"; import addStyle from "../utils/addStyle"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; import doQuickFly from "./doQuickFly"; import ZhongIcon from "../../class/ZhongIcon"; import WuhuBase from "../../class/WuhuBase"; diff --git a/src/func/translate/eventsTrans.ts b/src/func/translate/eventsTrans.ts index 3529212..02a5a7c 100644 --- a/src/func/translate/eventsTrans.ts +++ b/src/func/translate/eventsTrans.ts @@ -1,5 +1,5 @@ import { eventsDict, gymList, ocList } from "../../dictionary/translation"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; export default function eventsTrans(events: JQuery = $('span.mail-link')) { const index = window.location.href.indexOf('events.php#/step=received') >= 0 ? 1 : 0; diff --git a/src/func/translate/initOB.ts b/src/func/translate/initOB.ts index 7d0a710..edf1e40 100644 --- a/src/func/translate/initOB.ts +++ b/src/func/translate/initOB.ts @@ -1,4 +1,4 @@ -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; /** * observe 包装 diff --git a/src/func/translate/translateMain.ts b/src/func/translate/translateMain.ts index 5adab58..be821b6 100644 --- a/src/func/translate/translateMain.ts +++ b/src/func/translate/translateMain.ts @@ -34,7 +34,7 @@ import initOB from "./initOB"; import titleTrans from "./titleTrans"; import contentTitleLinksTrans from "./contentTitleLinksTrans"; import showItemInfoTrans from "./showItemInfoTrans"; -import log from "../utils/log"; +import log from "../utils/@deprecated/log"; import contentTitleLinksTransReact from "./contentTitleLinksTransReact"; import titleTransReact from "./titleTransReact"; diff --git a/src/func/utils/log.ts b/src/func/utils/@deprecated/log.ts similarity index 65% rename from src/func/utils/log.ts rename to src/func/utils/@deprecated/log.ts index efb8283..17e1a1d 100644 --- a/src/func/utils/log.ts +++ b/src/func/utils/@deprecated/log.ts @@ -1,5 +1,8 @@ -import getWhSettingObj from "./getWhSettingObj"; +import getWhSettingObj from "../getWhSettingObj"; +/** + * @deprecated + */ function debug() { try { return getWhSettingObj()['isDev'] || false; @@ -13,9 +16,21 @@ function debug() { * @deprecated */ const log = { + /** + * @deprecated + */ error: (...o) => (debug()) && (console.error('[WH]', ...o)), + /** + * @deprecated + */ info: (...o) => (debug()) && (console.log('[WH]', ...o)), + /** + * @deprecated + */ debug, } +/** + * @deprecated + */ export default log \ No newline at end of file diff --git a/src/func/utils/BuyBeer.ts b/src/func/utils/BuyBeer.ts index d7c47e2..fbac994 100644 --- a/src/func/utils/BuyBeer.ts +++ b/src/func/utils/BuyBeer.ts @@ -1,5 +1,5 @@ import getWhSettingObj from "./getWhSettingObj"; -import log from "./log"; +import log from "./@deprecated/log"; import WHNotify from "./WHNotify"; import setWhSetting from "./setWhSetting"; import audioPlay from "./audioPlay"; diff --git a/src/func/utils/COFetch.ts b/src/func/utils/COFetch.ts index e976e5b..8b4b516 100644 --- a/src/func/utils/COFetch.ts +++ b/src/func/utils/COFetch.ts @@ -1,6 +1,6 @@ import UserScriptEngine from "../../enum/UserScriptEngine"; import getScriptEngine from "./getScriptEngine"; -import log from "./log"; +import log from "./@deprecated/log"; /** * @deprecated diff --git a/src/func/utils/WHNotify.ts b/src/func/utils/WHNotify.ts index 9e278c4..ec5305c 100644 --- a/src/func/utils/WHNotify.ts +++ b/src/func/utils/WHNotify.ts @@ -25,14 +25,13 @@ export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTML sysNotifyClick = () => window.focus() } = options; - if (!isWindowActive() || (self !== top)) return null; + if (!isWindowActive.get() || (self !== top)) return null; const date = new Date(); // 通知的唯一id const uid = `${ date.getHours() }${ date.getSeconds() }${ date.getMilliseconds() }${ Utils.getRandomInt(1000, 9999) }`; // 通知容器id - const node_id = 'wh-notify'; // 通知的容器 - let notify_contain: MyHTMLElement = document.querySelector(`#${ node_id }`); + let notify_contain: MyHTMLElement = document.querySelector(`#wh-notify`); // 添加通知到容器 const add_notify = () => { // 每条通知 @@ -77,9 +76,9 @@ export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTML // 不存在容器 创建 if (!notify_contain) { notify_contain = document.createElement('div'); - notify_contain.id = node_id; + notify_contain.id = 'wh-notify'; addStyle(` -#${ node_id } { +#wh-notify { display: inline-block; position: fixed; top: 0; @@ -88,25 +87,25 @@ export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTML z-index: 9999990; color:#333; } -#${ node_id } a{ +#wh-notify a{ color:red; text-decoration:none; } -#${ node_id } .wh-notify-item { +#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; } -#${ node_id } .wh-notify-item:hover { +#wh-notify .wh-notify-item:hover { background: rgb(239 249 255 / 98%); } -#${ node_id } .wh-notify-item .wh-notify-bar { +#wh-notify .wh-notify-item .wh-notify-bar { height:2px; background:#2196f3; } -#${ node_id } .wh-notify-item .wh-notify-close { +#wh-notify .wh-notify-item .wh-notify-close { float:right; padding:0; width:16px;height:16px; @@ -115,7 +114,7 @@ background-size:100%; margin: 6px 6px 0 0; cursor: pointer; } -#${ node_id } .wh-notify-item .wh-notify-msg { +#wh-notify .wh-notify-item .wh-notify-msg { padding:12px; } `); diff --git a/src/func/utils/WindowActiveState.ts b/src/func/utils/WindowActiveState.ts deleted file mode 100644 index 33a3980..0000000 --- a/src/func/utils/WindowActiveState.ts +++ /dev/null @@ -1,22 +0,0 @@ -// 返回一个可用查询当前窗口是否激活的函数 -import uuidv4 from "./uuidv4"; - -export default function WindowActiveState() { - if (self !== top) return null; - const uuid = uuidv4(); - let isFocus = false; - localStorage.setItem('whuuid', uuid); - document.addEventListener('visibilitychange', () => - (document.visibilityState !== 'hidden') && (localStorage.setItem('whuuid', uuid)) - ); - addEventListener('focus', () => isFocus = true) - addEventListener('blur', () => isFocus = false) - return function (): boolean { - // 当前窗口获得了焦点 优先级最高 - if (isFocus) return true; - // 可视性 - if (!document.hidden) return true; - // 全部在后台,使用唯一id判断 - return uuid === localStorage.getItem('whuuid') - }; -} \ No newline at end of file diff --git a/src/func/utils/addStyle.ts b/src/func/utils/addStyle.ts index e5aaac6..8e91004 100644 --- a/src/func/utils/addStyle.ts +++ b/src/func/utils/addStyle.ts @@ -1,4 +1,4 @@ -import log from "./log"; +import log from "./@deprecated/log"; /** * 添加全局style diff --git a/src/func/utils/audioPlay.ts b/src/func/utils/audioPlay.ts index 7c68b3c..020e0eb 100644 --- a/src/func/utils/audioPlay.ts +++ b/src/func/utils/audioPlay.ts @@ -1,4 +1,4 @@ -import log from "./log"; +import log from "./@deprecated/log"; /** * 播放音频 diff --git a/src/func/utils/autoFetchJSON.ts b/src/func/utils/autoFetchJSON.ts index eecacaf..222aee1 100644 --- a/src/func/utils/autoFetchJSON.ts +++ b/src/func/utils/autoFetchJSON.ts @@ -10,7 +10,7 @@ function autoFetchJSON(dest, time = 30) { let obj; const res = Utils.COFetch(dest); setInterval(async () => { - if (!WuhuBase.glob.isWindowActive()) return; + if (!WuhuBase.glob.isWindowActive.get()) return; const res = await Utils.COFetch(dest); obj = JSON.parse(res); }, time * 1000); @@ -23,6 +23,4 @@ function autoFetchJSON(dest, time = 30) { return obj; } }; -} - -export default autoFetchJSON \ No newline at end of file +} \ No newline at end of file diff --git a/src/func/utils/elementReady.ts b/src/func/utils/elementReady.ts index 677b5ba..05969c5 100644 --- a/src/func/utils/elementReady.ts +++ b/src/func/utils/elementReady.ts @@ -1,9 +1,5 @@ /** - * 通过 mutation.observe 方法异步返回元素 - * @param {String} selector - CSS规则的HTML元素选择器 - * @param {Document} content - 上下文 - * @param {number} timeout - 超时毫秒数 - * @returns {Promise} + * @deprecated */ export default function elementReady(selector, content = document, timeout: number = 30000): Promise { return new Promise((resolve, reject) => { diff --git a/src/func/utils/getSidebarData.ts b/src/func/utils/getSidebarData.ts index 0ea5b23..7cc2183 100644 --- a/src/func/utils/getSidebarData.ts +++ b/src/func/utils/getSidebarData.ts @@ -1,5 +1,5 @@ import elementReady from "./elementReady"; -import log from "./log"; +import log from "./@deprecated/log"; /** * 边栏信息 diff --git a/src/interface/IGlobal.ts b/src/interface/IGlobal.ts index 0fda5fb..8bfad61 100644 --- a/src/interface/IGlobal.ts +++ b/src/interface/IGlobal.ts @@ -45,5 +45,5 @@ export default interface IGlobal { }; // 窗口活动状态 - isWindowActive?(): boolean; + isWindowActive: { get: () => boolean }; } \ No newline at end of file