Skip to content

Commit

Permalink
feat: wordlist editor support dragging, update style
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Jan 23, 2024
1 parent b31610f commit 93412e6
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- 新增:右键菜单新增 添加UP主到白名单
- 新增:标题关键词 支持正则(使用 `/` 包住,如 `/abc|\d+/`
- 优化:标题关键词 普通词汇大小写通配
- 优化:关键词编辑器样式

## 3.0.1

Expand Down
30 changes: 21 additions & 9 deletions src/components/panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,33 +182,45 @@
#bili-cleaner-wordlist {
background: #fff;
border-radius: 5px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.25);
overflow: hidden;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
border: 1px solid #000;
z-index: 2147483641;
}
#bili-cleaner-wordlist .wordlist-header {
background-color: #fb7299;
color: #fff;
font-size: 22px;
font-weight: bold;
margin: 8px auto;
height: 40px;
line-height: 40px;
margin: 0;
height: 100%;
width: 100%;
line-height: 36px;
text-align: center;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
#bili-cleaner-wordlist .wordlist-description {
font-size: 18px;
margin: 6px auto;
line-height: 18px;
text-align: center;
}
#bili-cleaner-wordlist textarea.wordlist-body {
width: 340px;
height: 400px;
margin: 5px 15px;
border: 1px solid #000;
border-radius: 5px;
margin: 0 12px;
border: 2px solid #ccc;
overflow-y: scroll;
font-size: 18px;
line-height: 24px;
padding: 8px;
line-height: 28px;
padding: 5px 10px;
flex-grow: 1;
resize: none;
}
Expand Down
29 changes: 19 additions & 10 deletions src/components/panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -188,34 +188,43 @@
#bili-cleaner-wordlist {
background: white;
border-radius: 5px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.25);
overflow: hidden;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
border: 1px solid black;
z-index: 2147483641;

& .wordlist-header {
background-color: #fb7299;
color: #fff;
font-size: 22px;
font-weight: bold;
margin: 8px auto;
height: 40px;
line-height: 40px;
margin: 0;
height: 100%;
width: 100%;
line-height: 36px;
text-align: center;
user-select: none;
}
& .wordlist-description {
font-size: 18px;
margin: 6px auto;
line-height: 18px;
text-align: center;
}

