-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
80 lines (73 loc) · 2.67 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Background Demo</title>
<style>
html,
body {
width: 100vw;
height: 100vh;
margin: 0;
background: linear-gradient(to bottom, #1D1D1F, #000);
display: grid;
justify-content: center;
align-items: center;
color: #1D1D1F;
user-select: none;
user-zoom: none;
}
body>*,
body>form>input {
outline: 0;
border-radius: 25px;
background-color: #F5F5F7;
padding: 1vh 1vw 1vh 1vw;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font: min(2vh, 2vw);
border: none;
text-align: center;
cursor: pointer;
min-width: min(6vh, 6vw);
min-height: min(3vh, 3vw);
}
</style>
<script type="module">
import { getGradientFromUrl } from "https://cdn.jsdelivr.net/gh/NacreousDawn596/dynamic-background@master/main.js";
window.addEventListener('load', async evl => {
document.getElementsByTagName("form")[0]?.addEventListener('submit', async e => {
e.preventDefault();
const gradient = await getGradientFromUrl(e.currentTarget.url.value);
console.log(gradient);
document.body.style.background = gradient;
});
document.getElementsByTagName('button')[0]?.addEventListener('click', async ebl => {
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = "image/*";
fileInput.style.display = "none";
fileInput.click();
fileInput.addEventListener('change', () => {
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = async (event) => {
const gradient = await getGradientFromUrl(event.target.result);
console.log(gradient);
document.body.style.background = gradient;
};
reader.readAsDataURL(file);
}
});
});
});
</script>
</head>
<body>
<form>
<input type="text" name="url" placeholder="paste an image url" id="">
</form>
<button type="button">Upload a picture</button>
</body>
</html>