-
Notifications
You must be signed in to change notification settings - Fork 12
/
injector.minify.js
61 lines (54 loc) · 1.75 KB
/
injector.minify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Babel plugin to transform functions and calls
const ASYNC_PLUGIN_1 = function ({ types: t }) {
return {
visitor: {
FunctionDeclaration(path) {
console.log(path);
path.node.async = true;
},
ArrowFunctionExpression(path) {
console.log(path);
path.node.async = true;
},
CallExpression(path) {
console.log(path);
if (path.parent.type !== 'AwaitExpression') {
path.replaceWith(
t.awaitExpression(path.node)
);
}
}
}
};
};
async function shronk(input) {
let isHtml = true;
let inputHtml = input;
// Check if the input is raw JavaScript
if (!input.trim().startsWith('<')) {
isHtml = false;
inputHtml = `<script>${input}</script>`;
}
_status("[ASYNC_PLUGIN_1] Parsing html...");
await wait(50);
const parser = new DOMParser();
const doc = parser.parseFromString(inputHtml, 'text/html');
const scriptTags = doc.querySelectorAll('script');
for (let i = 0; i < scriptTags.length; i++) {
const scriptTag = scriptTags[i];
const code = scriptTag.textContent;
_status("[ASYNC_PLUGIN_1] Transpiling script #" + (i + 1) + " of length " + Math.round(code.length / 1000) + "k...");
await wait(50);
const output = Babel.transform(code, {
plugins: []
});
scriptTag.textContent = output.code;
}
_status("[ASYNC_PLUGIN_1] Job complete!");
await wait(50);
if (isHtml) {
return doc.documentElement.outerHTML;
} else {
return doc.querySelector('script').textContent;
}
}