mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add custom style API
This commit is contained in:
parent
80511491c3
commit
b2992f40e7
8
@types/global/index.d.ts
vendored
8
@types/global/index.d.ts
vendored
@ -56,6 +56,13 @@ declare global {
|
||||
count: number
|
||||
date: string
|
||||
}
|
||||
interface CustomStyle {
|
||||
style: string
|
||||
name: string
|
||||
displayName: string
|
||||
enabled: boolean
|
||||
mode?: 'default' | 'instant' | 'important'
|
||||
}
|
||||
interface MonkeyInfo {
|
||||
script: {
|
||||
author: string;
|
||||
@ -385,6 +392,7 @@ declare global {
|
||||
hideRelatedVideos: boolean,
|
||||
defaultMedalID: number,
|
||||
autoMatchMedal: boolean,
|
||||
customStyles: CustomStyle[],
|
||||
latestVersionLink: string,
|
||||
currentVersion: string,
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -34,7 +34,7 @@
|
||||
// ==/UserScript==
|
||||
Vue.config.productionTip = false
|
||||
Vue.config.devtools = false
|
||||
import { logError, raiseEvent, loadLazyPanel, contentLoaded, fixed } from './utils'
|
||||
import { logError, raiseEvent, loadLazyPanel, contentLoaded, fixed, isOffline, getUID, scriptVersion, getCsrf, formatCount, escapeFilename } from './utils'
|
||||
import { settings, loadSettings, settingsChangeHandlers } from './settings'
|
||||
import { Ajax, setupAjaxHook } from './ajax'
|
||||
import { loadResources } from './resource-loader'
|
||||
@ -50,6 +50,7 @@ import { resourceManifest } from './resource-manifest'
|
||||
import { StyleManager } from './style-manager'
|
||||
import { ResourceManager } from './resource-manager'
|
||||
import { getScriptBlocker } from './script-blocker'
|
||||
import { installStyle, uninstallStyle } from './custom-styles'
|
||||
|
||||
(async () => {
|
||||
if (await GM.getValue('customNavbar') === true
|
||||
@ -163,6 +164,14 @@ import { getScriptBlocker } from './script-blocker'
|
||||
formatDuration,
|
||||
getDpiSourceSet,
|
||||
getScriptBlocker,
|
||||
isOffline,
|
||||
getUID,
|
||||
scriptVersion,
|
||||
getCsrf,
|
||||
formatCount,
|
||||
escapeFilename,
|
||||
installStyle,
|
||||
uninstallStyle,
|
||||
resources,
|
||||
theWorld: waitTime => {
|
||||
if (waitTime > 0) {
|
||||
|
||||
16
src/client/custom-styles.js
Normal file
16
src/client/custom-styles.js
Normal file
@ -0,0 +1,16 @@
|
||||
export const installStyle = style => {
|
||||
settings.customStyles.push(Object.assign({
|
||||
enabled: true,
|
||||
mode: 'default',
|
||||
}, style))
|
||||
settings.customStyles = settings.customStyles
|
||||
console.log(`已安装自定义样式'${style.displayName}'`)
|
||||
}
|
||||
export const uninstallStyle = name => {
|
||||
const styleIndex = settings.customStyles.findIndex(it => it.name === name)
|
||||
if (styleIndex !== -1) {
|
||||
settings.customStyles.splice(styleIndex, 1)
|
||||
settings.customStyles = settings.customStyles
|
||||
console.log(`已卸载自定义样式.`)
|
||||
}
|
||||
}
|
||||
@ -151,6 +151,7 @@ export class ResourceManager {
|
||||
// loadingToast.dismiss()
|
||||
// }
|
||||
this.applyReloadables() // reloadables run sync
|
||||
this.styleManager.applyCustomStyles()
|
||||
// await this.applyDropdownOptions();
|
||||
// this.applyWidgets() // No need to wait the widgets
|
||||
if (!isOffline() && settings.scriptDownloadMode === 'bundle') {
|
||||
|
||||
@ -173,6 +173,7 @@ export const settings = {
|
||||
hideRelatedVideos: false,
|
||||
defaultMedalID: 0,
|
||||
autoMatchMedal: false,
|
||||
customStyles: [],
|
||||
cache: {},
|
||||
}
|
||||
const fixedSettings = {
|
||||
|
||||
@ -73,5 +73,13 @@ export class StyleManager {
|
||||
this.fetchStyleByKey(key)
|
||||
}
|
||||
}
|
||||
for (const style of settings.customStyles.filter(it => it.mode === 'instant' && it.enabled)) {
|
||||
this.applyStyleFromText(style.style, this.getDefaultStyleId(style.name))
|
||||
}
|
||||
}
|
||||
applyCustomStyles() {
|
||||
for (const style of settings.customStyles.filter(it => it.mode !== 'instant' && it.enabled)) {
|
||||
this[style.mode === 'important' ? 'applyImportantStyleFromText' : 'applyStyleFromText'](style.style, this.getDefaultStyleId(style.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user