This repository has been archived by the owner on Jul 29, 2023. It is now read-only.
forked from kencx/startpage
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.html
187 lines (169 loc) · 6.51 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>~/startpage</title>
<link rel="stylesheet" type="text/css" href="style.css">
<!-- google fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<!-- anime.js -->
<script defer="" src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
</head>
<body>
<header>
<div id="img">
<img src="image.gif" />
</div>
</header>
<main>
<div id="content">
<div id="head">
<form action="https://duckduckgo.com/">
<label for="q" autofocus>> find / </label>
<input type="text" name="q" autocomplete="off">
</form>
<div id="info">
<p id="weatherDesc">Loading...</p>
<p id="temp">Loading...</p>
</div>
</div>
<div id="links">
<section>
<h3>section header</h3>
<ul>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
</ul>
</section>
<section>
<h3>section header</h3>
<ul>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
</ul>
</section>
<section>
<h3>section header</h3>
<ul>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
</ul>
</section>
<section>
<h3>section header</h3>
<ul>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
<li><a href="https://example.com">website text</a></li>
</ul>
</section>
</div>
</div>
</main>
<footer>
<a href="https://github.com/eaaasun/startpage">Github</a>
</footer>
<script type="module">
// ----- CHANGE THESE VARIABLES
// Do you want to show the weather?
const weather = true;
// Do you want animations?
const animated = true;
// Read the documentation for setting the weather API key
const apiKey = "[API KEY]";
const lat = 40.7127861;
const lon = -74.0134275;
const units = "imperial";
// ----- DON'T TOUCH ANYTHING BELOW THIS UNLESS YOU KNOW WHAT YOU'RE DOING
var weatherEl = document.getElementById("weatherDesc");
var tempEl = document.getElementById("temp");
if (weather) {
var apiLink =
"https://api.openweathermap.org/data/2.5/weather?lat=" +
lat +
"&lon=" +
lon +
"&units=" +
units +
"&appid=" +
apiKey;
console.log(apiLink);
// grabs json data from url, thanks https://stackoverflow.com/a/35970894
var getJSON = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "json";
xhr.onload = function () {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
// gets city name from weather api
getJSON(apiLink, function (err, data) {
if (err !== null) {
weatherEl.innerText = "";
tempEl.innerText = "";
} else {
var city = data.name;
var temp = data.main.temp;
var hiTemp = data.main.temp_max;
var loTemp = data.main.temp_min;
var weatherDesc = data.weather[0].description;
weatherEl.innerHTML =
weatherDesc + " in " + city;
tempEl.innerHTML = "h: " + hiTemp + "° / c: " + temp + "° / l: " + loTemp + "°";
}
});
} else {
weatherEl.innerText = "";
tempEl.innerText = "";
}
if (animated) {
// hides all elements
document.querySelectorAll("*").forEach(el => el.style.opacity = 0);
// anime.js animation function
function playAnimation() {
var tl = anime.timeline({
easing: "easeInOutExpo",
duration: 2000,
});
tl.add({
targets: "#img",
opacity: [0, 1],
translateY: [100, 0],
})
.add(
{
targets: "#img",
width: ["100%", "60%"],
},
"-=1200"
)
.add(
{
targets: "main *",
opacity: [0, 1],
translateY: [10, 0],
delay: anime.stagger(15),
},
"-=1800"
);
}
window.onload = function () {
document.querySelectorAll("*").forEach(el => el.style.opacity = 1);
playAnimation();
}
}
</script>
</body>
</html>