-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
65 lines (55 loc) · 1.78 KB
/
script.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
62
63
64
65
const runCode = async () => {
const code = document.getElementById('code-area').value;
const output = document.getElementById('output');
output.textContent = '';
try {
const oldLog = console.log;
console.log = (...args) => {
output.textContent += args.join(' ') + '\n';
oldLog.apply(console, args);
};
const script = new Function(`return (async () => { ${code} })()`);
await script();
console.log = oldLog;
} catch (error) {
output.textContent = 'Error: ' + error.message;
}
};
const redirectToLink = () => {
window.location.href = 'https://github.com/DarkRai087';
};
const clearCode = () => {
document.getElementById('code-area').value = '';
document.getElementById('output').textContent = '';
};
const copyCode = () => {
const codeArea = document.getElementById('code-area');
codeArea.select();
codeArea.setSelectionRange(0, 99999);
document.execCommand('copy');
};
const impCode = () => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.txt,.js';
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const contents = e.target.result;
document.getElementById('code-area').value = contents;
};
reader.readAsText(file);
}
});
fileInput.click();
};
const formatCode = () => {
const codeArea = document.getElementById('code-area');
const formattedCode = prettier.format(codeArea.value, {
parser: "babel",
plugins: prettierPlugins,
});
codeArea.value = formattedCode;
};