fast72 commited on
Commit
6b5c3aa
·
verified ·
1 Parent(s): 826b37e

Create script.js

Browse files
Files changed (1) hide show
  1. public/script.js +28 -0
public/script.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const editor = CodeMirror.fromTextArea(document.getElementById('code'), {
2
+ mode: "javascript",
3
+ theme: "default",
4
+ lineNumbers: true,
5
+ indentWithTabs: true,
6
+ tabSize: 4,
7
+ matchBrackets: true,
8
+ autoCloseBrackets: true,
9
+ lineWrapping: false
10
+ });
11
+
12
+ document.getElementById('language').addEventListener('change', function() {
13
+ editor.setOption("mode", this.value);
14
+ editor.setValue(`// Hello, ${this.value}!`);
15
+ });
16
+
17
+ document.getElementById('wrapCode').addEventListener('change', function() {
18
+ editor.setOption("lineWrapping", this.checked);
19
+ });
20
+
21
+ function downloadFile() {
22
+ const content = editor.getValue();
23
+ const blob = new Blob([content], { type: "text/plain" });
24
+ const a = document.createElement("a");
25
+ a.href = URL.createObjectURL(blob);
26
+ a.download = "code.txt";
27
+ a.click();
28
+ }