Add disable vip danmaku style (#4227)

This commit is contained in:
the1812 2023-08-05 23:02:18 +08:00
parent 20a2a4502f
commit 43435db219
4 changed files with 78 additions and 4 deletions

View File

@ -0,0 +1 @@
移除高赞弹幕或 UP 主弹幕的特殊样式, 弹幕内容不会移除.

View File

@ -6,6 +6,38 @@ import {
import { ComponentEntry } from '@/components/types'
import { playerUrls } from '@/core/utils/urls'
import { addComponentListener } from '@/core/settings'
import { watchLocalStorage } from '@/core/local-storage'
enum DanmakuBorderStyle {
Heavy,
Stroke,
Shadow,
}
const danmakuTextShadowMap = {
[DanmakuBorderStyle.Heavy]:
'1px 0 1px #000000,0 1px 1px #000000,0 -1px 1px #000000,-1px 0 1px #000000',
[DanmakuBorderStyle.Stroke]: '0px 0px 1px #000000,0 0 1px #000000,0 0 1px #000000',
[DanmakuBorderStyle.Shadow]: '1px 1px 2px #000000,0 0 1px #000000',
}
const watchDanmakuBorderSettings = () => {
const localStorageKey = 'bpx_player_profile'
const updateDanmakuTextShadow = (playerSettings: any) => {
const danmakuBorderStyle: DanmakuBorderStyle = lodash.get(
playerSettings,
'dmSetting.fontborder',
)
document.documentElement.style.setProperty(
'--danmaku-text-shadow',
danmakuTextShadowMap[danmakuBorderStyle],
)
}
updateDanmakuTextShadow(JSON.parse(localStorage.getItem(localStorageKey)))
watchLocalStorage((key, value) => {
if (key === localStorageKey) {
updateDanmakuTextShadow(JSON.parse(value))
}
})
}
const options = defineOptionsMetadata({
highlight: {
@ -16,6 +48,10 @@ const options = defineOptionsMetadata({
displayName: '禁用UP主弹幕',
defaultValue: true,
},
vip: {
displayName: '禁用大会员弹幕',
defaultValue: true,
},
})
type Options = OptionsOfMetadata<typeof options>
@ -30,6 +66,7 @@ const entry: ComponentEntry<Options> = ({ metadata, settings }) => {
true,
)
})
watchDanmakuBorderSettings()
}
const name = 'disableSpecialDanmaku'
@ -45,8 +82,5 @@ export const component = defineComponentMetadata({
},
],
urlInclude: playerUrls,
description: {
'zh-CN': '移除高赞弹幕或 UP 主弹幕的特殊样式, 弹幕内容不会移除.',
},
options,
})

View File

@ -28,3 +28,12 @@ body.disable-up-danmaku-style {
}
}
}
body.disable-vip-danmaku-style {
.bili-dm-vip {
display: contents !important;
text-shadow: inherit !important;
}
.bili-dm:not([style*='--textShadow']) {
--textShadow: var(--danmaku-text-shadow);
}
}

View File

@ -1,5 +1,5 @@
import { select } from './spin-query'
import { deleteValue, getRandomId } from './utils'
import { createPostHook, deleteValue, getRandomId } from './utils'
interface CrossOriginMessage {
type: string
@ -132,3 +132,33 @@ export const crossOriginLocalStorage = {
})
},
}
type LocalStorageListener = (key: string, value: string) => void
const localStorageListeners: LocalStorageListener[] = []
let currentWindowLocalStorageHooked = false
/**
* LocalStorage , window window LocalStorage
* @param onLocalStorageUpdate LocalStorage
* @returns
*/
export const watchLocalStorage = (onLocalStorageUpdate: LocalStorageListener) => {
if (!currentWindowLocalStorageHooked) {
createPostHook(unsafeWindow.localStorage, 'setItem', (key: string, value: string) => {
localStorageListeners.forEach(listener => listener(key, value))
})
currentWindowLocalStorageHooked = true
}
localStorageListeners.push(onLocalStorageUpdate)
const otherWindowLocalStorageListener = (e: StorageEvent) => {
onLocalStorageUpdate(e.key, e.newValue)
}
window.addEventListener('storage', otherWindowLocalStorageListener)
return () => {
const index = localStorageListeners.indexOf(onLocalStorageUpdate)
if (index > -1) {
localStorageListeners.splice(index, 1)
}
window.removeEventListener('storage', otherWindowLocalStorageListener)
}
}