Skip to content

Commit

Permalink
fix: contextmenu bug, update playlist support
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Mar 27, 2024
1 parent e2f1309 commit 600a992
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 73 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- 新增:播放页隐藏接下来播放
- 更新:净化分享适配新版标题
- 优化:一些页面净化功能细节
- 优化:对播放列表页的支持
- 修复:一些bug

## 3.2.1

Expand Down
6 changes: 1 addition & 5 deletions src/components/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type Menu = {
name: string
onclick: () => void
}
class ContextMenu {
export class ContextMenu {
private nodeHTML = `
<div id="bili-cleaner-context-menu-container">
<ul>
Expand Down Expand Up @@ -108,7 +108,3 @@ class ContextMenu {
this.isShowing = false
}
}

// 单例
const contextMenuInstance = new ContextMenu()
export default contextMenuInstance
16 changes: 9 additions & 7 deletions src/filters/commentFilter/pages/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { GM_getValue } from '$'
import { Group } from '../../../components/group'
import { CheckboxItem, ButtonItem } from '../../../components/item'
import { debugCommentFilter as debug, error } from '../../../utils/logger'
import { isPageBangumi, isPageVideo } from '../../../utils/page-type'
import { isPageBangumi, isPagePlaylist, isPageVideo } from '../../../utils/page-type'
import { showEle, waitForEle } from '../../../utils/tool'
import { ContentAction, UsernameAction } from './actions/action'
import contextMenuInstance from '../../../components/contextmenu'
import coreCommentFilterInstance, { CommentSelectorFunc } from '../filters/core'
import settings from '../../../settings'
import { ContextMenu } from '../../../components/contextmenu'

const videoPageCommentFilterGroupList: Group[] = []

Expand All @@ -23,7 +23,7 @@ let isPinnedCommentWhitelistEnable: boolean = GM_getValue('BILICLEANER_video-com
let isNoteCommentWhitelistEnable: boolean = GM_getValue('BILICLEANER_video-comment-note-whitelist-status', true)
let isLinkCommentWhitelistEnable: boolean = GM_getValue('BILICLEANER_video-comment-link-whitelist-status', true)

if (isPageVideo() || isPageBangumi()) {
if (isPageVideo() || isPageBangumi() || isPagePlaylist()) {
let commentListContainer: HTMLElement
// 一级评论
const rootCommentSelectorFunc: CommentSelectorFunc = {
Expand Down Expand Up @@ -177,7 +177,9 @@ if (isPageVideo() || isPageBangumi()) {
return
}
isContextMenuFuncRunning = true
const menu = new ContextMenu()
document.addEventListener('contextmenu', (e) => {
menu.hide()
if (e.target instanceof HTMLElement) {
const target = e.target
if (
Expand All @@ -188,19 +190,19 @@ if (isPageVideo() || isPageBangumi()) {
const username = target.textContent?.trim()
if (username) {
e.preventDefault()
contextMenuInstance.registerMenu(`屏蔽用户:${username}`, () => {
menu.registerMenu(`屏蔽用户:${username}`, () => {
usernameAction.add(username)
})
contextMenuInstance.show(e.clientX, e.clientY)
menu.show(e.clientX, e.clientY)
}
} else {
contextMenuInstance.hide()
menu.hide()
}
}
})
// 关闭右键菜单
document.addEventListener('click', () => {
contextMenuInstance.hide()
menu.hide()
})
debug('contextMenuFunc listen contextmenu')
}
Expand Down
18 changes: 10 additions & 8 deletions src/filters/videoFilter/pages/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Group } from '../../../components/group'
import coreFilterInstance, { VideoSelectorFunc } from '../filters/core'
import settings from '../../../settings'
import { isPageChannel } from '../../../utils/page-type'
import contextMenuInstance from '../../../components/contextmenu'
import { matchBvid, waitForEle } from '../../../utils/tool'
import {
BvidAction,
Expand All @@ -15,6 +14,7 @@ import {
UploaderKeywordAction,
UploaderWhitelistAction,
} from './actions/action'
import { ContextMenu } from '../../../components/contextmenu'

const channelPageVideoFilterGroupList: Group[] = []

Expand Down Expand Up @@ -155,8 +155,10 @@ if (isPageChannel()) {
return
}
isContextMenuFuncRunning = true
const menu = new ContextMenu()
// 监听右键单击
document.addEventListener('contextmenu', (e) => {
menu.hide()
if (e.target instanceof HTMLElement) {
// debug(e.target.classList)
if (
Expand All @@ -175,9 +177,9 @@ if (isPageChannel()) {
const onclickWhite = () => {
channelUploaderWhitelistAction.add(uploader)
}
contextMenuInstance.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
contextMenuInstance.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
menu.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
menu.show(e.clientX, e.clientY)
}
} else if (
isContextMenuBvidEnable &&
Expand All @@ -193,18 +195,18 @@ if (isPageChannel()) {
const onclick = () => {
channelBvidAction.add(bvid)
}
contextMenuInstance.registerMenu(`屏蔽视频:${bvid}`, onclick)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`屏蔽视频:${bvid}`, onclick)
menu.show(e.clientX, e.clientY)
}
}
} else {
contextMenuInstance.hide()
menu.hide()
}
}
})
// 监听左键单击,关闭右键菜单
document.addEventListener('click', () => {
contextMenuInstance.hide()
menu.hide()
})
debug('contextMenuFunc listen contextmenu')
}
Expand Down
18 changes: 10 additions & 8 deletions src/filters/videoFilter/pages/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Group } from '../../../components/group'
import coreFilterInstance, { VideoSelectorFunc } from '../filters/core'
import settings from '../../../settings'
import { isPageHomepage } from '../../../utils/page-type'
import contextMenuInstance from '../../../components/contextmenu'
import { ContextMenu } from '../../../components/contextmenu'
import { matchBvid, showEle, waitForEle } from '../../../utils/tool'
import {
BvidAction,
Expand Down Expand Up @@ -189,8 +189,10 @@ if (isPageHomepage()) {
return
}
isContextMenuFuncRunning = true
const menu = new ContextMenu()
// 监听右键单击
document.addEventListener('contextmenu', (e) => {
menu.hide()
if (e.target instanceof HTMLElement) {
// debug(e.target.classList)
if (
Expand All @@ -209,9 +211,9 @@ if (isPageHomepage()) {
const onclickWhite = () => {
homepageUploaderWhitelistAction.add(uploader)
}
contextMenuInstance.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
contextMenuInstance.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
menu.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
menu.show(e.clientX, e.clientY)
}
} else if (
isContextMenuBvidEnable &&
Expand All @@ -227,18 +229,18 @@ if (isPageHomepage()) {
const onclick = () => {
homepageBvidAction.add(bvid)
}
contextMenuInstance.registerMenu(`屏蔽视频:${bvid}`, onclick)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`屏蔽视频:${bvid}`, onclick)
menu.show(e.clientX, e.clientY)
}
}
} else {
contextMenuInstance.hide()
menu.hide()
}
}
})
// 监听左键单击,关闭右键菜单
document.addEventListener('click', () => {
contextMenuInstance.hide()
menu.hide()
})
debug('contextMenuFunc listen contextmenu')
}
Expand Down
18 changes: 10 additions & 8 deletions src/filters/videoFilter/pages/popular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ButtonItem, CheckboxItem } from '../../../components/item'
import { Group } from '../../../components/group'
import settings from '../../../settings'
import { isPagePopular } from '../../../utils/page-type'
import contextMenuInstance from '../../../components/contextmenu'
import { ContextMenu } from '../../../components/contextmenu'
import { matchBvid, waitForEle } from '../../../utils/tool'
import {
BvidAction,
Expand Down Expand Up @@ -160,8 +160,10 @@ if (isPagePopular()) {
return
}
isContextMenuFuncRunning = true
const menu = new ContextMenu()
// 监听右键单击
document.addEventListener('contextmenu', (e) => {
menu.hide()
if (e.target instanceof HTMLElement) {
const target = e.target
if (
Expand All @@ -178,9 +180,9 @@ if (isPagePopular()) {
const onclickWhite = () => {
popularUploaderWhitelistAction.add(uploader)
}
contextMenuInstance.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
contextMenuInstance.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
menu.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
menu.show(e.clientX, e.clientY)
}
} else if (
isContextMenuBvidEnable &&
Expand All @@ -203,18 +205,18 @@ if (isPagePopular()) {
const onclick = () => {
popularBvidAction.add(bvid)
}
contextMenuInstance.registerMenu(`屏蔽视频:${bvid}`, onclick)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`屏蔽视频:${bvid}`, onclick)
menu.show(e.clientX, e.clientY)
}
}
} else {
contextMenuInstance.hide()
menu.hide()
}
}
})
// 监听左键单击,关闭右键菜单
document.addEventListener('click', () => {
contextMenuInstance.hide()
menu.hide()
})
debug('contextMenuFunc listen contextmenu')
}
Expand Down
18 changes: 10 additions & 8 deletions src/filters/videoFilter/pages/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ButtonItem, CheckboxItem, NumberItem } from '../../../components/item'
import { Group } from '../../../components/group'
import coreFilterInstance, { VideoSelectorFunc } from '../filters/core'
import { isPageSearch } from '../../../utils/page-type'
import contextMenuInstance from '../../../components/contextmenu'
import { ContextMenu } from '../../../components/contextmenu'
import { matchBvid, showEle, waitForEle } from '../../../utils/tool'
import {
BvidAction,
Expand Down Expand Up @@ -157,8 +157,10 @@ if (isPageSearch()) {
return
}
isContextMenuFuncRunning = true
const menu = new ContextMenu()
// 监听右键单击
document.addEventListener('contextmenu', (e) => {
menu.hide()
if (e.target instanceof HTMLElement) {
debug(e.target.classList)
if (
Expand All @@ -177,9 +179,9 @@ if (isPageSearch()) {
const onclickWhite = () => {
searchUploaderWhitelistAction.add(uploader)
}
contextMenuInstance.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
contextMenuInstance.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`◎ 屏蔽UP主:${uploader}`, onclickBlack)
menu.registerMenu(`◎ 将UP主加入白名单`, onclickWhite)
menu.show(e.clientX, e.clientY)
}
} else if (
isContextMenuBvidEnable &&
Expand All @@ -197,18 +199,18 @@ if (isPageSearch()) {
const onclick = () => {
searchBvidAction.add(bvid)
}
contextMenuInstance.registerMenu(`屏蔽视频:${bvid}`, onclick)
contextMenuInstance.show(e.clientX, e.clientY)
menu.registerMenu(`屏蔽视频:${bvid}`, onclick)
menu.show(e.clientX, e.clientY)
}
}
} else {
contextMenuInstance.hide()
menu.hide()
}
}
})
// 监听左键单击,关闭右键菜单
document.addEventListener('click', () => {
contextMenuInstance.hide()
menu.hide()
})
debug('contextMenuFunc listen contextmenu')
}
Expand Down
Loading

0 comments on commit 600a992

Please sign in to comment.