@@ -170,15 +170,19 @@ function runScriptsBackground(
170170function checkWillRun ( scriptId , context , eventChain , details ) {
171171 const script = allScripts [ scriptId ] ;
172172 const s = script ?. [ context ] ;
173+
174+ let beforeFnName = eventChain . split ( "." ) ;
175+ let fnName = beforeFnName . pop ( ) ;
176+
173177 let fn = s ;
174- eventChain . split ( "." ) . forEach ( ( e ) => {
175- fn = fn ?. [ e ] ;
176- } ) ;
178+ beforeFnName . forEach ( ( e ) => ( fn = fn ?. [ e ] ) ) ;
179+ fn = fn ?. [ fnName + "_" ] || fn ?. [ fnName ] ;
180+
177181 if (
178182 typeof fn === "function" &&
179183 ( ! details ||
180- ( ( s . runInAllFrames || details . frameType == "outermost_frame" ) &&
181- utils . checkWillRun ( script , details . url ) ) )
184+ ( ( fn . name . endsWith ( "_" ) || details . frameType == "outermost_frame" ) &&
185+ utils . checkBlackWhiteList ( script , details . url ) ) )
182186 )
183187 return fn ;
184188
@@ -318,10 +322,9 @@ function listenNavigation() {
318322 const { tabId, frameId } = getDetailIds ( details ) ;
319323
320324 if ( eventChain === "onDocumentStart" ) {
321- // clear badge cache on main frame
325+ // clear badge cache on main frame load
322326 if ( details . frameId === 0 ) CACHED . badges [ tabId ] = [ ] ;
323- // inject ufs global
324- injectUfsGlobal ( tabId , frameId ) ;
327+ injectUfsGlobal ( tabId , frameId , details ) ;
325328 }
326329
327330 runScriptsTab ( eventChain , MAIN , details ) ;
@@ -389,27 +392,27 @@ function listenMessage() {
389392 } ) ;
390393}
391394
392- function injectUfsGlobal ( tabId , frameId ) {
395+ function injectUfsGlobal ( tabId , frameId , details ) {
393396 [
394- { files : [ "ufs_global.js" , "content_script.js" ] , world : ISOLATED } ,
395- { files : [ "ufs_global.js" ] , world : MAIN } ,
396- ] . forEach ( ( { files, world } ) => {
397+ [ [ "ufs_global.js" , "content_script.js" ] , ISOLATED ] ,
398+ [ [ "ufs_global.js" ] , MAIN ] ,
399+ ] . forEach ( ( [ files , world ] ) => {
397400 let paths = files . map ( ( file ) => CACHED . path + "content-scripts/" + file ) ;
398401 utils . runScriptFile ( {
399402 target : {
400403 tabId : tabId ,
401404 frameIds : [ frameId ] ,
402405 } ,
403- func : ( paths , frameId , world ) => {
406+ func : ( paths , frameId , world , url ) => {
404407 paths . forEach ( ( path ) => {
405408 import ( path )
406- . then ( ( ) => console . log ( "Ufs import SUCCESS" , frameId , world , path ) )
409+ . then ( ( ) => console . log ( "Ufs import SUCCESS" , frameId , world , url ) )
407410 . catch ( ( e ) =>
408- console . error ( "Ufs import FAILED" , frameId , world , e )
411+ console . error ( "Ufs import FAILED" , frameId , world , url , e )
409412 ) ;
410413 } ) ;
411414 } ,
412- args : [ paths , frameId , world ] ,
415+ args : [ paths , frameId , world , details . url ] ,
413416 world : world ,
414417 } ) ;
415418 } ) ;
0 commit comments