MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / loadFullScript

Function loadFullScript

popup/index.js:56–78  ·  view source on GitHub ↗

* Lazy load a full script when needed (on-demand loading) * @param {string} scriptId - The script ID * @returns {Promise } The full script object with all functions

(scriptId)

Source from the content-addressed store, hash-verified

54 * @returns {Promise<Object>} The full script object with all functions
55 */
56async function loadFullScript(scriptId) {
57 // Return from cache if already loaded
58 if (scriptCache.has(scriptId)) {
59 return scriptCache.get(scriptId);
60 }
61
62 try {
63 // Dynamic import - only loads this one script
64 const module = await import(`../scripts/${scriptId}.js`);
65 const fullScript = module.default;
66
67 // Inject the ID
68 fullScript.id = scriptId;
69
70 // Cache for future use
71 scriptCache.set(scriptId, fullScript);
72
73 return fullScript;
74 } catch (error) {
75 console.error(`Failed to lazy load script ${scriptId}:`, error);
76 throw error;
77 }
78}
79
80/**
81 * Preload popular/commonly used scripts in background

Callers 4

preloadPopularScriptsFunction · 0.85
createScriptButtonFunction · 0.85
runScriptFunction · 0.85
restoreFunction · 0.85

Calls 2

getMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected