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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<html>
|
2 |
+
|
3 |
+
<head>
|
4 |
+
<base href="https://websim.ai/clock-with-ai/">
|
5 |
+
</base>
|
6 |
+
<title>AI-Powered Clock with Dynamic Backgrounds</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
background-color: #1a1a1a;
|
10 |
+
display: flex;
|
11 |
+
flex-direction: column;
|
12 |
+
justify-content: center;
|
13 |
+
align-items: center;
|
14 |
+
height: 100vh;
|
15 |
+
margin: 0;
|
16 |
+
font-family: Arial, sans-serif;
|
17 |
+
color: #00ff00;
|
18 |
+
transition: background-image 1s ease-in-out;
|
19 |
+
}
|
20 |
+
|
21 |
+
#clock {
|
22 |
+
font-weight: bold;
|
23 |
+
text-shadow: 0 0 10px currentColor;
|
24 |
+
z-index: 10;
|
25 |
+
}
|
26 |
+
|
27 |
+
#settings-btn {
|
28 |
+
position: fixed;
|
29 |
+
top: 10px;
|
30 |
+
right: 10px;
|
31 |
+
background: none;
|
32 |
+
border: none;
|
33 |
+
color: #00ff00;
|
34 |
+
font-size: 24px;
|
35 |
+
cursor: pointer;
|
36 |
+
z-index: 20;
|
37 |
+
}
|
38 |
+
|
39 |
+
#settings-panel {
|
40 |
+
position: fixed;
|
41 |
+
top: 50px;
|
42 |
+
right: 10px;
|
43 |
+
background: rgba(255, 255, 255, 0.9);
|
44 |
+
color: #000;
|
45 |
+
padding: 20px;
|
46 |
+
border-radius: 10px;
|
47 |
+
display: none;
|
48 |
+
z-index: 20;
|
49 |
+
max-width: 300px;
|
50 |
+
max-height: 80vh;
|
51 |
+
overflow-y: auto;
|
52 |
+
}
|
53 |
+
|
54 |
+
#token-input,
|
55 |
+
#prompt-input,
|
56 |
+
#frequency-input,
|
57 |
+
#clock-color-input,
|
58 |
+
#clock-size-input {
|
59 |
+
width: 100%;
|
60 |
+
margin-bottom: 10px;
|
61 |
+
}
|
62 |
+
|
63 |
+
.btn {
|
64 |
+
background-color: #4CAF50;
|
65 |
+
border: none;
|
66 |
+
color: white;
|
67 |
+
padding: 10px 20px;
|
68 |
+
text-align: center;
|
69 |
+
text-decoration: none;
|
70 |
+
display: inline-block;
|
71 |
+
font-size: 16px;
|
72 |
+
margin: 4px 2px;
|
73 |
+
cursor: pointer;
|
74 |
+
border-radius: 5px;
|
75 |
+
}
|
76 |
+
|
77 |
+
#background-image {
|
78 |
+
position: fixed;
|
79 |
+
top: 0;
|
80 |
+
left: 0;
|
81 |
+
width: 100%;
|
82 |
+
height: 100%;
|
83 |
+
object-fit: cover;
|
84 |
+
z-index: 1;
|
85 |
+
}
|
86 |
+
|
87 |
+
label {
|
88 |
+
display: block;
|
89 |
+
margin-top: 10px;
|
90 |
+
margin-bottom: 5px;
|
91 |
+
}
|
92 |
+
|
93 |
+
.checkbox-container {
|
94 |
+
display: flex;
|
95 |
+
align-items: center;
|
96 |
+
margin-top: 10px;
|
97 |
+
}
|
98 |
+
|
99 |
+
.checkbox-container input {
|
100 |
+
margin-right: 10px;
|
101 |
+
}
|
102 |
+
</style>
|
103 |
+
</head>
|
104 |
+
|
105 |
+
<body>
|
106 |
+
<img id="background-image" alt="AI generated abstract landscape based on current time" src="">
|
107 |
+
<div id="clock"></div>
|
108 |
+
<button id="settings-btn">⚙️</button>
|
109 |
+
<div id="settings-panel">
|
110 |
+
<label for="token-input">Hugging Face Token:</label>
|
111 |
+
<input type="text" id="token-input" placeholder="Enter Hugging Face token">
|
112 |
+
|
113 |
+
<label for="prompt-input">Custom Prompt:</label>
|
114 |
+
<textarea id="prompt-input" rows="4" placeholder="Enter custom prompt (use {time} for current time)"></textarea>
|
115 |
+
|
116 |
+
<label for="frequency-input">Image Generation Frequency (minutes):</label>
|
117 |
+
<input type="number" id="frequency-input" placeholder="Image generation frequency (minutes)" min="1" max="60">
|
118 |
+
|
119 |
+
<label for="clock-color-input">Clock Color:</label>
|
120 |
+
<input type="color" id="clock-color-input">
|
121 |
+
|
122 |
+
<label for="clock-size-input">Clock Size (vw):</label>
|
123 |
+
<input type="range" id="clock-size-input" min="1" max="20" step="0.1">
|
124 |
+
<span id="clock-size-value"></span>
|
125 |
+
|
126 |
+
<div class="checkbox-container">
|
127 |
+
<input type="checkbox" id="keep-awake-checkbox">
|
128 |
+
<label for="keep-awake-checkbox">Prevent screen lock (Android)</label>
|
129 |
+
</div>
|
130 |
+
|
131 |
+
<button id="fullscreen-btn" class="btn">Toggle Fullscreen</button>
|
132 |
+
<button id="save-settings" class="btn">Save</button>
|
133 |
+
<button id="test-image" class="btn">Test Image Generation</button>
|
134 |
+
</div>
|
135 |
+
|
136 |
+
<script>
|
137 |
+
let hfToken = localStorage.getItem('hfToken') || '';
|
138 |
+
let customPrompt = localStorage.getItem('customPrompt') || 'beautiful abstract landscape that suits the time {time}';
|
139 |
+
let generationFrequency = parseInt(localStorage.getItem('generationFrequency')) || 3;
|
140 |
+
let clockColor = localStorage.getItem('clockColor') || '#00ff00';
|
141 |
+
let clockSize = parseFloat(localStorage.getItem('clockSize')) || 8;
|
142 |
+
let keepAwake = localStorage.getItem('keepAwake') === 'true';
|
143 |
+
let imageGenerationInterval;
|
144 |
+
let wakeLock = null;
|
145 |
+
|
146 |
+
function updateClock() {
|
147 |
+
const now = new Date();
|
148 |
+
let hours = now.getHours();
|
149 |
+
const minutes = now.getMinutes()
|
150 |
+
.toString()
|
151 |
+
.padStart(2, '0');
|
152 |
+
const seconds = now.getSeconds()
|
153 |
+
.toString()
|
154 |
+
.padStart(2, '0');
|
155 |
+
const ampm = hours >= 12 ? 'PM' : 'AM';
|
156 |
+
|
157 |
+
hours = hours % 12;
|
158 |
+
hours = hours ? hours : 12;
|
159 |
+
hours = hours.toString()
|
160 |
+
.padStart(2, '0');
|
161 |
+
|
162 |
+
const timeString = `${hours}:${minutes}:${seconds} ${ampm}`;
|
163 |
+
const clockElement = document.getElementById('clock');
|
164 |
+
clockElement.textContent = timeString;
|
165 |
+
clockElement.style.color = clockColor;
|
166 |
+
clockElement.style.fontSize = `${clockSize}vw`;
|
167 |
+
|
168 |
+
return `${hours}:${minutes} ${ampm}`;
|
169 |
+
}
|
170 |
+
|
171 |
+
async function generateImage(prompt) {
|
172 |
+
if (!hfToken) return;
|
173 |
+
|
174 |
+
try {
|
175 |
+
const response = await fetch('https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell', {
|
176 |
+
method: 'POST',
|
177 |
+
headers: {
|
178 |
+
'Content-Type': 'application/json',
|
179 |
+
'Authorization': `Bearer ${hfToken}`
|
180 |
+
},
|
181 |
+
body: JSON.stringify({
|
182 |
+
inputs: prompt
|
183 |
+
})
|
184 |
+
});
|
185 |
+
|
186 |
+
if (!response.ok) {
|
187 |
+
throw new Error('Failed to generate image');
|
188 |
+
}
|
189 |
+
|
190 |
+
const blob = await response.blob();
|
191 |
+
const imageUrl = URL.createObjectURL(blob);
|
192 |
+
const backgroundImage = document.getElementById('background-image');
|
193 |
+
|
194 |
+
const newImage = new Image();
|
195 |
+
newImage.onload = function() {
|
196 |
+
URL.revokeObjectURL(backgroundImage.src);
|
197 |
+
backgroundImage.src = this.src;
|
198 |
+
};
|
199 |
+
newImage.src = imageUrl;
|
200 |
+
} catch (error) {
|
201 |
+
console.error('Error generating image:', error);
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
function updateBackgroundImage() {
|
206 |
+
const currentTime = updateClock()
|
207 |
+
.slice(0, -3);
|
208 |
+
const prompt = customPrompt.replace('{time}', currentTime);
|
209 |
+
generateImage(prompt);
|
210 |
+
}
|
211 |
+
|
212 |
+
function initializeSettings() {
|
213 |
+
document.getElementById('token-input')
|
214 |
+
.value = hfToken;
|
215 |
+
document.getElementById('prompt-input')
|
216 |
+
.value = customPrompt;
|
217 |
+
document.getElementById('frequency-input')
|
218 |
+
.value = generationFrequency;
|
219 |
+
document.getElementById('clock-color-input')
|
220 |
+
.value = clockColor;
|
221 |
+
document.getElementById('clock-size-input')
|
222 |
+
.value = clockSize;
|
223 |
+
document.getElementById('clock-size-value')
|
224 |
+
.textContent = clockSize + ' vw';
|
225 |
+
document.getElementById('keep-awake-checkbox')
|
226 |
+
.checked = keepAwake;
|
227 |
+
}
|
228 |
+
|
229 |
+
function toggleFullscreen() {
|
230 |
+
if (!document.fullscreenElement) {
|
231 |
+
document.documentElement.requestFullscreen()
|
232 |
+
.catch(err => console.error(err));
|
233 |
+
} else {
|
234 |
+
if (document.exitFullscreen) {
|
235 |
+
document.exitFullscreen();
|
236 |
+
}
|
237 |
+
}
|
238 |
+
}
|
239 |
+
|
240 |
+
function setupImageGenerationInterval() {
|
241 |
+
clearInterval(imageGenerationInterval);
|
242 |
+
imageGenerationInterval = setInterval(updateBackgroundImage, generationFrequency * 60 * 1000);
|
243 |
+
}
|
244 |
+
|
245 |
+
async function requestWakeLock() {
|
246 |
+
if ('wakeLock' in navigator && keepAwake) {
|
247 |
+
try {
|
248 |
+
wakeLock = await navigator.wakeLock.request('screen');
|
249 |
+
wakeLock.addEventListener('release', () => {
|
250 |
+
console.log('Wake Lock was released');
|
251 |
+
});
|
252 |
+
console.log('Wake Lock is active');
|
253 |
+
} catch (err) {
|
254 |
+
console.error(`${err.name}, ${err.message}`);
|
255 |
+
}
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
async function releaseWakeLock() {
|
260 |
+
if (wakeLock !== null) {
|
261 |
+
await wakeLock.release();
|
262 |
+
wakeLock = null;
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
setInterval(updateClock, 1000);
|
267 |
+
setupImageGenerationInterval();
|
268 |
+
|
269 |
+
updateClock();
|
270 |
+
updateBackgroundImage();
|
271 |
+
initializeSettings();
|
272 |
+
if (keepAwake) requestWakeLock();
|
273 |
+
|
274 |
+
document.getElementById('settings-btn')
|
275 |
+
.addEventListener('click', () => {
|
276 |
+
const panel = document.getElementById('settings-panel');
|
277 |
+
panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
|
278 |
+
});
|
279 |
+
|
280 |
+
document.getElementById('fullscreen-btn')
|
281 |
+
.addEventListener('click', toggleFullscreen);
|
282 |
+
|
283 |
+
document.getElementById('save-settings')
|
284 |
+
.addEventListener('click', async () => {
|
285 |
+
hfToken = document.getElementById('token-input')
|
286 |
+
.value;
|
287 |
+
customPrompt = document.getElementById('prompt-input')
|
288 |
+
.value;
|
289 |
+
generationFrequency = parseInt(document.getElementById('frequency-input')
|
290 |
+
.value);
|
291 |
+
clockColor = document.getElementById('clock-color-input')
|
292 |
+
.value;
|
293 |
+
clockSize = parseFloat(document.getElementById('clock-size-input')
|
294 |
+
.value);
|
295 |
+
keepAwake = document.getElementById('keep-awake-checkbox')
|
296 |
+
.checked;
|
297 |
+
|
298 |
+
localStorage.setItem('hfToken', hfToken);
|
299 |
+
localStorage.setItem('customPrompt', customPrompt);
|
300 |
+
localStorage.setItem('generationFrequency', generationFrequency);
|
301 |
+
localStorage.setItem('clockColor', clockColor);
|
302 |
+
localStorage.setItem('clockSize', clockSize);
|
303 |
+
localStorage.setItem('keepAwake', keepAwake);
|
304 |
+
|
305 |
+
document.getElementById('settings-panel')
|
306 |
+
.style.display = 'none';
|
307 |
+
updateBackgroundImage();
|
308 |
+
setupImageGenerationInterval();
|
309 |
+
updateClock();
|
310 |
+
|
311 |
+
if (keepAwake) {
|
312 |
+
await requestWakeLock();
|
313 |
+
} else {
|
314 |
+
await releaseWakeLock();
|
315 |
+
}
|
316 |
+
});
|
317 |
+
|
318 |
+
document.getElementById('test-image')
|
319 |
+
.addEventListener('click', () => {
|
320 |
+
updateBackgroundImage();
|
321 |
+
});
|
322 |
+
|
323 |
+
document.getElementById('clock-size-input')
|
324 |
+
.addEventListener('input', (e) => {
|
325 |
+
const value = e.target.value;
|
326 |
+
document.getElementById('clock-size-value')
|
327 |
+
.textContent = value + ' vw';
|
328 |
+
clockSize = parseFloat(value);
|
329 |
+
updateClock();
|
330 |
+
});
|
331 |
+
|
332 |
+
document.getElementById('clock-color-input')
|
333 |
+
.addEventListener('input', (e) => {
|
334 |
+
clockColor = e.target.value;
|
335 |
+
updateClock();
|
336 |
+
});
|
337 |
+
|
338 |
+
document.addEventListener('DOMContentLoaded', () => {
|
339 |
+
const settingsBtn = document.getElementById('settings-btn');
|
340 |
+
const newSettingsBtn = settingsBtn.cloneNode(true);
|
341 |
+
settingsBtn.parentNode.replaceChild(newSettingsBtn, settingsBtn);
|
342 |
+
newSettingsBtn.addEventListener('click', () => {
|
343 |
+
const panel = document.getElementById('settings-panel');
|
344 |
+
panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
|
345 |
+
});
|
346 |
+
});
|
347 |
+
|
348 |
+
document.addEventListener('visibilitychange', async () => {
|
349 |
+
if (keepAwake && !document.hidden) {
|
350 |
+
await requestWakeLock();
|
351 |
+
}
|
352 |
+
});
|
353 |
+
</script>
|
354 |
+
</body>
|
355 |
+
|
356 |
+
</html>
|