Moniquekeys95 commited on
Commit
6f3e28d
·
verified ·
1 Parent(s): dd9f776

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +186 -18
index.html CHANGED
@@ -1,19 +1,187 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>JavaScript Code Analyzer</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
9
+ <script src="https://unpkg.com/[email protected]/dist/jshint.js"></script>
10
+ </head>
11
+ <body class="bg-gray-100 p-8">
12
+ <div class="container mx-auto">
13
+ <h1 class="text-3xl font-bold mb-6 text-center">
14
+ JavaScript Code Analysis Tool
15
+ </h1>
16
+
17
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
18
+ <!-- Code Editor -->
19
+ <div>
20
+ <h2 class="text-xl font-semibold mb-4">Input JavaScript Code</h2>
21
+ <div
22
+ id="editor"
23
+ class="h-96 border rounded-lg"
24
+ >// Paste your JavaScript code here
25
+ function exampleFunction() {
26
+ // Your code goes here
27
+ }
28
+ </div>
29
+ </div>
30
+
31
+ <!-- Results Panel -->
32
+ <div>
33
+ <h2 class="text-xl font-semibold mb-4">Analysis Results</h2>
34
+ <div
35
+ id="analysisResults"
36
+ class="bg-white border rounded-lg p-4 h-96 overflow-y-auto"
37
+ >
38
+ <div id="lintingErrors" class="mb-4">
39
+ <h3 class="font-bold text-red-600">Linting Errors</h3>
40
+ </div>
41
+ <div id="consoleOutput">
42
+ <h3 class="font-bold text-green-600">Console Output</h3>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ </div>
47
+
48
+ <!-- Action Buttons -->
49
+ <div class="flex justify-center space-x-4 mt-6">
50
+ <button
51
+ id="lintButton"
52
+ class="bg-yellow-500 text-white px-6 py-2 rounded hover:bg-yellow-600"
53
+ >
54
+ Lint Code
55
+ </button>
56
+ <button
57
+ id="runButton"
58
+ class="bg-blue-500 text-white px-6 py-2 rounded hover:bg-blue-600"
59
+ >
60
+ Run Code
61
+ </button>
62
+ <button
63
+ id="autoFixButton"
64
+ class="bg-green-500 text-white px-6 py-2 rounded hover:bg-green-600"
65
+ >
66
+ Auto Fix
67
+ </button>
68
+ </div>
69
+ </div>
70
+
71
+ <script>
72
+ const editor = ace.edit("editor");
73
+ editor.setTheme("ace/theme/monokai");
74
+ editor.session.setMode("ace/mode/javascript");
75
+ editor.setOptions({
76
+ enableBasicAutocompletion: true,
77
+ enableSnippets: true,
78
+ enableLiveAutocompletion: true
79
+ });
80
+
81
+ document.getElementById('lintButton').addEventListener('click', () => {
82
+ const code = editor.getValue();
83
+ const lintingErrors = document.getElementById('lintingErrors');
84
+ lintingErrors.innerHTML = '<h3 class="font-bold text-red-600">Linting Errors</h3>';
85
+
86
+ JSHINT(code, {
87
+ esversion: 6,
88
+ asi: true,
89
+ unused: true,
90
+ globals: {
91
+ console: true,
92
+ window: true,
93
+ document: true
94
+ }
95
+ });
96
+
97
+ if (JSHINT.errors.length > 0) {
98
+ JSHINT.errors.forEach((error, index) => {
99
+ if (error) {
100
+ const errorEl = document.createElement('div');
101
+ errorEl.innerHTML = `
102
+ <span class="text-red-500">Error ${index + 1}:</span>
103
+ Line ${error.line}: ${error.reason}
104
+ `;
105
+ errorEl.className = 'mt-2 p-2 bg-red-50 rounded';
106
+ lintingErrors.appendChild(errorEl);
107
+ }
108
+ });
109
+ } else {
110
+ const successEl = document.createElement('div');
111
+ successEl.textContent = '✅ No linting errors found!';
112
+ successEl.className = 'text-green-600 mt-2';
113
+ lintingErrors.appendChild(successEl);
114
+ }
115
+ });
116
+
117
+ document.getElementById('runButton').addEventListener('click', () => {
118
+ const consoleOutput = document.getElementById('consoleOutput');
119
+ consoleOutput.innerHTML = '<h3 class="font-bold text-green-600">Console Output</h3>';
120
+
121
+ try {
122
+ const code = editor.getValue();
123
+
124
+ const originalLog = console.log;
125
+ const logs = [];
126
+ console.log = (...args) => {
127
+ logs.push(args.map(arg =>
128
+ typeof arg === 'object' ? JSON.stringify(arg) : arg
129
+ ).join(' '));
130
+ };
131
+
132
+ const runCode = new Function('console', code);
133
+ runCode(console);
134
+
135
+ console.log = originalLog;
136
+
137
+ logs.forEach(log => {
138
+ const logEl = document.createElement('div');
139
+ logEl.textContent = log;
140
+ consoleOutput.appendChild(logEl);
141
+ });
142
+ } catch (error) {
143
+ const errorEl = document.createElement('div');
144
+ errorEl.innerHTML = `
145
+ <span class="text-red-500">🚨 Execution Error:</span>
146
+ ${error.message}
147
+ `;
148
+ errorEl.className = 'mt-2 p-2 bg-red-50 rounded';
149
+ consoleOutput.appendChild(errorEl);
150
+ }
151
+ });
152
+
153
+ document.getElementById('autoFixButton').addEventListener('click', () => {
154
+ const code = editor.getValue();
155
+ const lintingErrors = document.getElementById('lintingErrors');
156
+ lintingErrors.innerHTML = '<h3 class="font-bold text-green-600">Auto-Fix Suggestions</h3>';
157
+
158
+ let fixedCode = code;
159
+
160
+ // Basic auto-fix strategies
161
+ fixedCode = fixedCode.replace(/([^;])\s*$/gm, '$1;');
162
+
163
+ const unclosedStringRegex = /([`'"])[^'"]*$/gm;
164
+ if (unclosedStringRegex.test(fixedCode)) {
165
+ fixedCode = fixedCode.replace(unclosedStringRegex, '$1');
166
+ }
167
+
168
+ const undefinedVarRegex = /\b(\w+)\s*=[^;]+;(?!\s*const|\s*let|\s*var)/g;
169
+ fixedCode = fixedCode.replace(undefinedVarRegex, 'let $1 = $&');
170
+
171
+ editor.setValue(fixedCode, -1);
172
+
173
+ const suggestionsEl = document.createElement('div');
174
+ suggestionsEl.innerHTML = `
175
+ ✅ Auto-Fixed:
176
+ <ul>
177
+ <li>• Added missing semicolons</li>
178
+ <li>• Closed unclosed strings</li>
179
+ <li>• Declared potential undefined variables</li>
180
+ </ul>
181
+ `;
182
+ suggestionsEl.className = 'mt-2 p-2 bg-green-50 rounded';
183
+ lintingErrors.appendChild(suggestionsEl);
184
+ });
185
+ </script>
186
+ </body>
187
  </html>