-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI-Assistant.html
More file actions
239 lines (213 loc) · 12.2 KB
/
AI-Assistant.html
File metadata and controls
239 lines (213 loc) · 12.2 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>AI Assistant - MyScratchBlocks - A Scratch & TurboWarp Modification</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #f8fafc;
color: #334155;
}
.loading-spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 24px;
height: 24px;
animation: spin 1s linear infinite;
display: inline-block;
vertical-align: middle;
margin-left: 8px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body class="antialiased">
<header class="bg-white shadow-sm py-4">
<div class="container mx-auto px-4 flex justify-between items-center">
<a href="#" class="flex items-center space-x-2 text-2xl font-bold text-indigo-600">
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15h2v-6h-2v6zm0-8h2V7h-2v2z"/>
</svg>
<span>MyScratchBlocks</span>
</a>
<nav class="hidden md:flex space-x-6">
<a href="/" class="text-gray-600 hover:text-indigo-600 font-medium">Home</a>
<a href="/#features" class="text-gray-600 hover:text-indigo-600 font-medium">Features</a>
<a href="/#block-ideas" class="text-gray-600 hover:text-indigo-600 font-medium">Block Ideas</a>
<a href="/#project-ideas" class="text-gray-600 hover:text-indigo-600 font-medium">Project Ideas</a>
<a href="/#featured-projects" class="text-gray-600 hover:text-indigo-600 font-medium">Featured Projects</a>
<a href="/#access" class="text-gray-600 hover:text-indigo-600 font-medium">Access</a>
<a href="/#community" class="text-gray-600 hover:text-indigo-600 font-medium">Community</a>
<a href="/#about" class="text-gray-600 hover:text-indigo-600 font-medium">About</a>
<a id="account" href="account" class="text-gray-600 hover:text-indigo-600 font-medium">Account</a>
</nav>
</div>
</header>
<section id="home" class="bg-gradient-to-r from-indigo-500 to-purple-600 text-white py-20 px-4 text-center rounded-b-lg shadow-lg">
<div class="container mx-auto max-w-4xl">
<h1 class="text-4xl sm:text-5xl md:text-6xl font-extrabold leading-tight mb-6">
MyScratchBlocks<br class="hidden sm:inline"> AI<br class="hidden sm:inline">Coding Assistant
</h1>
<h2>Need help? Ask the AI Bot to debug code and more!</h2>
</div>
</section>
<section id="project-ideas" class="py-16 px-4 bg-white">
<div class="container mx-auto max-w-4xl text-center">
<h2 class="text-3xl sm:text-4xl font-bold mb-8 text-gray-800">✨ Coding Assistant (powered by AI) ✨</h2>
<p class="text-lg text-gray-600 mb-6">
Need help with MyScratchBlocks? Just ask our AI Assistant! For example, there may be a bug in your code. Make sure to tell the code that's not working it in text format! But, there is no limit of what you can use it for (but you can't use it for illegal or rule-breaking things)
</p>
<div class="bg-gray-50 p-6 rounded-lg shadow-md">
<textarea id="project-idea-input" class="w-full p-4 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500 mb-4 h-32 resize-y" placeholder="e.g., 'How do I code this: [enter coding problem here], 'What extensions does MyScratchBlocks have?'"></textarea>
<button id="generate-project-idea" class="bg-indigo-600 text-white hover:bg-indigo-700 font-bold py-3 px-6 rounded-full shadow-lg transition-all duration-300 transform hover:scale-105 inline-flex items-center justify-center">
Send Message
<span id="project-idea-spinner" class="loading-spinner hidden"></span>
</button>
<div id="project-idea-output" class="mt-6 p-4 bg-green-50 border border-green-200 text-green-800 rounded-md text-left whitespace-pre-wrap">
Hello! I am an AI Assistant that can help you with MyScratchBlocks. If you would of talked to me, the chat results would appear here.
</div>
</div>
</div>
</section>
<script>
async function fetchFeaturedProjects() {
const projectsContainer = document.getElementById('projects-container');
const projectsLoading = document.getElementById('projects-loading');
const projectsError = document.getElementById('projects-error');
projectsLoading.classList.remove('hidden');
projectsError.classList.add('hidden');
projectsContainer.innerHTML = '';
const PROJECTS_API_URL = 'https://corsproxy.io/?url=https://editor-compiler.onrender.com/api/projects';
try {
const response = await fetch(PROJECTS_API_URL);
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
const projects = await response.json();
if (!projects || projects.length === 0) {
projectsContainer.innerHTML = '<p class="col-span-full text-gray-600">No featured projects available at the moment.</p>';
return;
}
projects.forEach(project => {
const projectCard = document.createElement('div');
projectCard.className = 'bg-white p-6 rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 transform hover:-translate-y-1';
projectCard.innerHTML = `
<img src="${project.image}" alt="${project.name} thumbnail" class="w-full h-40 object-cover rounded-md mb-4">
<h3 class="text-xl font-semibold text-gray-700 mb-2">${project.name}</h3>
<p class="text-gray-600 text-sm mb-4">Genre: ${project.genre}</p>
<a href="${project.link}" class="text-indigo-600 hover:text-indigo-800 font-medium inline-flex items-center">
View Project
<svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
</svg>
</a>
`;
projectsContainer.appendChild(projectCard);
});
} catch (error) {
console.error('Error fetching featured projects:', error);
projectsError.classList.remove('hidden');
projectsError.textContent = `Failed to load projects. Please try again later. (Error: ${error.message})`;
} finally {
projectsLoading.classList.add('hidden');
}
}
async function fetchRecentProjects() {
const projectsContainer = document.getElementById('recent-projects-container');
const projectsLoading = document.getElementById('recent-projects-loading');
const projectsError = document.getElementById('recent-projects-error');
projectsLoading.classList.remove('hidden');
projectsError.classList.add('hidden');
projectsContainer.innerHTML = '';
const PROJECTS_API_URL = 'https://corsproxy.io/?url=https://editor-compiler.onrender.com/api/projects';
try {
const response = await fetch(PROJECTS_API_URL);
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
const projects = await response.json();
if (!projects || projects.length === 0) {
projectsContainer.innerHTML = '<p class="col-span-full text-gray-600">No recently uploaded projects available at the moment. Try uploadjng a project and your project will appear here!</p>';
return;
}
projects.forEach(project => {
const projectCard = document.createElement('div');
projectCard.className = 'bg-white p-6 rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 transform hover:-translate-y-1';
projectCard.innerHTML = `
<img src="${project.image}" alt="${project.name} thumbnail" class="w-full h-40 object-cover rounded-md mb-4">
<h3 class="text-xl font-semibold text-gray-700 mb-2">${project.name}</h3>
<p class="text-gray-600 text-sm mb-4">Genre: ${project.genre}</p>
<a href="${project.link}" class="text-indigo-600 hover:text-indigo-800 font-medium inline-flex items-center">
View Project
<svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
</svg>
</a>
`;
projectsContainer.appendChild(projectCard);
});
} catch (error) {
console.error('Error fetching recent projects:', error);
projectsError.classList.remove('hidden');
projectsError.textContent = `Failed to recent load projects. Please try again later. (Error: ${error.message})`;
} finally {
projectsLoading.classList.add('hidden');
}
}
// Gemini API Integration – Project Idea Brainstormer
const projectIdeaInput = document.getElementById('project-idea-input');
const generateProjectIdeaButton = document.getElementById('generate-project-idea');
const projectIdeaOutput = document.getElementById('project-idea-output');
const projectIdeaSpinner = document.getElementById('project-idea-spinner');
if (generateProjectIdeaButton) {
generateProjectIdeaButton.addEventListener('click', async () => {
const prompt = projectIdeaInput.value.trim();
if (!prompt) {
projectIdeaOutput.textContent = "Hello There! What do you need help with? Your response seems blank.";
return;
}
projectIdeaOutput.textContent = "We are contacting the AI Assistant, and the AI Assistant will respond shortly...";
projectIdeaSpinner.classList.remove('hidden');
generateProjectIdeaButton.disabled = true;
try {
const chatHistory = [{
role: "user",
parts: [{
text: `You are a AI Assistant designed to help people with coding in the MyScratchBlocks Scratch Mod (which is a mod of TurbroWarp, make sure to get info from there as well). But today, your job is to respond to the following prompt generated by a coder using MyScratchBlocks: "${prompt}".`
}]
}];
const payload = { contents: chatHistory };
const apiKey = "AIzaSyBVZwRE3rId" + "UZqgVeSy5RcmUn-adMhwimI"; // Key injected at runtime
const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${apiKey}`;
const response = await fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const result = await response.json();
const text = result?.candidates?.[0]?.content?.parts?.[0]?.text;
projectIdeaOutput.textContent = text || "Failed to contact the AI Assistant to help you with your prompts. We still want to help you, so please, Please try again.";
} catch (error) {
projectIdeaOutput.textContent = "Failed to contact the AI Assistant to help you with your prompts. We still want to help you, so please, Please try again. I think this may be about bad Wi-Fi, So Please Check your connection.";
console.error("Gemini API error (AI AssistNt):", error);
} finally {
projectIdeaSpinner.classList.add('hidden');
generateProjectIdeaButton.disabled = false;
}
});
}
// Fetch projects after DOM loads
document.addEventListener('DOMContentLoaded', fetchFeaturedProjects);
const username = localStorage.getItem('username');
if (username) {
const accountElement = document.getElementById('account');
if (accountElement) {
}
}
</script>
</body>
</html>