123456789101112131415161718192021222324 |
- /**
- * injectScript - Inject internal script to available access to the `window`
- *
- * @param {type} file_path Local path of the internal script.
- * @param {type} tag The tag as string, where the script will be append (default: "body").
- * @see {@link http://stackoverflow.com/questions/20499994/access-window-variable-from-content-script}
- */
- function injectScript(file_path, tag) {
- var node = document.getElementsByTagName(tag)[0];
- var script = document.createElement("script");
- script.setAttribute("type", "text/javascript");
- script.setAttribute("src", file_path);
- node.appendChild(script);
- }
- function injectData(property, value, tag) {
- var node = document.getElementsByTagName(tag)[0];
- var span = document.createElement("span");
- span.setAttribute("id", `property-${property}`);
- span.setAttribute("data-value", value);
- console.log(property, value, tag, node);
- node.appendChild(span);
- }
- injectData("extension-id", chrome.runtime.id, "body");
- injectScript(chrome.extension.getURL("js/content.js"), "body");
|