Skip to content

Commit d5ce2a4

Browse files
committed
Wrapped injector script into function
1 parent 45a5f54 commit d5ce2a4

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/plugin-append-script.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
*/
1010

1111
// see if script tag exists
12-
let scrptExists = document.querySelector('script#ReloadSite');
12+
(function () {
13+
let scriptExists = document.querySelector('script#ReloadSite');
1314

14-
if (!scrptExists) {
15-
// get document body
16-
let body = document.querySelector('body,html');
15+
if (!scriptExists) {
16+
// get document body
17+
let body = document.querySelector('body,html');
1718

18-
if (body) {
19-
// create tag
20-
let tag = document.createElement('script');
21-
tag.src = 'http://127.0.0.1:{PORT}/reloadsite.js';
22-
tag.id = 'ReloadSite';
23-
body.append(tag);
24-
} else {
25-
console.warn('HTML document has no body or html tag!');
19+
if (body) {
20+
// create tag
21+
let tag = document.createElement('script');
22+
tag.src = 'http://127.0.0.1:{PORT}/reloadsite.js';
23+
tag.id = 'ReloadSite';
24+
body.append(tag);
25+
} else {
26+
console.warn('HTML document has no body or html tag!');
27+
}
2628
}
27-
}
29+
})();

0 commit comments

Comments
 (0)