& textarea.wordlist-body {
width: 340px;
height: 400px;
margin: 5px 15px;
border: 1px solid black;
border-radius: 5px;
margin: 0 12px;
border: 2px solid #ccc;
overflow-y: scroll;
font-size: 18px;
line-height: 24px;
padding: 8px;
line-height: 28px;
padding: 5px 10px;
flex-grow: 1;
resize: none;
&:focus {
Expand Down
2 changes: 1 addition & 1 deletion src/components/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { debug, error } from '../utils/logger'

class Panel {
panelCSS = `
#bili-cleaner{position:fixed;left:50%;top:50%;transform:translate(-50%, -50%);width:max(32vw,300px);height:90vh;border-radius:10px;background:#f4f5f7;box-shadow:0 0 8px rgba(0,0,0,.25);overflow:auto;z-index:2147483640}#bili-cleaner #bili-cleaner-bar{width:max(32vw,300px);height:6vh;background:#fb7299;border-top-left-radius:10px;border-top-right-radius:10px;cursor:move;-webkit-user-select:none;-moz-user-select:none;user-select:none}#bili-cleaner #bili-cleaner-bar #bili-cleaner-title{width:max(32vw,300px);height:6vh;display:flex;justify-content:center;align-items:center;color:#fff;font-weight:bold;font-size:22px}#bili-cleaner #bili-cleaner-bar #bili-cleaner-title span{text-align:center}#bili-cleaner #bili-cleaner-bar #bili-cleaner-close{position:absolute;top:0;right:0;width:6vh;height:6vh;border-radius:6vh;display:flex;justify-content:center;align-items:center;cursor:auto}#bili-cleaner #bili-cleaner-bar #bili-cleaner-close:hover{background:rgba(255,255,255,.2)}#bili-cleaner #bili-cleaner-bar #bili-cleaner-close svg{text-align:center}#bili-cleaner #bili-cleaner-group-list{height:84vh;overflow:auto;scrollbar-width:none !important}#bili-cleaner #bili-cleaner-group-list::-webkit-scrollbar{display:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group{margin:14px;background:#fff;border-radius:6px;padding:8px 16px;border:1px solid #ddd;-webkit-user-select:none;-moz-user-select:none;user-select:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group hr{border:1px solid #eee;margin:5px 0 10px 0}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-group-title{font-size:20px;font-weight:bold;padding:2px;color:#000;letter-spacing:1px}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-list label{display:flex;align-items:center;margin:6px 0 6px 10px;font-size:16px;color:#000}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-list hr{border:1px solid #eee;margin:15px 20px}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox{width:50px;min-width:50px;height:27px;margin:0 1em 0 0;position:relative;border:1px solid #dfdfdf;background-color:#fdfdfd;box-shadow:#dfdfdf 0 0 0 0 inset;border-radius:50px;-moz-appearance:none;appearance:none;-webkit-appearance:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox:before{content:"";width:25px;height:25px;position:absolute;top:0px;left:0;border-radius:50px;background-color:#fff;box-shadow:0 1px 3px rgba(0,0,0,.5)}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox:checked{border-color:#fb7299;box-shadow:#fb7299 0 0 0 16px inset;background-color:#fb7299}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox:checked:before{left:25px}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-number{width:50px;min-width:50px;height:27px;margin:0 .5em 0 .5em;position:relative;border:1px solid #dfdfdf;background-color:#fdfdfd;box-shadow:#dfdfdf 0 0 0 0 inset;border-radius:5px;-moz-appearance:none;appearance:none;-webkit-appearance:none;text-align:center;color:blue;font-size:16px;-moz-appearance:textfield}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-number::-webkit-inner-spin-button,#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-number::-webkit-inner-spin-button{-webkit-appearance:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-button{width:50px;background-color:#fff;border:1px solid #666;border-radius:6px;box-sizing:border-box;cursor:pointer;display:inline-block;font-size:16px;margin:0 1em 0 0;outline:none;padding:5px 0;position:relative;text-align:center;text-decoration:none;touch-action:manipulation;transition:box-shadow .2s,transform .1s;-moz-user-select:none;user-select:none;-webkit-user-select:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-button:active{background-color:#f7f7f7;border-color:#000;transform:scale(0.96)}#bili-cleaner-wordlist{background:#fff;border-radius:5px;position:fixed;left:50%;top:50%;transform:translate(-50%, -50%);display:flex;flex-direction:column;border:1px solid #000;z-index:2147483641}#bili-cleaner-wordlist .wordlist-header{font-size:22px;font-weight:bold;margin:8px auto;height:40px;line-height:40px;text-align:center}#bili-cleaner-wordlist textarea.wordlist-body{width:340px;height:400px;margin:5px 15px;border:1px solid #000;border-radius:5px;overflow-y:scroll;font-size:18px;line-height:24px;padding:8px;flex-grow:1;resize:none}#bili-cleaner-wordlist textarea.wordlist-body:focus{outline:none !important}#bili-cleaner-wordlist .wordlist-footer{height:50px;display:flex;justify-content:space-evenly;padding:0 10px;align-items:center}#bili-cleaner-wordlist .wordlist-footer button{width:100px;height:30px;border-radius:5px;border:1px solid #666;font-size:18px}#bili-cleaner-wordlist .wordlist-footer button:hover{background-color:#666;color:#fff}
#bili-cleaner{position:fixed;left:50%;top:50%;transform:translate(-50%, -50%);width:max(32vw,300px);height:90vh;border-radius:10px;background:#f4f5f7;box-shadow:0 0 8px rgba(0,0,0,.25);overflow:auto;z-index:2147483640}#bili-cleaner #bili-cleaner-bar{width:max(32vw,300px);height:6vh;background:#fb7299;border-top-left-radius:10px;border-top-right-radius:10px;cursor:move;-webkit-user-select:none;-moz-user-select:none;user-select:none}#bili-cleaner #bili-cleaner-bar #bili-cleaner-title{width:max(32vw,300px);height:6vh;display:flex;justify-content:center;align-items:center;color:#fff;font-weight:bold;font-size:22px}#bili-cleaner #bili-cleaner-bar #bili-cleaner-title span{text-align:center}#bili-cleaner #bili-cleaner-bar #bili-cleaner-close{position:absolute;top:0;right:0;width:6vh;height:6vh;border-radius:6vh;display:flex;justify-content:center;align-items:center;cursor:auto}#bili-cleaner #bili-cleaner-bar #bili-cleaner-close:hover{background:rgba(255,255,255,.2)}#bili-cleaner #bili-cleaner-bar #bili-cleaner-close svg{text-align:center}#bili-cleaner #bili-cleaner-group-list{height:84vh;overflow:auto;scrollbar-width:none !important}#bili-cleaner #bili-cleaner-group-list::-webkit-scrollbar{display:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group{margin:14px;background:#fff;border-radius:6px;padding:8px 16px;border:1px solid #ddd;-webkit-user-select:none;-moz-user-select:none;user-select:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group hr{border:1px solid #eee;margin:5px 0 10px 0}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-group-title{font-size:20px;font-weight:bold;padding:2px;color:#000;letter-spacing:1px}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-list label{display:flex;align-items:center;margin:6px 0 6px 10px;font-size:16px;color:#000}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-list hr{border:1px solid #eee;margin:15px 20px}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox{width:50px;min-width:50px;height:27px;margin:0 1em 0 0;position:relative;border:1px solid #dfdfdf;background-color:#fdfdfd;box-shadow:#dfdfdf 0 0 0 0 inset;border-radius:50px;-moz-appearance:none;appearance:none;-webkit-appearance:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox:before{content:"";width:25px;height:25px;position:absolute;top:0px;left:0;border-radius:50px;background-color:#fff;box-shadow:0 1px 3px rgba(0,0,0,.5)}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox:checked{border-color:#fb7299;box-shadow:#fb7299 0 0 0 16px inset;background-color:#fb7299}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-checkbox:checked:before{left:25px}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-number{width:50px;min-width:50px;height:27px;margin:0 .5em 0 .5em;position:relative;border:1px solid #dfdfdf;background-color:#fdfdfd;box-shadow:#dfdfdf 0 0 0 0 inset;border-radius:5px;-moz-appearance:none;appearance:none;-webkit-appearance:none;text-align:center;color:blue;font-size:16px;-moz-appearance:textfield}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-number::-webkit-inner-spin-button,#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-number::-webkit-inner-spin-button{-webkit-appearance:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-button{width:50px;background-color:#fff;border:1px solid #666;border-radius:6px;box-sizing:border-box;cursor:pointer;display:inline-block;font-size:16px;margin:0 1em 0 0;outline:none;padding:5px 0;position:relative;text-align:center;text-decoration:none;touch-action:manipulation;transition:box-shadow .2s,transform .1s;-moz-user-select:none;user-select:none;-webkit-user-select:none}#bili-cleaner #bili-cleaner-group-list .bili-cleaner-group .bili-cleaner-item-button:active{background-color:#f7f7f7;border-color:#000;transform:scale(0.96)}#bili-cleaner-wordlist{background:#fff;border-radius:5px;box-shadow:0 0 8px rgba(0,0,0,.25);overflow:hidden;position:fixed;left:50%;top:50%;transform:translate(-50%, -50%);display:flex;flex-direction:column;z-index:2147483641}#bili-cleaner-wordlist .wordlist-header{background-color:#fb7299;color:#fff;font-size:22px;font-weight:bold;margin:0;height:100%;width:100%;line-height:36px;text-align:center;-webkit-user-select:none;-moz-user-select:none;user-select:none}#bili-cleaner-wordlist .wordlist-description{font-size:18px;margin:6px auto;line-height:18px;text-align:center}#bili-cleaner-wordlist textarea.wordlist-body{width:340px;height:400px;margin:0 12px;border:2px solid #ccc;overflow-y:scroll;font-size:18px;line-height:28px;padding:5px 10px;flex-grow:1;resize:none}#bili-cleaner-wordlist textarea.wordlist-body:focus{outline:none !important}#bili-cleaner-wordlist .wordlist-footer{height:50px;display:flex;justify-content:space-evenly;padding:0 10px;align-items:center}#bili-cleaner-wordlist .wordlist-footer button{width:100px;height:30px;border-radius:5px;border:1px solid #666;font-size:18px}#bili-cleaner-wordlist .wordlist-footer button:hover{background-color:#666;color:#fff}
`
panelHTML = `
<div id="bili-cleaner">
Expand Down
43 changes: 41 additions & 2 deletions src/components/wordlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class WordList {
private readonly nodeHTML = `
<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>
<div class="wordlist-footer">
<button class="wordlist-save-button">保存</button>
Expand All @@ -18,11 +19,13 @@ export class WordList {
/**
* WordList用于维护各种string array(up主列表、BVID列表、关键词列表)
* @param listID 列表唯一ID, 对应数据存储
* @param description 列表说明, 会显示在编辑框头部作为标题
* @param title 列表标题
* @param description 列表详情说明
* @param callback 回调函数, 在保存列表时回调
*/
constructor(
private listID: string,
private title: string,
private description: string,
private callback: (values: string[]) => void,
) {
Expand Down Expand Up @@ -122,7 +125,8 @@ export class WordList {
}
const e = document.createElement('div')
e.innerHTML = this.nodeHTML.trim()
e.querySelector('.wordlist-header')!.innerHTML = this.description.replace('\n', '<br>')
e.querySelector('.wordlist-header')!.innerHTML = this.title.replace('\n', '<br>')
e.querySelector('.wordlist-description')!.innerHTML = this.description.replace('\n', '<br>')
debug(`insertNode, fetchList ${this.fetchList().length} lines`)
let lines = this.fetchList().join('\n')
if (lines) {
Expand Down Expand Up @@ -172,9 +176,44 @@ export class WordList {
debug(`list ${this.listID} listen save button`)
}

/** 可拖拽bar */
draggableBar() {
try {
const wordlist = document.getElementById('bili-cleaner-wordlist') as HTMLFormElement
const bar = document.querySelector('#bili-cleaner-wordlist .wordlist-header') as HTMLFormElement
let isDragging = false
let initX: number, initY: number, initLeft: number, initTop: number

bar.addEventListener('mousedown', (e) => {
isDragging = true
initX = e.clientX
initY = e.clientY
const c = window.getComputedStyle(wordlist)
initLeft = parseInt(c.getPropertyValue('left'), 10)
initTop = parseInt(c.getPropertyValue('top'), 10)
})
document.addEventListener('mousemove', (e) => {
if (isDragging) {
const diffX = e.clientX - initX
const diffY = e.clientY - initY
wordlist.style.left = `${initLeft + diffX}px`
wordlist.style.top = `${initTop + diffY}px`
}
})
document.addEventListener('mouseup', () => {
isDragging = false
})
debug('draggableBar OK')
} catch (err) {
error(`draggableBar failed`)
error(err)
}
}

/** 显示编辑框 */
show() {
this.insertNode()
this.watchNode()
this.draggableBar()
}
}
1 change: 0 additions & 1 deletion src/filters/filters/subfilters/titleKeyword.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { error } from '../../../utils/logger'
import { ISubFilter } from '../core'

// Todo: 支持正则
class TitleKeywordFilter implements ISubFilter {
isEnable = false
private titleKeywordSet = new Set<string>()
Expand Down
28 changes: 19 additions & 9 deletions src/filters/pages/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class UploaderAction implements Action {
uploaderFilterInstance.setStatus(this.status)
uploaderFilterInstance.setParams(this.value)
// 初始化黑名单, callback触发edit, 必需用箭头函数
this.blacklist = new WordList(this.valueKey, 'UP主 黑名单', (values: string[]) => {
this.blacklist = new WordList(this.valueKey, 'UP主 黑名单', '保存时自动去重,实时生效', (values: string[]) => {
this.edit(values)
})
}
Expand Down Expand Up @@ -150,7 +150,7 @@ export class BvidAction implements Action {
bvidFilterInstance.setStatus(this.status)
bvidFilterInstance.setParams(this.value)
// 初始化黑名单, callback触发edit
this.blacklist = new WordList(this.valueKey, 'BV号 黑名单', (values: string[]) => {
this.blacklist = new WordList(this.valueKey, 'BV号 黑名单', '保存时自动去重,实时生效', (values: string[]) => {
this.edit(values)
})
}
Expand Down Expand Up @@ -202,9 +202,14 @@ export class TitleKeywordAction implements Action {
titleKeywordFilterInstance.setStatus(this.status)
titleKeywordFilterInstance.setParams(this.value)
// 初始化黑名单, callback触发edit
this.blacklist = new WordList(this.valueKey, '标题关键词 黑名单', (values: string[]) => {
this.edit(values)
})
this.blacklist = new WordList(
this.valueKey,
'标题关键词 黑名单',
`支持正则(iv模式)\n需使用 /.../ 将表达式包起来,如 /xyz|\\d+/`,
(values: string[]) => {
this.edit(values)
},
)
}

enable() {
Expand Down Expand Up @@ -254,7 +259,7 @@ export class UploaderWhitelistAction implements Action {
uploaderWhitelistFilterInstance.setStatus(this.status)
uploaderWhitelistFilterInstance.setParams(this.value)
// 初始化白名单, callback触发edit
this.whitelist = new WordList(this.valueKey, 'UP主 白名单', (values: string[]) => {
this.whitelist = new WordList(this.valueKey, 'UP主 白名单', '保存时自动去重,实时生效', (values: string[]) => {
this.edit(values)
})
}
Expand Down Expand Up @@ -306,9 +311,14 @@ export class TitleKeywordWhitelistAction implements Action {
titleKeywordWhitelistFilterInstance.setStatus(this.status)
titleKeywordWhitelistFilterInstance.setParams(this.value)
// 初始化白名单, callback触发edit
this.whitelist = new WordList(this.valueKey, '标题关键词 白名单', (values: string[]) => {
this.edit(values)
})
this.whitelist = new WordList(
this.valueKey,
'标题关键词 白名单',
`支持正则(iv模式)\n需使用 /.../ 将表达式包起来,如 /xyz|\\d+/`,
(values: string[]) => {
this.edit(values)
},
)
}

enable() {
Expand Down
Loading

0 comments on commit 93412e6

Please sign in to comment.