Skip to content

Commit

Permalink
feat: 添加弹幕屏蔽等级控制 #145
Browse files Browse the repository at this point in the history
  • Loading branch information
msojocs committed Dec 28, 2024
1 parent d078329 commit b5a842b
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# 🌈 v1.16.1-2 / 2024-12-
# 🌈 v1.16.1-2 / 2024-12-28

## 🚀 功能

- 插件: 修正模块加载失败。
- 插件: 添加弹幕屏蔽等级控制 #145

# 🌈 v1.16.1-1 / 2024-12-17

Expand Down
135 changes: 131 additions & 4 deletions extensions/area_unlimit/hook/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,25 +398,152 @@ const sleep = (ms) => {
}
// 1.75倍速
let rate175check = setInterval(()=>{
// console.log('1.75倍速')
log.info('1.75倍速')
try{
const createElement = (apeedRate) => {
const rate = document.createElement('li')
rate.className = "cpx-player-ctrl-playbackrate-menu-item"
rate.className = "bpx-player-ctrl-playbackrate-menu-item"
rate.dataset.value = `${apeedRate}`
rate.textContent = `${apeedRate}x`
return rate
}
const speedRate = window.danmakuManage.nodes.controlBottomRight.querySelector('.cpx-player-ctrl-playbackrate-menu > li:nth-child(1)')
const speedRate = window.danmakuManage.nodes.controlBottomRight.querySelector('.bpx-player-ctrl-playbackrate-menu > li:nth-child(1)')

speedRate.after(createElement(1.75))
speedRate.before(createElement(4.0))
speedRate.before(createElement(3.5))
speedRate.before(createElement(3.0))
speedRate.before(createElement(2.5))
{
/**
* @type {Element | null}
*/
const speed = window.danmakuManage.nodes.controlBottomCenter.querySelector('.bpx-player-dm-setting-left-speedplus')

const weightFilter = document.createElement('div')
weightFilter.innerHTML = `
<div class="bpx-player-dm-setting-left-speedplus bui bui-progress">
<div class="bpx-player-dm-setting-left-speedplus-title">屏蔽等级</div>
<div class="bpx-player-dm-setting-left-speedplus-content">
<div class="bpx-player-dm-setting-ui-speedplus"></div>
</div>
<div class="bui-area">
<div class="bui-progress-wrap">
<div class="bui-progress-bar" style="width: 0%;">
<span class="bui-progress-dot"></span>
</div>
<div class="bui-progress-step">
<div class="bui-progress-item" style="left:0%">
<div class="bui-progress-lab"></div>
</div>
</div>
</div>
<div class="bui-progress-val" style="width:60px">0</div>
</div>
</div>`
const valueText = weightFilter.querySelector('.bui-progress-val')
const value = weightFilter.querySelector('.bui-progress-bar')
const option = weightFilter.querySelector('.bui-progress-item')
let originalFilter = window.danmakuManage.danmaku.config.fn.filter
const changeFilterWeight = (weight) => {
if (weight > 10) weight = 10
if (weight < 0) weight = 0
localStorage.setItem('dm-filter-weight', weight)

valueText.textContent = `${weight}级`
value.style.width = `${weight * 10}%`
if (weight < 5)
{
value.firstElementChild.style.transform = 'translate3d(10px, -4px, 0px)'
}
else {
value.firstElementChild.style = {}
}

window.danmakuManage.danmaku.config.fn.filter = (t) => {
// log.info('filter:', t)
if (originalFilter(t)){
// log.info('default block:', t.weight)
return true
}
if (t.weight < weight) {
// log.info('block weight:', t.weight)
return true
}
return false
}
}
let isDown = false
const cal = (e) => {
// log.info('click options', e)
if (e.target.classList.contains('bui-progress-dot')) return
const filterWeight = Math.round(e.offsetX / 160 * 10)
// log.info('click result:', e.offsetX, filterWeight)

changeFilterWeight(filterWeight)
}
option.parentElement.parentElement.onmousedown = (e) => {
isDown = true
cal(e)
}
option.parentElement.parentElement.onmouseup = () => {
isDown = false
}
option.parentElement.parentElement.onmousemove = (e) => {
if (isDown) cal(e)
}
{
const originalInitDanmaku = window.danmakuManage.initDanmaku
window.danmakuManage.initDanmaku = function () {
log.info('initDanmaku...')
originalInitDanmaku.apply(this)
log.info('update filter...')
originalFilter = this.danmaku.config.fn.filter
changeFilterWeight(parseInt(localStorage.getItem('dm-filter-weight') || '0'))
{
let check = setInterval(() => {
/**
调整大小
* @type {Element | null}
*/
const left = document.querySelector('.bpx-player-dm-setting-left')
if (left.parentElement.style.height === '340px')
clearInterval(check)
left.parentElement.style.height = '340px'
left.parentElement.parentElement.parentElement.style.height = '340px'
log.info('fix height end')
}, 1000)
}
}
}
changeFilterWeight(parseInt(localStorage.getItem('dm-filter-weight') || '0'))

for (let i = 0; i <= 10; i++) {
const newOption = option.cloneNode(true)
newOption.style.left = `${i * 10}%`
option.before(newOption)
}
option.remove()
// log.info(weightFilter.firstElementChild)
speed.after(weightFilter.firstElementChild)
{
let check = setInterval(() => {
/**
调整大小
* @type {Element | null}
*/
const left = document.querySelector('.bpx-player-dm-setting-left')
if (left.parentElement.style.height === '340px')
clearInterval(check)
left.parentElement.style.height = '340px'
left.parentElement.parentElement.parentElement.style.height = '340px'
log.info('fix height end')
}, 1000)
}
}
clearInterval(rate175check)
}catch(err){
// console.error('添加1.75倍速失败:', err)
log.error('添加1.75倍速异常:', err)
}
}, 1000)
})()

0 comments on commit b5a842b

Please sign in to comment.