Skip to content

Commit

Permalink
Merge pull request #23 from festoney8/dev
Browse files Browse the repository at this point in the history
merge dev to main, v3.0.0 alpha, close #21
  • Loading branch information
festoney8 committed Jan 20, 2024
2 parents eca112e + 6eb6ab9 commit 90b2297
Show file tree
Hide file tree
Showing 38 changed files with 3,257 additions and 373 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# CHANGELOG

## 3.0.0

- 新增:视频过滤器(时长过滤、UP主过滤、标题关键词过滤、BV号过滤)
- 新增:黑名单管理(UP主、标题关键词、BV号)
- 新增:视频过滤 支持首页
- 新增:视频过滤 支持播放页
- 新增:视频过滤 支持播热门页(热门视频、每周必看、排行榜)
- 新增:首页隐藏adblock提示 #21
- 新增:直播页 全屏下隐藏弹幕输入框
- 优化:播放页 隐藏列表时隐藏右侧展开按钮

## 2.3.4

- 优化:动态页 动态过滤、元素隐藏
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"husky": "^8.0.3",
"prettier": "^3.1.1",
"typescript": "^5.1.6",
"vite": "^4.4.8",
"vite": "^4.5.2",
"vite-plugin-monkey": "^3.4.0"
}
}
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions src/components/contextmenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { debug, error } from '../utils/logger'

type Menu = {
name: string
onclick: () => void
}
class ContextMenu {
private nodeHTML = `
<div id="bili-cleaner-context-menu-container">
<ul>
</ul>
</div>`
private nodeCSS = `
#bili-cleaner-context-menu-container {
position: fixed;
background: white;
border-radius: 5px;
box-shadow: 0 0 6px rgba(0,0,0,.3);
user-select: none;
overflow: hidden;
z-index: 99999;
}
#bili-cleaner-context-menu-container li {
padding: 6px 12px;
font-size: 1rem;
}
#bili-cleaner-context-menu-container li:hover {
background: rgb(251, 114, 153);
font-weight: 500;
color: white;
}
`
private menus: Menu[] = []
private node: HTMLDivElement | undefined
private isShowing = false

constructor() {}

/** 向document.head中添加CSS */
insertContextMenuCSS() {
try {
if (document.head.querySelector('#bili-cleaner-context-menu-css')) {
return
}
const style = document.createElement('style')
style.innerHTML = this.nodeCSS.replace(/\n\s*/g, '').trim()
style.setAttribute('id', 'bili-cleaner-context-menu-css')
document.head.appendChild(style)
debug('insertContextMenuCSS OK')
} catch (err) {
error(`insertContextMenuCSS failed`)
error(err)
}
}

/**
* 注册右键菜单
* @param name 功能名
* @param onclick 点击执行的回调函数
*/
registerMenu(name: string, onclick: () => void) {
if (this.isShowing) {
this.menus = []
this.isShowing = false
}
this.menus.push({
name: name,
onclick: onclick,
})
}
/**
* 显示右键菜单
* @param x 坐标X
* @param y 坐标Y
*/
show(x: number, y: number) {
// 新建节点
if (!this.node) {
this.insertContextMenuCSS()
const wrap = document.createElement('div')
wrap.innerHTML = this.nodeHTML
this.node = wrap.querySelector('#bili-cleaner-context-menu-container') as HTMLDivElement
document.body?.appendChild(this.node)
}
// 新建列表
const menuList = this.node.querySelector('ul')! as HTMLUListElement
menuList.innerHTML = ''
this.menus.forEach((menu) => {
const li = document.createElement('li')
li.className = 'bili-cleaner-context-menu'
li.innerHTML = `${menu.name}`
li.onclick = menu.onclick
menuList.appendChild(li)
})
this.node.style.left = `${x + 3}px`
this.node.style.top = `${y + 3}px`
this.node.style.display = 'block'

this.isShowing = true
}
/** 隐藏右键菜单 */
hide() {
if (this.node) {
this.node.style.display = 'none'
this.node.querySelector('ul')!.innerHTML = ''
this.menus = []
}
this.isShowing = false
}
}

// 单例
const contextMenuInstance = new ContextMenu()
export default contextMenuInstance
23 changes: 7 additions & 16 deletions src/core/group.ts → src/components/group.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { debug, error } from '../utils/logger'
import { CheckboxItem, RadioItem } from './item'
import { ButtonItem, CheckboxItem, NumberItem, RadioItem } from './item'

interface IGroup {
readonly groupHTML: myHTML
insertGroup(): void
insertGroupItems(): void
enableGroup(): void
reloadGroup(): void
disableGroup(): void
}

export class Group implements IGroup {
export class Group {
groupHTML = `
<div class="bili-cleaner-group">
<div class="bili-cleaner-group-title">
Expand All @@ -29,7 +20,7 @@ export class Group implements IGroup {
constructor(
private groupID: string,
private title: string,
private items: (CheckboxItem | RadioItem)[],
private items: (CheckboxItem | RadioItem | NumberItem | ButtonItem)[],
) {
this.groupID = 'bili-cleaner-group-' + groupID
}
Expand Down Expand Up @@ -66,7 +57,7 @@ export class Group implements IGroup {
enableGroup(enableFunc = true) {
try {
this.items.forEach((e) => {
if (typeof e.enableItem === 'function') {
if (e instanceof CheckboxItem || e instanceof RadioItem) {
e.enableItem(enableFunc)
}
})
Expand All @@ -80,11 +71,11 @@ export class Group implements IGroup {
reloadGroup() {
try {
this.items.forEach((e) => {
if (typeof e.reloadItem === 'function') {
if (e instanceof CheckboxItem || e instanceof RadioItem) {
e.reloadItem()
}
})
// debug(`reloadGroup ${this.groupID} OK`)
debug(`reloadGroup ${this.groupID} OK`)
} catch (err) {
error(`reloadGroup ${this.groupID} err`)
error(err)
Expand All @@ -94,7 +85,7 @@ export class Group implements IGroup {
disableGroup() {
try {
this.items.forEach((e) => {
if (typeof e.removeItemCSS === 'function') {
if (e instanceof CheckboxItem || e instanceof RadioItem) {
e.removeItemCSS()
}
})
Expand Down
Loading

0 comments on commit 90b2297

Please sign in to comment.