@@ -347,39 +347,7 @@ chrome.tabs.onUpdated.addListener(async function (tabId, info) {
347347 ScratchTools . Features . data = dataFeatures ;
348348 }
349349 addData ( ) ;
350- cachedStyles = await getEnabledStyles ( ) ;
351- var theStyles = [ ] ;
352- cachedStyles . forEach ( function ( el ) {
353- el . url = chrome . runtime . getURL (
354- `/features/${ style . feature . id } /${ style . file } `
355- ) ;
356- theStyles . push ( el . url ) ;
357- } ) ;
358- await chrome . scripting . executeScript ( {
359- args : [ theStyles ] ,
360- target : { tabId : tabId } ,
361- func : injectStyles ,
362- world : "MAIN" ,
363- } ) ;
364- ScratchTools . console . log ( "Injected styles." ) ;
365- function injectStyles ( styles ) {
366- if ( ! document . querySelector ( ".scratchtools-styles-div *" ) ) {
367- var div = document . createElement ( "div" ) ;
368- div . className = "scratchtools-styles-div" ;
369- document . head . appendChild ( div ) ;
370- styles . forEach ( function ( style ) {
371- if ( new URL ( tab . url ) . pathname . match ( style . runOn ) ) {
372- var link = document . createElement ( "link" ) ;
373- link . rel = "stylesheet" ;
374- link . href = style . url ;
375- link . dataset . feature = style . feature . id ;
376- document
377- . querySelector ( ".scratchtools-styles-div" )
378- . appendChild ( link ) ;
379- }
380- } ) ;
381- }
382- }
350+ injectStyles ( tabId ) ;
383351 for ( var i in data ) {
384352 var feature = data [ i ] ;
385353 if ( feature . version === 2 ) {
@@ -489,7 +457,9 @@ chrome.tabs.onUpdated.addListener(async function (tabId, info) {
489457 var newData = await (
490458 await fetch ( `/features/${ data [ el ] . id } /data.json` )
491459 ) . json ( ) ;
460+ console . log ( data [ el ] . id ) ;
492461 newData . scripts ?. forEach ( function ( script ) {
462+ console . log ( script . file ) ;
493463 if ( new URL ( tab . url ) . pathname . match ( script . runOn ) ) {
494464 chrome . scripting . executeScript ( {
495465 target : { tabId : tabId } ,
@@ -640,3 +610,37 @@ chrome.alarms.onAlarm.addListener(async function () {
640610 chrome . action . setBadgeText ( { text : "" } ) ;
641611 }
642612} ) ;
613+
614+ async function injectStyles ( tabId ) {
615+ cachedStyles = await getEnabledStyles ( ) ;
616+ var theStyles = [ ] ;
617+ cachedStyles . forEach ( function ( el ) {
618+ el . url = chrome . runtime . getURL (
619+ `/features/${ style . feature . id } /${ style . file } `
620+ ) ;
621+ theStyles . push ( el . url ) ;
622+ } ) ;
623+ await chrome . scripting . executeScript ( {
624+ args : [ theStyles ] ,
625+ target : { tabId : tabId } ,
626+ func : injectStyles ,
627+ world : "MAIN" ,
628+ } ) ;
629+ ScratchTools . console . log ( "Injected styles." ) ;
630+ function injectStyles ( styles ) {
631+ if ( ! document . querySelector ( ".scratchtools-styles-div *" ) ) {
632+ var div = document . createElement ( "div" ) ;
633+ div . className = "scratchtools-styles-div" ;
634+ document . head . appendChild ( div ) ;
635+ styles . forEach ( function ( style ) {
636+ if ( new URL ( tab . url ) . pathname . match ( style . runOn ) ) {
637+ var link = document . createElement ( "link" ) ;
638+ link . rel = "stylesheet" ;
639+ link . href = style . url ;
640+ link . dataset . feature = style . feature . id ;
641+ document . querySelector ( ".scratchtools-styles-div" ) . appendChild ( link ) ;
642+ }
643+ } ) ;
644+ }
645+ }
646+ }
0 commit comments