MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / deferScript

Function deferScript

packages/challenge-builder/src/transformers.js:257–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257const deferScript = scriptCode => {
258 // Mimic the behavior of a defer script by waiting until the DOM is loaded
259 // before executing the script.
260 return `
261(() => {
262 const run = (() => {
263 if (document.readyState === "interactive") {
264 ${scriptCode}
265 }
266 });
267
268 document.addEventListener('readystatechange', run, { once: true });
269})();
270`;
271};
272
273export const embedScript = (script, source, contents) => {
274 const code = contents ?? '';

Callers 1

embedScriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected