MCPcopy
hub / github.com/orestbida/cookieconsent / loadScript

Function loadScript

src/core/api.js:433–467  ·  view source on GitHub ↗
(src, attrs)

Source from the content-addressed store, hash-verified

431 * @returns {Promise<boolean>} promise
432 */
433export const loadScript = (src, attrs) => {
434 /**
435 * @type {HTMLScriptElement}
436 */
437 let script = document.querySelector('script[src="' + src + '"]');
438
439 return new Promise((resolve) => {
440 if (script)
441 return resolve(true);
442
443 script = createNode('script');
444
445 /**
446 * Add custom attributes
447 */
448 if (isObject(attrs)) {
449 for (const key in attrs) {
450 setAttribute(script, key, attrs[key]);
451 }
452 }
453
454 script.onload = () => resolve(true);
455 script.onerror = () => {
456 /**
457 * Remove script from dom if error is thrown
458 */
459 script.remove();
460 resolve(false);
461 };
462
463 script.src = src;
464
465 appendChild(document.head, script);
466 });
467};
468
469/**
470 * Save custom data inside cookie

Callers

nothing calls this directly

Calls 4

createNodeFunction · 0.90
isObjectFunction · 0.90
setAttributeFunction · 0.90
appendChildFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…