Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge dev to main, v3.7.3 #92

Merged
merged 8 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## 3.7.3

- 新增:直播页 隐藏倒计时互动
- 新增:直播页 隐藏发送框粉丝勋章
- 新增:播放页/番剧页 小窗播放器记忆移动位置
- 优化:直播页 隐藏互动功能改为默认开启
- 优化:直播页 隐藏发送框相关功能样式
- 优化:代码typo更正

## 3.7.2

- 新增:直播页 活动直播页自动跳转普通直播
Expand Down
14 changes: 0 additions & 14 deletions src/components/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
98 changes: 37 additions & 61 deletions src/components/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ interface IItem {
removeItemCSS?(): void
watchItem?(): void
enableItem?(): void
reloadItem?(): void
}

/**
* itemID item的唯一ID, 与GM database中的Key对应, 使用相同ID可共享item状态
* description item的功能介绍, 显示在panel内, \n可用来换行
* defaultStatus item默认开启状态, 第一次安装时使用, 对于所有用户均开启的项目给true
* itemFunc 功能函数
* isItemFuncReload 功能函数是否在URL变动时重新运行
* itemCSS item的CSS
* callback 回调函数, 用于在关掉开关时触发外部事务
*/
interface ICheckboxItemOption {
itemID: string
description: string
defaultStatus?: boolean
itemFunc?: () => void
isItemFuncReload?: boolean
enableFunc?: () => Promise<void>
// 分别对应:立即执行,DOMContentLoaded, load
enableFuncRunAt?: 'document-start' | 'document-end' | 'document-idle'
disableFunc?: () => Promise<void>
itemCSS?: string
callback?: () => void
}

/** 普通开关 */
Expand Down Expand Up @@ -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
Expand All @@ -126,16 +125,11 @@ export class CheckboxItem implements IItem {
if ((<HTMLInputElement>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`)
Expand All @@ -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) {
Expand All @@ -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)
}
}
}
}

/**
Expand All @@ -187,7 +186,6 @@ export class CheckboxItem implements IItem {
* radioItemIDList 当前item所在互斥组的ID列表, 用于修改其他item状态
* defaultStatus item默认开启状态, 第一次安装时使用, 对于所有用户均开启的项目默认给true
* itemFunc 功能函数
* isItemFuncReload 功能函数是否在URL变动时重新运行
* itemCSS item的CSS
*/
interface IRadioItemOption {
Expand All @@ -196,8 +194,7 @@ interface IRadioItemOption {
radioName: string
radioItemIDList: string[]
defaultStatus?: boolean
itemFunc?: () => void
isItemFuncReload?: boolean
itemFunc?: () => Promise<void>
itemCSS?: string
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
}

/**
Expand All @@ -388,7 +367,7 @@ interface INumberItemOption {
itemCSS?: string
// CSS中待替换为数值的占位符
itemCSSPlaceholder?: string
callback?: (value: number) => void
callback?: (value: number) => Promise<void>
}

/** 数值设定 */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -553,7 +529,7 @@ interface IButtonItemOption {
itemID: string
description: string
name: string
itemFunc: () => void
itemFunc: () => Promise<void>
}

/** 普通按钮 */
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Panel {
<span>bilibili 页面净化大师</span>
</div>
<div id="bili-cleaner-close">
<svg t="1699601981125" class="icon" viewBox="0 0 1026 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5964" width="20" height="20"><path d="M996.742543 154.815357L639.810328 511.747572l356.932215 356.932215a90.158906 90.158906 0 0 1-127.490994 127.490994L512.319334 639.195998l-356.932215 356.889647A90.158906 90.158906 0 1 1 27.896126 868.637219L384.82834 511.747572 27.896126 154.815357A90.158906 90.158906 0 1 1 155.387119 27.324364L512.319334 384.256578 869.251549 27.324364a90.158906 90.158906 0 1 1 127.490994 127.490993z" fill="#ffffff" p-id="5965"></path></svg>
<svg class="icon" viewBox="0 0 1026 1024" xmlns="http://www.w3.org/2000/svg" width="20" height="20"><path d="M996.742543 154.815357L639.810328 511.747572l356.932215 356.932215a90.158906 90.158906 0 0 1-127.490994 127.490994L512.319334 639.195998l-356.932215 356.889647A90.158906 90.158906 0 1 1 27.896126 868.637219L384.82834 511.747572 27.896126 154.815357A90.158906 90.158906 0 1 1 155.387119 27.324364L512.319334 384.256578 869.251549 27.324364a90.158906 90.158906 0 1 1 127.490994 127.490993z" fill="#ffffff"></path></svg>
</div>
</div>
<div id="bili-cleaner-group-list">
Expand Down
38 changes: 19 additions & 19 deletions src/components/wordlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class WordList {
<div id="bili-cleaner-wordlist">
<div class="wordlist-header"></div>
<div class="wordlist-description"></div>
<textarea class="wordlist-body" spellcheck="false" autocapitalize="off" autocomplete="off" autocorrect="off"></textarea>
<textarea class="wordlist-body" spellcheck="false" autocapitalize="off" autocomplete="off"></textarea>
<div class="wordlist-footer">
<button class="wordlist-save-button">保存</button>
<button class="wordlist-close-button">关闭</button>
Expand Down Expand Up @@ -60,24 +60,24 @@ export class WordList {
}
}

/** 添加多个值到列表 */
addValues(values: string[]) {
try {
this.getValue()
values.forEach((value) => {
value = value.trim()
if (value && !this.wordSet.has(value)) {
this.wordArr.push(value)
this.wordSet.add(value)
}
})
this.setValue()
debug(`list ${this.listID} add ${values.length} lines, OK`)
} catch (err) {
error(err)
error(`list ${this.listID} add ${values.length} lines, ERROR`)
}
}
// /** 添加多个值到列表 */
// addValues(values: string[]) {
// try {
// this.getValue()
// values.forEach((value) => {
// value = value.trim()
// if (value && !this.wordSet.has(value)) {
// this.wordArr.push(value)
// this.wordSet.add(value)
// }
// })
// this.setValue()
// debug(`list ${this.listID} add ${values.length} lines, OK`)
// } catch (err) {
// error(err)
// error(`list ${this.listID} add ${values.length} lines, ERROR`)
// }
// }

/**
* 编辑整个列表
Expand Down
Loading