mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
* 【新增】支持固定全局倍速值和设置倍速菜单最大高度(后者不显示选项) * 【新增】支持隐藏倍速菜单滚动条 * 【优化】改变选项实时更新 * 【优化】使用了更稳妥的方式获取菜单项元素 * 【优化】使用自实现的 mini-rxjs 处理事件流,避免重复操作,实现更改选项值实时响应 * 【优化】为切换倍速等操作加上了防抖处理 * 【修复】添加空倍速会报倍速值太小的错误信息 * 【迁移】添加了迁移提示和自动迁移配置的功能 * 【更名】「倍速记忆」/「倍速增强」->「记忆倍速」 * 【更名】「扩展倍速菜单」->「扩展倍速」
27 lines
573 B
TypeScript
27 lines
573 B
TypeScript
import { addStyle } from '@/core/style'
|
|
|
|
export interface LoadStyleOptions<D> {
|
|
style: string | ((dep: D) => any)
|
|
name?: string
|
|
container?: HTMLElement
|
|
}
|
|
|
|
export const loadStyle = <D>(
|
|
{ style, name, container }: LoadStyleOptions<D>,
|
|
) => {
|
|
let styleElement
|
|
const complete = () => styleElement?.remove()
|
|
const next = (dep: D) => {
|
|
complete()
|
|
const styleText = typeof style === 'function' ? style(dep) : style
|
|
if (!styleText) {
|
|
return
|
|
}
|
|
styleElement = addStyle(styleText, name, container)
|
|
}
|
|
return {
|
|
next,
|
|
complete,
|
|
}
|
|
}
|