Skip to content

Commit 00f7b4a

Browse files
author
hoang.tran12
committed
refactor
1 parent 520187c commit 00f7b4a

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

scripts/content-scripts/document_start.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,4 @@
1-
// https://stackoverflow.com/a/70949953
2-
// https://stackoverflow.com/a/9517879
3-
// https://stackoverflow.com/a/2920207/11898496
4-
51
(async () => {
6-
// https://stackoverflow.com/a/8578840/11898496
7-
function injectScript(
8-
src,
9-
onload,
10-
type = "text/javascript",
11-
async = false,
12-
defer = false
13-
) {
14-
let s = document.createElement("script");
15-
s.type = type;
16-
s.async = async;
17-
s.defer = defer;
18-
s.addEventListener("load", () => {
19-
console.log("Useful-scripts injected " + src);
20-
onload?.();
21-
s.remove();
22-
});
23-
s.src = src;
24-
let head =
25-
document.head ||
26-
document.getElementsByTagName("head")[0] ||
27-
document.documentElement;
28-
head.insertBefore(s, head.firstChild);
29-
// (document.head || document.documentElement).prepend(s);
30-
}
31-
322
injectScript(
333
chrome.runtime.getURL(
344
"/scripts/content-scripts/scripts/ufs_global_webpage_context.js"
@@ -81,3 +51,33 @@
8151
console.log("ERROR: ", e);
8252
}
8353
})();
54+
55+
// https://stackoverflow.com/a/70949953
56+
// https://stackoverflow.com/a/9517879
57+
// https://stackoverflow.com/a/2920207/11898496
58+
59+
// https://stackoverflow.com/a/8578840/11898496
60+
function injectScript(
61+
src,
62+
onload,
63+
type = "text/javascript",
64+
async = false,
65+
defer = false
66+
) {
67+
let s = document.createElement("script");
68+
s.type = type;
69+
s.async = async;
70+
s.defer = defer;
71+
s.addEventListener("load", () => {
72+
console.log("Useful-scripts injected " + src);
73+
onload?.();
74+
s.remove();
75+
});
76+
s.src = src;
77+
let head =
78+
document.head ||
79+
document.getElementsByTagName("head")[0] ||
80+
document.documentElement;
81+
head.insertBefore(s, head.firstChild);
82+
// (document.head || document.documentElement).prepend(s);
83+
}

0 commit comments

Comments
 (0)