Skip to content

Commit b84e0e8

Browse files
committed
Optimize display and removal of background static
1 parent b5d51ec commit b84e0e8

File tree

5 files changed

+65
-77
lines changed

5 files changed

+65
-77
lines changed

astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default defineConfig({
1212
},
1313
adapter: netlify(),
1414
prefetch: true,
15+
trailingSlash: "never",
1516
redirects: {
1617
"/ch/00": "/",
1718
"/about": "/credits",

src/components/IFrame.astro

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,65 @@ const { src }: Props = Astro.props;
1111
class="iframe"
1212
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
1313
referrerpolicy="strict-origin-when-cross-origin"
14-
allowfullscreen></iframe>
14+
allowfullscreen
15+
>
16+
</iframe>
17+
<canvas id="static"></canvas>
1518

1619
<script>
17-
const iframe = document.querySelector(".iframe");
20+
const canvas = document.getElementById("static") as HTMLCanvasElement;
1821

19-
if (iframe) {
20-
iframe.addEventListener("load", () => {
21-
iframe.classList.add("loaded");
22-
});
22+
if (canvas) {
23+
const ctx = canvas.getContext("2d");
24+
25+
function setCanvasSize() {
26+
canvas.width = window.innerWidth / 3;
27+
canvas.height = (window.innerHeight * 0.5625) / 3;
28+
}
29+
30+
// Generate CRT noise
31+
function snow() {
32+
if (!ctx) return;
33+
34+
const w = ctx.canvas.width;
35+
const h = ctx.canvas.height;
36+
const d = ctx.createImageData(w, h);
37+
const b = new Uint32Array(d.data.buffer);
38+
const len = b.length;
39+
40+
for (let i = 0; i < len; i++) {
41+
b[i] = ((255 * Math.random()) | 0) << 24;
42+
}
43+
44+
ctx.putImageData(d, 0, 0);
45+
}
46+
47+
function animate() {
48+
snow();
49+
requestAnimationFrame(animate);
50+
}
51+
52+
// resize the canvas to fill browser window dynamically
53+
window.addEventListener("resize", resizeCanvas, false);
54+
55+
function resizeCanvas() {
56+
setCanvasSize();
57+
animate();
58+
}
59+
60+
setCanvasSize();
61+
animate();
2362
}
24-
</script>
2563

26-
<script>
2764
const iframe = document.querySelector(".iframe");
2865

2966
if (iframe) {
3067
iframe.addEventListener("load", () => {
68+
// Display white background (for sites with undefined backgrounds)
3169
iframe.classList.add("loaded");
70+
71+
// Remove background static
72+
canvas.remove();
3273
});
3374
}
3475
</script>
@@ -44,4 +85,16 @@ const { src }: Props = Astro.props;
4485
background-color: white;
4586
}
4687
}
88+
89+
#static {
90+
display: block;
91+
position: absolute;
92+
inset: 0;
93+
width: 100%;
94+
height: 100%;
95+
z-index: -1;
96+
pointer-events: none;
97+
background: transparent linear-gradient(to bottom, #85908c 0%, #323431 100%)
98+
repeat scroll 0 0;
99+
}
47100
</style>

src/components/Screen.astro

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
import Menu from "./Menu.astro";
3-
import Static from "./Static.astro";
43
54
interface Props {
65
channelId: string;
@@ -19,7 +18,6 @@ const { channelId, channelName }: Props = Astro.props;
1918
<div class="screen-content" data-horizontal="0" data-vertical="0">
2019
<Menu />
2120
<slot />
22-
<Static />
2321
</div>
2422
</div>
2523

src/components/Static.astro

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/layouts/Layout.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import "../styles/index.css";
33
44
interface Props {
5-
title: string;
5+
title: string;
66
}
77
88
const { title } = Astro.props;
99
1010
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
1111
const pageTitle =
12-
Astro.url.pathname === "/" ? title : `${title} | Hypertext TV`;
12+
Astro.url.pathname === "/" ? title : `${title} | Hypertext TV`;
1313
---
1414

1515
<!doctype html>
@@ -19,6 +19,7 @@ const pageTitle =
1919
<meta name="viewport" content="width=device-width" />
2020
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
2121
<link rel="canonical" href={canonicalURL} />
22+
<link rel="sitemap" href="/sitemap-index.xml" />
2223
<meta name="generator" content={Astro.generator} />
2324
<title>{pageTitle}</title>
2425
<link

0 commit comments

Comments
 (0)