diff --git a/CHANGELOG.md b/CHANGELOG.md index ebcfea3c..0c3501b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +## 3.7.3 + +- 新增:直播页 隐藏倒计时互动 +- 新增:直播页 隐藏发送框粉丝勋章 +- 新增:播放页/番剧页 小窗播放器记忆移动位置 +- 优化:直播页 隐藏互动功能改为默认开启 +- 优化:直播页 隐藏发送框相关功能样式 +- 优化:代码typo更正 + ## 3.7.2 - 新增:直播页 活动直播页自动跳转普通直播 diff --git a/src/components/group.ts b/src/components/group.ts index e8b01862..0c63b7ea 100644 --- a/src/components/group.ts +++ b/src/components/group.ts @@ -67,20 +67,6 @@ export class Group { error(err) } } - /** 在URL变动时, 重载group内需要重载的项目 */ - reloadGroup() { - try { - this.items.forEach((e) => { - if (e instanceof CheckboxItem || e instanceof RadioItem || e instanceof NumberItem) { - e.reloadItem() - } - }) - debug(`reloadGroup ${this.groupID} OK`) - } catch (err) { - error(`reloadGroup ${this.groupID} err`) - error(err) - } - } /** 禁用Group, 临时使用, 移除全部CSS, 监听函数保持不变 */ disableGroup() { try { diff --git a/src/components/item.ts b/src/components/item.ts index c80b507f..33c1ab13 100644 --- a/src/components/item.ts +++ b/src/components/item.ts @@ -9,7 +9,6 @@ interface IItem { removeItemCSS?(): void watchItem?(): void enableItem?(): void - reloadItem?(): void } /** @@ -17,7 +16,6 @@ interface IItem { * description item的功能介绍, 显示在panel内, \n可用来换行 * defaultStatus item默认开启状态, 第一次安装时使用, 对于所有用户均开启的项目给true * itemFunc 功能函数 - * isItemFuncReload 功能函数是否在URL变动时重新运行 * itemCSS item的CSS * callback 回调函数, 用于在关掉开关时触发外部事务 */ @@ -25,10 +23,11 @@ interface ICheckboxItemOption { itemID: string description: string defaultStatus?: boolean - itemFunc?: () => void - isItemFuncReload?: boolean + enableFunc?: () => Promise + // 分别对应:立即执行,DOMContentLoaded, load + enableFuncRunAt?: 'document-start' | 'document-end' | 'document-idle' + disableFunc?: () => Promise itemCSS?: string - callback?: () => void } /** 普通开关 */ @@ -117,7 +116,7 @@ export class CheckboxItem implements IItem { } } } - /** 监听item chekbox开关 */ + /** 监听item checkbox开关 */ watchItem() { try { this.itemEle = document.querySelector(`#${this.option.itemID} input`) as HTMLInputElement @@ -126,16 +125,11 @@ export class CheckboxItem implements IItem { if ((event.target).checked) { this.setStatus(true) this.insertItemCSS() - if (this.option.itemFunc !== undefined) { - this.option.itemFunc() - } + this.option.enableFunc && this.option.enableFunc().then().catch() } else { this.setStatus(false) this.removeItemCSS() - // 回调 - if (typeof this.option.callback === 'function') { - this.option.callback() - } + this.option.disableFunc && this.option.disableFunc().then().catch() } }) debug(`watchItem ${this.option.itemID} OK`) @@ -153,8 +147,28 @@ export class CheckboxItem implements IItem { if (this.isEnable) { try { this.insertItemCSS() - if (enableFunc && this.option.itemFunc instanceof Function) { - this.option.itemFunc() + if (enableFunc && this.option.enableFunc) { + switch (this.option.enableFuncRunAt) { + case 'document-start': + this.option.enableFunc().then().catch() + break + case 'document-end': + if (['complete', 'interactive'].includes(document.readyState)) { + this.option.enableFunc().then().catch() + } else { + document.addEventListener('DOMContentLoaded', this.option.enableFunc) + } + break + case 'document-idle': + if (document.readyState === 'complete') { + this.option.enableFunc().then().catch() + } else { + document.addEventListener('load', this.option.enableFunc) + } + break + default: + this.option.enableFunc().then().catch() + } } debug(`enableItem ${this.option.itemID} OK`) } catch (err) { @@ -163,21 +177,6 @@ export class CheckboxItem implements IItem { } } } - /** - * 重载item, 用于非页面刷新但URL变动情况, 此时已注入CSS只重新运行func, 如: 非刷新式切换视频 - */ - reloadItem() { - // this.getStatus() - if (this.option.isItemFuncReload && this.isEnable && this.option.itemFunc instanceof Function) { - try { - this.option.itemFunc() - debug(`reloadItem ${this.option.itemID} OK`) - } catch (err) { - error(`reloadItem ${this.option.itemID} Error`) - error(err) - } - } - } } /** @@ -187,7 +186,6 @@ export class CheckboxItem implements IItem { * radioItemIDList 当前item所在互斥组的ID列表, 用于修改其他item状态 * defaultStatus item默认开启状态, 第一次安装时使用, 对于所有用户均开启的项目默认给true * itemFunc 功能函数 - * isItemFuncReload 功能函数是否在URL变动时重新运行 * itemCSS item的CSS */ interface IRadioItemOption { @@ -196,8 +194,7 @@ interface IRadioItemOption { radioName: string radioItemIDList: string[] defaultStatus?: boolean - itemFunc?: () => void - isItemFuncReload?: boolean + itemFunc?: () => Promise itemCSS?: string } @@ -302,9 +299,7 @@ export class RadioItem implements IItem { debug(`radioItem ${this.option.itemID} checked`) this.setStatus(true) this.insertItemCSS() - if (this.option.itemFunc !== undefined) { - this.option.itemFunc() - } + this.option.itemFunc && this.option.itemFunc().then().catch() // 相同name的其他option自动置为uncheck, 但这一行为无法被监听, 需传入itemID逐一修改 this.option.radioItemIDList.forEach((targetID) => { if (targetID !== this.option.itemID) { @@ -337,8 +332,8 @@ export class RadioItem implements IItem { if (this.isEnable) { try { this.insertItemCSS() - if (enableFunc && this.option.itemFunc instanceof Function) { - this.option.itemFunc() + if (enableFunc && this.option.itemFunc) { + this.option.itemFunc().then().catch() } debug(`enableItem ${this.option.itemID} OK`) } catch (err) { @@ -347,22 +342,6 @@ export class RadioItem implements IItem { } } } - /** - * 重载item, 用于非页面刷新但URL变动情况, 此时已注入CSS只重新运行func, 如: 非刷新式切换视频 - */ - reloadItem() { - // 存在其他item修改当前item状态的情况 - this.getStatus() - if (this.option.isItemFuncReload && this.isEnable && this.option.itemFunc instanceof Function) { - try { - this.option.itemFunc() - debug(`reloadItem ${this.option.itemID} OK`) - } catch (err) { - error(`reloadItem ${this.option.itemID} Error`) - error(err) - } - } - } } /** @@ -388,7 +367,7 @@ interface INumberItemOption { itemCSS?: string // CSS中待替换为数值的占位符 itemCSSPlaceholder?: string - callback?: (value: number) => void + callback?: (value: number) => Promise } /** 数值设定 */ @@ -502,10 +481,7 @@ export class NumberItem implements IItem { debug(`${this.option.itemID} currValue ${itemEle.value}`) // reload this.reloadItem() - // 调用回调函数 - if (this.option.callback && typeof this.option.callback === 'function') { - this.option.callback(parseInt(itemEle.value)) - } + this.option.callback && this.option.callback(parseInt(itemEle.value)).then().catch() }) debug(`watchItem ${this.option.itemID} OK`) } catch (err) { @@ -553,7 +529,7 @@ interface IButtonItemOption { itemID: string description: string name: string - itemFunc: () => void + itemFunc: () => Promise } /** 普通按钮 */ @@ -588,7 +564,7 @@ export class ButtonItem implements IItem { const itemEle = document.querySelector(`#${this.option.itemID} button`) as HTMLButtonElement itemEle.addEventListener('click', () => { debug(`button ${this.option.itemID} click`) - this.option.itemFunc() + this.option.itemFunc().then().catch() }) debug(`watchItem ${this.option.itemID} OK`) } catch (err) { diff --git a/src/components/panel.ts b/src/components/panel.ts index 0903c542..34f8794f 100644 --- a/src/components/panel.ts +++ b/src/components/panel.ts @@ -9,7 +9,7 @@ export class Panel { bilibili 页面净化大师
- +
diff --git a/src/components/wordlist.ts b/src/components/wordlist.ts index 47ca3fff..07ec6694 100644 --- a/src/components/wordlist.ts +++ b/src/components/wordlist.ts @@ -9,7 +9,7 @@ export class WordList {
- +