-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
149 lines (142 loc) · 4.75 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
<html>
<head>
<title>wholesome!</title>
<link
href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="mobile.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="intro_card">
<h1>happeer</h1>
<p>✨bringing some much needed happiness to the internet! ✨</p>
<p>press space or click for more happiness</p>
<hr />
</div>
<div id="main_card">
<div id="loader">
<div class="hollowLoader">
<div class="largeBox"></div>
<div class="smallBox"></div>
</div>
</div>
<div class="content_zone" id="content_zone"></div>
</div>
<div class="loadContainter" id="load_more">
<button class="loadMore" onclick="nextPost()">more happiness</button>
</div>
<footer id="footer_u">
<p>made with ❤️ by lucas and zach</p>
<p>forked from jacky zhao 2019</p>
</footer>
<script>
nextPost()
function clearContent() {
document.getElementById("content_zone").innerHTML = "";
}
function insertContent(post) {
let div = document.getElementById("content_zone");
let insert = "";
let wasVideo = false;
const uuid = uuidv4();
let source = "";
if (post.is_video) {
wasVideo = true;
source = post.v_url;
insert = `<video controls loop class="vid" id='${uuid}'>
</video>
`;
} else {
if (post.url.includes("gifv")) {
wasVideo = true;
source = post.url.replace(".gifv", ".mp4");
insert = `<video controls loop class="vid" id='${uuid}>
</video>
`;
} else if (post.url.includes("m.imgur.com")) {
wasVideo = true;
source =
"http://i.imgur.com/" + post.url.split("/").slice(-1)[0] + ".mp4";
insert = `<video controls loop class="vid" id='${uuid}>
</video>
`;
} else if (post.url.includes("gfycat")) {
wasVideo = true;
source =
"https://giant.gfycat.com/" +
post.gfy.split("%2F")[10].split("-")[0] +
".mp4";
insert = `<video controls loop class="vid" id='${uuid} >
</video>
`;
} else {
insert = `<img class="img" id='${uuid}' src='${post.url}''></img>`;
}
}
var normalHTML = `<div class="card" id = "card">
<div class="content-container">
<div class="inner">
${insert}
<div class="inner">
<div id="text">
<p id="title">${post.title}</p>
<a id="link" href="https://www.reddit.com${post.plink}" target="_blank">Link</a>
</div>
</div>
</div>
</div>
</div>
`;
div.innerHTML += normalHTML;
if (wasVideo) {
var video = document.getElementById(uuid);
video.pause();
var vidSource = document.createElement("source");
vidSource.setAttribute("src", source);
video.appendChild(vidSource);
video.load();
}
}
function uuidv4() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
/[xy]/g,
function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
}
);
}
function nextPost() {
clearContent();
document.getElementById("loader").style.height = "5vh";
document.getElementById("loader").style.opacity = "1";
document.getElementById("footer_u").style.opacity = "0";
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "/");
xmlHttp.send();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
document.getElementById("loader").style.height = "0";
document.getElementById("loader").style.opacity = "0";
document.getElementById("footer_u").style.opacity = "1";
let post = JSON.parse(xmlHttp.responseText);
insertContent(post);
}
};
}
</script>
<script>
var i;
document.body.onkeyup = function (e) {
if (e.keyCode == 32) {
nextPost()
}
}
};
</script>
</body>
</html>