-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat.html
191 lines (188 loc) · 4.7 KB
/
cat.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
188
189
190
191
<html class="sl-theme-dark">
<head>
<meta content="CLICK ME FOR INFINITE CATTOS!!!" property="og:description" />
<title>Infinite Catto's!</title>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/shoelace-autoloader.js"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/themes/dark.css"
/>
</head>
<body onload="getCatImage()">
<div id="cat-block">
<h1 class="center" id="title">Infinite Catto's!</h1>
<img id="cat" class="center" onload="" alt="click me!" />
<br />
<div id="btns">
<sl-button variant="success" onclick="getCatImage()" id="refresh"
>🐈</sl-button
>
<sl-button variant="danger" onclick="toggleAuto()" id="auto"
>🤖</sl-button
>
<sl-input type="number" value="4" label="Seconds" id="secs"></sl-input>
</div>
</div>
<div id="bottom" onclick="goto('https://hexloc.me')">
made with ♥️ by hexlocation using thecatapi.com
</div>
<p id="credit">
<sl-details summary="Favorites">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</sl-details>
</p>
</body>
</html>
<style>
@import url("https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;500&family=Poppins&display=swap");
img[alt=""] {
display: none;
}
img {
border: none;
}
#secs {
display: none;
}
.break {
flex-basis: 100%;
height: 0;
}
#title {
display: flex;
justify-content: center;
align-items: center;
margin-left: auto;
margin-right: auto;
letter-spacing: 1px;
}
#credit {
color: gray;
max-width: 500px;
display: flex;
position: fixed;
top: 20px;
left: 20px;
}
#bottom:hover {
cursor: grabbing;
}
#bottom {
color: gray;
margin-top: auto;
display: flex;
justify-content: center;
align-items: center;
margin-left: auto;
margin-right: auto;
position: fixed;
bottom: 10px;
left: 30%;
right: 30%;
}
body {
font-family: "Open Sans";
color: white;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
#cat {
margin-top: 10px;
max-width: 25%;
max-height: 25%;
border-radius: 5px;
box-shadow: -20px 20px 10px rgba(0, 0, 0, 0.153);
}
#cat:hover {
cursor: grab;
}
#btns {
display: flex;
width: 100px;
gap: 100px;
align-items: center;
justify-content: center;
margin-left: auto;
margin-right: auto;
}
</style>
<script>
var cat_img = document.getElementById("cat");
cat_img.addEventListener("click", function (e) {
cat_img.requestFullscreen();
});
var catimg;
var autoStat;
function goto(s) {
window.location.href = s;
}
function toggleAuto() {
var btn = document.getElementById("auto");
var secsBox = document.getElementById("secs");
var warning = document.getElementById("warning");
if (autoStat) {
secsBox.style = "display: none !important;";
clearInterval(autoStat);
autoStat = "";
auto.variant = "danger";
} else {
secsBox.style = "display: flex !important;";
autoStat = setInterval(() => {
getCatImage();
}, secsBox.value * 1000);
secsBox.oninput = () => {
console.log("changed!");
clearInterval(autoStat);
autoStat = setInterval(() => {
getCatImage();
}, secsBox.value * 1000);
};
auto.variant = "success";
}
}
function getCatImage() {
document.querySelector("#refresh").disabled = true;
//https://hexloc.me/icons/loading.gif
fetch("https://api.thecatapi.com/v1/images/search")
.then((val) => val.json())
.then((val) => {
var img = document.getElementById("cat");
img.src = val[0].url;
catimg = val[0];
img.onload = function () {
console.log("loaded");
if (img.src.startsWith("https://hexloc.me")) return;
document.querySelector("#refresh").disabled = false;
};
});
}
function vote(vote_val) {
var body = { image_id: id };
if (vote_val) {
body["value"] = 1;
} else {
body["value"] = -1;
}
fetch("https://api.thecatapi.com/v1/votes", {
method: "POST",
body: JSON.stringify(body),
headers: {
"x-api-key": "x",
},
})
.then((val) => val.text())
.then((val) => {
console.log(val);
getCatImage();
});
}
</script>