-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
71 lines (67 loc) · 2.85 KB
/
index.html
File metadata and controls
71 lines (67 loc) · 2.85 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Frontpage</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="filler"></div>
<div class="rectangle">
<h1>Frontpage</h1>
<form action="https://duckduckgo.com" method="get">
<input type="text" name="q" placeholder="Enter your search here..." required>
<button type="submit">Search</button>
</form>
</div>
<input type="file" id="fileInput" accept="image/*">
</body>
</html>
<script>
const storedImage = localStorage.getItem('backgroundImage');
if (storedImage) {
document.body.style.backgroundImage = `url(${storedImage})`;
setRectangleBackground(storedImage);
}
const fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const imageUrl = e.target.result;
document.body.style.backgroundImage = `url(${imageUrl})`;
localStorage.setItem('backgroundImage', imageUrl);
setRectangleBackground(imageUrl);
};
reader.readAsDataURL(file);
}
});
function setRectangleBackground(imageUrl) {
const img = new Image();
img.src = imageUrl;
img.onload = function() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const pixel = ctx.getImageData(img.width / 2, img.height / 2, 1, 1).data;
const darkenFactor = 0.6;
const darkenedColor = `rgb(${Math.floor(pixel[0] * darkenFactor)}, ${Math.floor(pixel[1] * darkenFactor)}, ${Math.floor(pixel[2] * darkenFactor)})`;
const isCloseToBlack = (pixel[0] < 50 && pixel[1] < 50 && pixel[2] < 50);
document.querySelector('.rectangle').style.backgroundColor = isCloseToBlack ? '#555555' : darkenedColor;
};
}
let elementsVisible = true;
document.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.altKey && event.key === 'h') {
const elements = document.body.querySelectorAll('*:not(script)');
elements.forEach(element => {
element.classList.toggle('hidden');
});
elementsVisible = !elementsVisible;
}
});
</script>