88// Quá trình maintain sẽ khó hơn 1 chút, nhưng script sẽ chạy chính xác hơn
99
1010( ( ) => {
11- let search = new URLSearchParams ( getCurrentScriptSrc ( ) . split ( "?" ) ?. [ 1 ] ) ;
12- let path = search . get ( "path" ) ;
11+ // let search = new URLSearchParams(getCurrentScriptSrc().split("?")?.[1]);
12+ // let path = search.get("path");
13+
14+ let { path, ids, event } = JSON . parse (
15+ localStorage . getItem ( "ufs-auto-run-scripts" ) ?? "{}"
16+ ) ;
1317
1418 // run script on receive event
1519 window . addEventListener ( "ufs-run-page-scripts" , ( { detail } ) => {
1822 } ) ;
1923
2024 // auto run initial event defined in URL search params
21- ( ( ) => {
22- let ids = search . get ( "ids" ) ;
23- let event = search . get ( "event" ) ;
24- if ( ids && event ) {
25- let scriptIds = ids . split ( "," ) ;
26- runScripts ( scriptIds , event , path ) ;
27- }
28- } ) ( ) ;
25+ if ( ids && event ) {
26+ let scriptIds = ids . split ( "," ) ;
27+ runScripts ( scriptIds , event , path ) ;
28+ }
2929} ) ( ) ;
3030
3131function getCurrentScriptSrc ( ) {
@@ -39,7 +39,7 @@ function getCurrentScriptSrc() {
3939}
4040
4141function runScripts ( scriptIds , event , path ) {
42- for ( let id of scriptIds ) {
42+ for ( let id of scriptIds . filter ( ( _ ) => _ ) ) {
4343 let scriptPath = `${ path } /${ id } .js` ;
4444 import ( scriptPath ) . then ( ( { default : script } ) => {
4545 try {
0 commit comments