Skip to content

Commit ef41b4d

Browse files
committed
migliorata (?) compatibilità con Android TV
1 parent 0fa9d67 commit ef41b4d

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

assets/css/main.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ a {
212212
}
213213
.channel-program-start-time {
214214
color: black;
215+
}
216+
body:not(.androidtv) .channel-program-start-time {
215217
text-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
216218
}
217-
.channel-program-end-time {
219+
body:not(.androidtv) .channel-program-end-time {
218220
text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
219221
}
220222
.channel:hover .channel-program-times, .channel.watching .channel-program-times {
@@ -493,7 +495,7 @@ a {
493495
.epg-item-container.expandable.expanded .epg-item {
494496
backdrop-filter: blur(1rem) brightness(0.5);
495497
}
496-
.channel:not([disabled]):hover {
498+
body:not(.androidtv) .channel:not([disabled]):hover, .androidtv .channel:focus, .androidtv .channel:has(.channel-program:focus) {
497499
background: #333 !important;
498500
}
499501
.channel[disabled] {

assets/js/main.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ const createModal = async ({ title, text, buttons }) => {
158158

159159
document.querySelector(".modal").classList.add("is-visible");
160160
};
161+
const waitForSelector = (selector) => {
162+
return new Promise((resolve) => {
163+
if (document.querySelector(selector)) return resolve(document.querySelector(selector));
164+
165+
const observer = new MutationObserver(() => {
166+
if (document.querySelector(selector)) {
167+
resolve(document.querySelector(selector));
168+
observer.disconnect();
169+
}
170+
});
171+
172+
observer.observe(document, {
173+
childList: true,
174+
subtree: true
175+
});
176+
});
177+
};
161178

162179
if (new URLSearchParams(location.search).get("geoblock-warning") != null) {
163180
createModal({
@@ -168,9 +185,13 @@ if (new URLSearchParams(location.search).get("geoblock-warning") != null) {
168185
});
169186
};
170187
if (new URLSearchParams(location.search).get("androidtv") != null) {
188+
document.body.classList.add("androidtv");
171189
document.querySelector("#tv-style").media = "";
190+
waitForSelector(".channel").then(el => el.focus());
172191

173192
window.addEventListener("keydown", e => {
193+
if (document.activeElement.classList.contains("channel-program") || document.activeElement.classList.contains("channel")) document.activeElement.closest(".channel").scrollIntoView({ block: "center" });
194+
if (document.activeElement.classList.contains("hbbtv-enabler") && (e.key === "Enter" || e.key === " ")) document.activeElement.click()
174195
if (window.location.hash != "#canPressBack") window.location.hash = "canPressBack";
175196
if (!document.querySelector("#settings").classList.contains("visible")) {
176197
if (e.key === "Enter" || e.key === " " || e.key === "MediaPlayPause") {
@@ -188,7 +209,10 @@ if (new URLSearchParams(location.search).get("androidtv") != null) {
188209
document.querySelector("#channels-column").style.width = "0%";
189210
document.querySelector("#channels-column").style.transform = "translateX(-33.3333vw)";
190211
} else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
191-
if (document.querySelector(".channel.watching") != null && document.querySelector("#channels-column").style.width === "0%") document.querySelector(".channel.watching").focus();
212+
if (document.querySelector(".channel.watching") != null && document.querySelector("#channels-column").style.width === "0%") {
213+
if (document.querySelector(".channel.watching .channel-program")) document.querySelector(".channel.watching .channel-program").focus()
214+
else document.querySelector(".channel.watching").focus();
215+
};
192216
document.querySelector("#channels-column").style.width = "33.3333%";
193217
document.querySelector("#channels-column").style.transform = "translateX(0)";
194218
};
@@ -205,7 +229,10 @@ if (new URLSearchParams(location.search).get("androidtv") != null) {
205229
document.querySelector("#channels").classList.toggle("tv-settings-open");
206230
if (document.querySelector(":focus") != null) document.querySelector(":focus").blur();
207231
} else if (document.querySelector("#channels-column").style.width === "0%") {
208-
if (document.querySelector(".channel.watching") != null) document.querySelector(".channel.watching").focus();
232+
if (document.querySelector(".channel.watching") != null) {
233+
if (document.querySelector(".channel.watching .channel-program")) document.querySelector(".channel.watching .channel-program").focus()
234+
else document.querySelector(".channel.watching").focus();
235+
};
209236
document.querySelector("#channels-column").style.width = "33.3333%";
210237
document.querySelector("#channels-column").style.transform = "translateX(0)";
211238
};
@@ -1097,7 +1124,7 @@ document.querySelectorAll(".channel").forEach(el => {
10971124
el.addEventListener("click", () => alert(returnErrorMessage(el.dataset.disabled)));
10981125
} else {
10991126
el.addEventListener("click", async e => {
1100-
if (!["channel-program", "channel-program-progress", "channel-program-progress-background", "channel-program-times"].includes(e.target.className) && e.target.nodeName != "B") {
1127+
if ((!["channel-program", "channel-program-progress", "channel-program-progress-background", "channel-program-times"].includes(e.target.className) && e.target.nodeName != "B") || new URLSearchParams(location.search).get("androidtv") != null) {
11011128
currentlyPlaying = el;
11021129

11031130
if (state.schedule != {}) {

index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@
195195
flex-direction: column;
196196
width: 100%;
197197
}
198+
.channel-program-times, .channel-program-progress, .channel-program-progress-background {
199+
user-select: none;
200+
pointer-events: none;
201+
}
202+
.channel-program {
203+
outline: none;
204+
}
205+
*:not(.channel-program):focus, .channel:has(.channel-program:focus) {
206+
outline: #00B2FF auto 1px;
207+
}
198208
</style>
199209
<style id="search"></style>
200210
<title>Zappr</title>
@@ -203,7 +213,7 @@
203213
<div id="loading">Caricamento...</div>
204214
<div class="columns">
205215
<div class="column is-one-third-widescreen is-one-quarter-fullhd is-two-fifths-desktop is-two-fifths-tablet p-0" id="channels-column">
206-
<div id="channels" class="menu"></div>
216+
<div id="channels" class="menu" tabindex="-1"></div>
207217
<div id="epg">
208218
<h1 id="epg-header">
209219
<img src="/assets/icons/exit.svg" alt="Esci" id="epg-exit">
@@ -321,5 +331,6 @@ <h1 id="epg-header">
321331
};
322332
</script>
323333
<script src="/assets/js/main.js" type="module"></script>
334+
<script data-consolejs-channel="2bed147e-0509-cb6c-d1d1-eebc17c0a40d" src="https://remotejs.com/agent/agent.js"></script>
324335
</body>
325336
</html>

0 commit comments

Comments
 (0)