11import { createPlugin } from '@/utils' ;
2- // @ts -ignore
32import style from './style.css?inline' ;
4- import { getLyrics , LyricResult } from './lyrics' ;
3+ import { getLyrics , type LyricResult } from './lyrics' ;
4+
5+ // 1. Define the Config structure
6+ interface Config {
7+ enabled : boolean ;
8+ perfectSync : boolean ;
9+ romanize : boolean ;
10+ }
11+
12+ // 2. Define the PluginContext structure
13+ interface PluginContext {
14+ getConfig : ( ) => Promise < Config > ;
15+ setConfig : ( config : Config ) => void ;
16+ }
517
618export default createPlugin ( {
719 name : 'Better Fullscreen' ,
820 restartNeeded : true ,
921 config : {
1022 enabled : true ,
1123 perfectSync : false ,
12- romanize : false
24+ romanize : false ,
1325 } ,
1426 stylesheets : [ style ] ,
1527
@@ -21,18 +33,17 @@ export default createPlugin({
2133 type : 'checkbox' ,
2234 checked : config . enabled ,
2335 click : ( ) => setConfig ( { ...config , enabled : ! config . enabled } ) ,
24- }
36+ } ,
2537 ] ;
2638 } ,
2739
2840 renderer : {
29- async start ( ctx : any ) {
30- let config = await ctx . getConfig ( ) ;
41+ async start ( ctx : PluginContext ) {
42+ const config = await ctx . getConfig ( ) ;
3143 let isFullscreen = false ;
3244 let lyrics : LyricResult | null = null ;
33- let lastSrc = '' ;
45+ let lastSrc = '' ;
3446 let retryCount = 0 ;
35-
3647 const html = `
3748 <div id="bfs-container">
3849 <div class="bfs-bg-layer">
@@ -137,7 +148,7 @@ export default createPlugin({
137148 settingsBtn : document . getElementById ( 'bfs-settings-btn' ) ,
138149 settingsModal : document . getElementById ( 'bfs-settings-modal' ) ,
139150 optSync : document . getElementById ( 'bfs-opt-sync' ) as HTMLInputElement ,
140- optRoman : document . getElementById ( 'bfs-opt-roman' ) as HTMLInputElement
151+ optRoman : document . getElementById ( 'bfs-opt-roman' ) as HTMLInputElement ,
141152 } ;
142153
143154 const updateColors = ( ) => {
@@ -146,12 +157,10 @@ export default createPlugin({
146157 if ( ! ctx ) return ;
147158 ctx . drawImage ( ui . art , 0 , 0 , 50 , 50 ) ;
148159 const data = ctx . getImageData ( 0 , 0 , 50 , 50 ) . data ;
149-
150160 const getC = ( x :number , y :number ) => {
151- const i = ( y * 50 + x ) * 4 ;
152- return `rgb(${ data [ i ] } , ${ data [ i + 1 ] } , ${ data [ i + 2 ] } )` ;
161+ const i = ( ( y * 50 ) + x ) * 4 ;
162+ return `rgb(${ data [ i ] } , ${ data [ i + 1 ] } , ${ data [ i + 2 ] } )` ;
153163 } ;
154-
155164 document . documentElement . style . setProperty ( '--bfs-c1' , getC ( 25 , 25 ) ) ;
156165 document . documentElement . style . setProperty ( '--bfs-c2' , getC ( 10 , 10 ) ) ;
157166 document . documentElement . style . setProperty ( '--bfs-c3' , getC ( 40 , 40 ) ) ;
@@ -163,7 +172,6 @@ export default createPlugin({
163172 const renderLyrics = ( ) => {
164173 if ( ! ui . lines ) return ;
165174 ui . lines . innerHTML = '' ;
166-
167175 if ( ! lyrics ) {
168176 ui . lines . innerHTML = `
169177 <div class="bfs-empty">
@@ -174,10 +182,12 @@ export default createPlugin({
174182 </button>
175183 </div>
176184 ` ;
177- document . getElementById ( 'bfs-force-fetch' ) ?. addEventListener ( 'click' , ( ) => {
178- const title = ui . title ?. innerText ;
179- const artist = ui . artist ?. innerText ;
180- const video = document . querySelector ( 'video' ) ;
185+ document
186+ . getElementById ( 'bfs-force-fetch' )
187+ ?. addEventListener ( 'click' , ( ) => {
188+ const title = ui . title ?. innerText ;
189+ const artist = ui . artist ?. innerText ;
190+ const video = document . querySelector ( 'video' ) ;
181191 if ( title && artist && video ) {
182192 ui . lines ! . innerHTML = '<div class="bfs-empty">Searching...</div>' ;
183193 performFetch ( title , artist , video . duration ) ;
0 commit comments