MCPcopy Create free account
hub / github.com/Justineo/github-hovercard / inject

Function inject

extensions/firefox/background.js:24–59  ·  view source on GitHub ↗
(id, files, type, callback)

Source from the content-addressed store, hash-verified

22let storage = chrome.storage.sync || chrome.storage.local;
23
24function inject(id, files, type, callback) {
25 let injector = INJECTORS[type];
26 if (!injector) {
27 return;
28 }
29
30 // inject code
31 if (typeof files === 'string') {
32 injector(id, {
33 code: files
34 }, callback);
35 return;
36 }
37
38 // inject files
39 let index = 0;
40 let remaining = files.length;
41
42 function injectNext() {
43 if (remaining > 0) {
44 injector(id, {
45 file: files[index]
46 }, () => {
47 console.log('"' + files[index] + '" is injected.');
48 index++;
49 remaining--;
50 injectNext();
51 });
52 } else {
53 if (typeof callback === 'function') {
54 callback();
55 }
56 }
57 }
58 injectNext();
59}
60
61function injectJS(id, content, callback) {
62 inject(id, content, 'js', callback);

Callers 2

injectJSFunction · 0.70
injectCSSFunction · 0.70

Calls 2

injectorFunction · 0.70
injectNextFunction · 0.70

Tested by

no test coverage detected