DHEIVER commited on
Commit
534b72e
·
verified ·
1 Parent(s): 4d0ad85

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +49 -23
script.js CHANGED
@@ -1,29 +1,28 @@
1
  // Theme Toggle
2
- const themeSwitch = document.getElementById('theme-switch');
3
- themeSwitch.addEventListener('click', () => {
4
  document.body.classList.toggle('light');
5
- themeSwitch.textContent = document.body.classList.contains('light') ? '☀️' : '🌙';
6
  });
7
 
8
  // Query Submission
9
  document.getElementById('submit-query').addEventListener('click', () => {
10
  const query = document.getElementById('query-input').value.trim();
11
  if (!query) {
12
- alert('Please enter a query.');
13
  return;
14
  }
15
 
16
- // Simulate loading state
17
  const responseOutput = document.getElementById('response-output');
18
  const contextOutput = document.getElementById('context-output');
19
- responseOutput.innerHTML = '<p class="loading">Generating response...</p>';
20
- contextOutput.innerHTML = '<p class="loading">Retrieving context...</p>';
21
 
22
- // Simulate API response (replace with actual backend integration)
23
  setTimeout(() => {
24
- responseOutput.innerHTML = `<p>Response to: ${query}</p>`;
25
  contextOutput.innerHTML = `<p>Context for: ${query}</p>`;
26
- }, 1500);
27
  });
28
 
29
  // Apply Settings
@@ -33,18 +32,45 @@ document.getElementById('apply-settings').addEventListener('click', () => {
33
  const temperature = document.getElementById('temperature').value;
34
  const contextLength = document.getElementById('context-length').value;
35
 
36
- // Simulate settings application
37
- const settingsOutput = `Settings applied: Model=${model}, Top-K=${topK}, Temperature=${temperature}, Context Length=${contextLength}`;
38
- console.log(settingsOutput);
39
- alert(settingsOutput);
40
  });
41
 
42
- // Smooth scroll for better UX
43
- document.querySelectorAll('a[href^="#"]').forEach(anchor => {
44
- anchor.addEventListener('click', (e) => {
45
- e.preventDefault();
46
- document.querySelector(anchor.getAttribute('href')).scrollIntoView({
47
- behavior: 'smooth'
48
- });
49
- });
50
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  // Theme Toggle
2
+ const themeToggle = document.getElementById('theme-toggle');
3
+ themeToggle.addEventListener('click', () => {
4
  document.body.classList.toggle('light');
 
5
  });
6
 
7
  // Query Submission
8
  document.getElementById('submit-query').addEventListener('click', () => {
9
  const query = document.getElementById('query-input').value.trim();
10
  if (!query) {
11
+ showFeedback('Please enter a query.', 'error');
12
  return;
13
  }
14
 
15
+ // Show loading state
16
  const responseOutput = document.getElementById('response-output');
17
  const contextOutput = document.getElementById('context-output');
18
+ responseOutput.innerHTML = '<p class="loading">Processing...</p>';
19
+ contextOutput.innerHTML = '<p class="loading">Retrieving...</p>';
20
 
21
+ // Simulate API call (replace with actual backend integration)
22
  setTimeout(() => {
23
+ responseOutput.innerHTML = `<p>Response for: ${query}</p>`;
24
  contextOutput.innerHTML = `<p>Context for: ${query}</p>`;
25
+ }, 1200);
26
  });
27
 
28
  // Apply Settings
 
32
  const temperature = document.getElementById('temperature').value;
33
  const contextLength = document.getElementById('context-length').value;
34
 
35
+ const settings = `Model: ${model}, Top-K: ${topK}, Temperature: ${temperature}, Context Length: ${contextLength}`;
36
+ showFeedback(`Settings updated: ${settings}`, 'success');
 
 
37
  });
38
 
39
+ // Feedback Function
40
+ function showFeedback(message, type) {
41
+ const feedback = document.createElement('div');
42
+ feedback.className = `feedback feedback-${type}`;
43
+ feedback.textContent = message;
44
+ document.body.appendChild(feedback);
45
+ setTimeout(() => {
46
+ feedback.style.opacity = '0';
47
+ setTimeout(() => feedback.remove(), 300);
48
+ }, 2000);
49
+ }
50
+
51
+ // Dynamic Loading Styles
52
+ const style = document.createElement('style');
53
+ style.textContent = `
54
+ .loading {
55
+ opacity: 0.7;
56
+ font-style: italic;
57
+ }
58
+ .feedback {
59
+ position: fixed;
60
+ bottom: 20px;
61
+ right: 20px;
62
+ padding: 12px 24px;
63
+ border-radius: 8px;
64
+ color: #fff;
65
+ font-size: 0.9em;
66
+ transition: opacity 0.3s;
67
+ z-index: 1000;
68
+ }
69
+ .feedback-success {
70
+ background: #00c4ff;
71
+ }
72
+ .feedback-error {
73
+ background: #ff4d4d;
74
+ }
75
+ `;
76
+ document.head.appendChild(style);