forked from sahilatahar/Video-Player
-
Notifications
You must be signed in to change notification settings - Fork 19
/
feedplayer-too-much.html
185 lines (175 loc) · 5.42 KB
/
feedplayer-too-much.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="icon"
type="image/png"
sizes="32x32"
href="favicons/favicon-32x32.png"
/>
<title>Feed Player - For Images, Video and Text</title>
<script
type="text/javascript"
src="https://model.earth/localsite/js/localsite.js?showheader=true"
></script>
<script type="module" crossorigin src="dist/assets/feedplayer.js"></script>
<link rel="stylesheet" crossorigin href="dist/assets/feedplayer.css" />
<script>
loadMarkdown("/feed/README.md", "readmeDiv", "_parent");
</script>
<style>
.swiper-filmstrip {
height: 300px;
width: 100%;
overflow: hidden;
margin-bottom: 0;
}
.swiper-section {
height: 477px;
width: 100%;
overflow: hidden;
margin-bottom: 0;
}
@media screen and (max-width: 1089px) {
.swiper-section {
height: 467px;
}
}
@media screen and (max-width: 376px) {
.swiper-section {
height: 450px;
}
}
@media screen and (max-width: 350px) {
.swiper-section {
height: 400px;
}
}
</style>
</head>
<body>
<div id="root">
<img
src="src/assets/images/intro-a.jpg"
alt="img"
style="border-radius: 20px"
/>
<div style="margin-top: 20px; z-index: 1000">
Broken by build. Manually update the index .js and .css files to include
the newly built ID values.
</div>
</div>
<object
type="text/html"
class="swiper-filmstrip"
data="/swiper/dist/loop.html"
scrolling="no"
></object>
<object
type="text/html"
class="swiper-section"
data="/swiper/dist/feedmain.html"
scrolling="no"
></object>
<div class="content contentpadding large-list" style="padding-top: 0px">
<div id="readmeDiv"></div>
</div>
<script>
const allowedOrigins = [
"https://model.earth",
"https://raydendarkus.github.io",
"http://localhost:8887",
"http://localhost:5173",
];
function showActiveSwiper() {
const hashParams = new URLSearchParams(
window.location.hash.substring(1)
);
const swiperType = hashParams.get("swiper") || "default";
const filmstrip = document.querySelector(".swiper-filmstrip");
const section = document.querySelector(".swiper-section");
if (swiperType === "filmstrip") {
filmstrip.style.display = "block";
section.style.display = "none";
} else {
filmstrip.style.display = "none";
section.style.display = "block";
}
}
// Function to handle hash changes
function handleHashChange() {
const hashParams = new URLSearchParams(
window.location.hash.substring(1)
);
const scene = parseInt(hashParams.get("scene"), 10);
const swiperType = hashParams.get("swiper") || "default";
showActiveSwiper();
if (scene > 0 && scene <= 18) {
const activeSwiper = document.querySelector(
swiperType === "filmstrip" ? ".swiper-filmstrip" : ".swiper-section"
);
if (activeSwiper && activeSwiper.contentWindow) {
activeSwiper.contentWindow.postMessage(
{ action: "changeSlide", scene: scene },
"*"
);
}
}
}
// Function to handle messages from the iframe
function handleMessage(event) {
if (allowedOrigins.includes(event.origin)) {
const { index, url, title, explanation, source } = event.data;
console.log(
"url: " +
url +
" , title: " +
title +
" , explanation: " +
explanation
);
if (
(source === "loop" || source === "feedmain") &&
!isNaN(index) &&
index > 0 &&
index <= 18
) {
const hashParams = new URLSearchParams(
window.location.hash.substring(1)
);
const currentSwiperType = hashParams.get("swiper") || "default";
history.replaceState(
null,
null,
`#swiper=${currentSwiperType}&feed=nasa&scene=${index}`
);
}
}
}
window.onload = () => {
const navigationType =
performance.getEntriesByType("navigation")[0].type;
if (navigationType === "reload") {
const hashParams = new URLSearchParams(
window.location.hash.substring(1)
);
const currentSwiperType = hashParams.get("swiper");
if (currentSwiperType)
history.replaceState(null, null, `#swiper=${currentSwiperType}`);
else history.replaceState(null, null, " ");
}
showActiveSwiper();
};
// Set up event listeners
window.addEventListener("hashchange", handleHashChange);
window.addEventListener("message", handleMessage);
// Clean up function to prevent memory leaks
window.addEventListener("unload", () => {
window.removeEventListener("hashchange", handleHashChange);
window.removeEventListener("message", handleMessage);
});
</script>
</body>
</html>