@@ -232,6 +232,42 @@ document.addEventListener('DOMContentLoaded', () => {
232232 // ── Plugin Settings ────────────────────────────────────────
233233 const pluginsList = document . getElementById ( 'plugins-list' ) ;
234234
235+ function renderPluginOptionsHtml ( plugin , cfg ) {
236+ if ( ! plugin . options || plugin . options . length === 0 ) return '' ;
237+ const pluginOpts = ( cfg && cfg . options ) ? cfg . options : { } ;
238+ let html = '<div class="plugin-options" style="margin-top: 10px; margin-left: 0;">' ;
239+ for ( const opt of plugin . options ) {
240+ const val = pluginOpts [ opt . id ] !== undefined ? pluginOpts [ opt . id ] : opt . defaultValue ;
241+ if ( opt . type === 'checkbox' ) {
242+ html += `
243+ <div class="setting-row" style="margin-bottom: 5px;">
244+ <input type="checkbox" id="plugin-opt-${ plugin . name . replace ( / \s + / g, '-' ) } -${ opt . id } " data-opt="${ opt . id } " ${ val ? 'checked' : '' } >
245+ <label for="plugin-opt-${ plugin . name . replace ( / \s + / g, '-' ) } -${ opt . id } " style="font-size: 13px;">${ opt . label } </label>
246+ </div>
247+ ` ;
248+ }
249+ }
250+ html += '</div>' ;
251+ return html ;
252+ }
253+
254+ function bindPluginOptionsEvents ( row , plugin ) {
255+ if ( ! plugin . options || plugin . options . length === 0 ) return ;
256+ row . querySelectorAll ( 'input[type="checkbox"][data-opt]' ) . forEach ( chk => {
257+ chk . addEventListener ( 'change' , ( e ) => {
258+ chrome . storage . local . get ( [ 'pluginsConfig' ] , ( res ) => {
259+ const updated = res . pluginsConfig || { } ;
260+ if ( ! updated [ plugin . name ] ) {
261+ updated [ plugin . name ] = { enabled : plugin . defaultEnabled !== false , options : { } } ;
262+ }
263+ if ( ! updated [ plugin . name ] . options ) updated [ plugin . name ] . options = { } ;
264+ updated [ plugin . name ] . options [ e . target . dataset . opt ] = e . target . checked ;
265+ chrome . storage . local . set ( { pluginsConfig : updated } ) ;
266+ } ) ;
267+ } ) ;
268+ } ) ;
269+ }
270+
235271 function renderPlugins ( pluginsMeta , pluginsConfig ) {
236272 pluginsList . innerHTML = '' ;
237273 if ( ! pluginsMeta || pluginsMeta . length === 0 ) {
@@ -253,14 +289,18 @@ document.addEventListener('DOMContentLoaded', () => {
253289 <div class="plugin-info">
254290 <div class="plugin-name">${ plugin . name } </div>
255291 ${ plugin . description ? `<div class="plugin-desc">${ plugin . description } </div>` : '' }
292+ ${ renderPluginOptionsHtml ( plugin , cfg ) }
256293 </div>
257294 ` ;
258295 pluginsList . appendChild ( row ) ;
259296
260- row . querySelector ( 'input[type="checkbox"]' ) . addEventListener ( 'change' , ( e ) => {
297+ bindPluginOptionsEvents ( row , plugin ) ;
298+
299+ row . querySelector ( `input#${ id } ` ) . addEventListener ( 'change' , ( e ) => {
261300 chrome . storage . local . get ( [ 'pluginsConfig' ] , ( res ) => {
262301 const updated = res . pluginsConfig || { } ;
263- updated [ plugin . name ] = { enabled : e . target . checked } ;
302+ const existing = updated [ plugin . name ] || { } ;
303+ updated [ plugin . name ] = { ...existing , enabled : e . target . checked } ;
264304 chrome . storage . local . set ( { pluginsConfig : updated } ) ;
265305 } ) ;
266306 } ) ;
0 commit comments