mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
28 lines
724 B
TypeScript
28 lines
724 B
TypeScript
export const injectScripts = (scripts: string[], cb?: () => void) => {
|
|
let injected = 0;
|
|
scripts.forEach(s =>
|
|
injectScript(chrome.runtime.getURL(s), () => {
|
|
injected++;
|
|
if (injected === scripts.length && cb) {
|
|
cb();
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
const injectScript = (scriptName: string, cb: () => void) => {
|
|
const src = `
|
|
(function() {
|
|
var script = document.constructor.prototype.createElement.call(document, 'script');
|
|
script.src = "${scriptName}";
|
|
document.documentElement.appendChild(script);
|
|
script.parentNode.removeChild(script);
|
|
})()
|
|
`;
|
|
chrome.devtools.inspectedWindow.eval(src, (_, err) => {
|
|
if (err) {
|
|
console.log(err);
|
|
}
|
|
cb();
|
|
});
|
|
};
|