@@ -4,7 +4,6 @@ import { BADGES_CONFIG } from "../scripts/helpers/badge.js";
44import { checkForUpdate } from "./helpers/checkForUpdate.js" ;
55import { UfsGlobal } from "../scripts/content-scripts/ufs_global.js" ;
66import { THEME , THEME_KEY , getTheme , setTheme } from "./helpers/theme.js" ;
7- import { enableSmoothScroll } from "../scripts/smoothScroll.js" ;
87import {
98 isActiveScript ,
109 getCurrentTab ,
@@ -39,8 +38,8 @@ import {
3938 isTitle ,
4039 viewScriptSource ,
4140} from "./helpers/utils.js" ;
42- import { checkPass } from "../scripts/auto_lockWebsite.js" ;
43- import allScripts from "../scripts/@allScripts.js" ;
41+ // import { checkPass } from "../scripts/auto_lockWebsite.js";
42+ // import allScripts from "../scripts/@allScripts.js";
4443// import _ from "../md/exportScriptsToMd.js";
4544
4645// ============================================================================
@@ -83,21 +82,23 @@ async function loadFullScript(scriptId) {
8382 */
8483function preloadPopularScripts ( ) {
8584 const popular = [
86- 'fb_toggleLight' ,
87- 'youtube_downloadVideo' ,
88- 'simpleAllowCopy' ,
89- 'darkModePDF' ,
85+ // "ggdrive_downloadPdf",
9086 ] ;
9187
9288 setTimeout ( ( ) => {
93- popular . forEach ( id => {
89+ popular . forEach ( ( id ) => {
9490 loadFullScript ( id ) . catch ( ( ) => {
9591 // Silently fail - not critical
9692 } ) ;
9793 } ) ;
9894 } , 100 ) ;
9995}
10096
97+ async function lazyEnableSmoothScroll ( ) {
98+ const { enableSmoothScroll } = await import ( "../scripts/smoothScroll.js" ) ;
99+ return enableSmoothScroll ( ) ;
100+ }
101+
101102// ============================================================================
102103
103104const settingsBtn = document . querySelector ( ".settings" ) ;
@@ -374,13 +375,21 @@ function createScriptButton(script, isFavorite = false) {
374375 const fullScriptBtnIndex = hasInfoLink ? btnIndex - 1 : btnIndex ;
375376 const fullBtnConfig = fullScript . buttons ?. [ fullScriptBtnIndex ] ;
376377
377- if ( fullBtnConfig ?. onClick && typeof fullBtnConfig . onClick === 'function' ) {
378+ if (
379+ fullBtnConfig ?. onClick &&
380+ typeof fullBtnConfig . onClick === "function"
381+ ) {
378382 await fullBtnConfig . onClick ( ) ;
379383 } else {
380- console . error ( `Button onClick not found in script ${ script . id } at index ${ fullScriptBtnIndex } ` ) ;
384+ console . error (
385+ `Button onClick not found in script ${ script . id } at index ${ fullScriptBtnIndex } `
386+ ) ;
381387 }
382388 } catch ( error ) {
383- console . error ( `Failed to execute button onClick for ${ script . id } :` , error ) ;
389+ console . error (
390+ `Failed to execute button onClick for ${ script . id } :` ,
391+ error
392+ ) ;
384393 }
385394 } ;
386395 more . appendChild ( btn ) ;
@@ -582,13 +591,14 @@ async function runScript(scriptMetadata) {
582591
583592 let tab = await getCurrentTab ( ) ;
584593 let willRun = checkBlackWhiteList ( scriptMetadata , tab . url ) ;
594+
595+ // ⚡ LAZY LOAD: Load full script on-demand
596+ const script = await loadFullScript ( scriptMetadata . id ) ;
597+
585598 if ( willRun ) {
586599 recentScriptsSaver . add ( scriptMetadata ) ;
587600 trackEvent ( scriptMetadata . id ) ;
588601
589- // ⚡ LAZY LOAD: Load full script on-demand
590- const script = await loadFullScript ( scriptMetadata . id ) ;
591-
592602 try {
593603 if ( isFunction ( script . popupScript ?. onClick ) ) {
594604 await script . popupScript . onClick ( ) ;
@@ -822,15 +832,15 @@ function initSettings() {
822832 "active" ,
823833 ! ( disableSmoothScrollSaver . get ( ) ?? false )
824834 ) ;
825- checkbox . onclick = ( ) => {
835+ checkbox . onclick = async ( ) => {
826836 let curVal = disableSmoothScrollSaver . get ( ) ;
827837 let newVal = ! curVal ;
828838 disableSmoothScrollSaver . set ( newVal ) ;
829839
830840 let enabled = ! newVal ;
831841 trackEvent ( "CHANGE-SMOOTH-SCROLL-" + ( enabled ? "ON" : "OFF" ) ) ;
832842 checkbox . classList . toggle ( "active" , enabled ) ;
833- if ( enabled ) disableSmoothScroll = enableSmoothScroll ( ) ;
843+ if ( enabled ) disableSmoothScroll = await lazyEnableSmoothScroll ( ) ;
834844 else if ( typeof disableSmoothScroll == "function" ) disableSmoothScroll ( ) ;
835845 } ;
836846 body . appendChild ( smoothScrollRow ) ;
@@ -942,6 +952,8 @@ async function backup() {
942952}
943953
944954async function restore ( ) {
955+ const { checkPass } = await import ( "../scripts/auto_lockWebsite.js" ) ;
956+
945957 if (
946958 ! ( await checkPass (
947959 t ( {
@@ -1035,6 +1047,7 @@ async function restore() {
10351047}
10361048
10371049async function reset ( ) {
1050+ const { checkPass } = await import ( "../scripts/auto_lockWebsite.js" ) ;
10381051 if (
10391052 ! ( await checkPass (
10401053 t ( {
@@ -1184,7 +1197,9 @@ window.addEventListener("scroll", onScrollEnd);
11841197 trackEvent ( "OPEN-POPUP" ) ;
11851198
11861199 if ( ! disableSmoothScrollSaver . get ( ) )
1187- disableSmoothScroll = enableSmoothScroll ( ) ;
1200+ lazyEnableSmoothScroll ( ) . then ( ( _ ) => {
1201+ disableSmoothScroll = _ ;
1202+ } ) ;
11881203 initTracking ( ) ;
11891204 initSearch ( ) ;
11901205 initTooltip ( ) ;
0 commit comments