@stolbivi/pirojok
Version:
Some minimalistic library used to build chrome extensions, covers some popular Chrome Extension API
37 lines (36 loc) • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.injectIframe = exports.injectScript = void 0;
/**
* Injects a script file into the specified HTML node.
*
* @param {string} file - The path to the JavaScript file to inject
* @param {string} node - The HTML tag name of the parent node where the script should be injected
* @returns {void}
*/
function injectScript(file, node) {
var parent = document.getElementsByTagName(node)[0];
var scriptElement = document.createElement('script');
scriptElement.setAttribute('type', 'text/javascript');
scriptElement.setAttribute('src', file);
parent.appendChild(scriptElement);
}
exports.injectScript = injectScript;
/**
* Creates and injects an iframe element into the specified node.
*
* @param {string} id - The unique identifier for the iframe element
* @param {string} src - The source URL for the iframe content
* @param {Node} node - The parent node where the iframe should be injected
* @returns {HTMLIFrameElement} The created iframe element
*/
var injectIframe = function (id, src, node) {
var iframe = document.createElement('iframe');
iframe.id = id;
iframe.src = src;
// @ts-ignore
iframe.style = 'width: 0px;height: 0px';
node.appendChild(iframe);
return iframe;
};
exports.injectIframe = injectIframe;