-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
152 lines (135 loc) · 4.28 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
150
151
152
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jubla Glattbrugg</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}
#navbar {
background-color: #333;
color: white;
padding: 10px;
}
#navbar a {
color: white;
padding: 14px 20px;
text-decoration: none;
}
#navbar a:hover {
background-color: #575757;
}
#content {
height: calc(100vh - 40px);
overflow: hidden;
position: relative;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
#loader {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.8);
display: flex;
justify-content: center;
align-items: center;
z-index: 10;
}
#loader.hidden {
display: none;
}
body.dark {
background-color: #333;
color: #fff;
}
#navbar {
background-color: #444;
}
#navbar a {
color: #fff;
}
#navbar a:hover {
background-color: #575757;
}
</style>
</head>
<body>
<div id="navbar">
<a href="#" id="loadJubla">Jubla Glattbrugg</a>
</div>
<div id="content">
<div id="loader">
<div>Loading...</div>
</div>
<iframe id="contentFrame" src=""></iframe>
</div>
<script>
const iframe = document.getElementById('contentFrame');
const loader = document.getElementById('loader');
async function loadUrl(url) {
loader.classList.remove('hidden'); // Show loader
// Check if the URL is cached
const cachedData = localStorage.getItem(url);
const cachedHash = localStorage.getItem(url + '_hash');
if (cachedData) {
// If cached data exists, load it
iframe.srcdoc = cachedData;
console.log("Loaded from cache:", url);
}
try {
const response = await fetch(url);
if (!response.ok) throw new Error('Network response was not ok.');
const data = await response.text();
const newHash = hashCode(data); // Calculate hash of the new content
// Check if the cached hash matches the new hash
if (cachedHash !== newHash) {
// Update the iframe with the new content
iframe.srcdoc = data;
// Cache the new content and hash
localStorage.setItem(url, data);
localStorage.setItem(url + '_hash', newHash);
console.log("Updated cache for:", url);
} else {
console.log("No update needed for:", url);
}
loader.classList.add('hidden'); // Hide loader
} catch (error) {
console.error('Fetch error:', error);
// If there's an error, you can choose to show an error message or keep the cached content
if (cachedData) {
iframe.srcdoc = cachedData; // Load cached content if available
console.log("Loaded cached content due to error:", url);
}
loader.classList.add('hidden'); // Hide loader
}
}
function hashCode(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash << 5) - hash + str.charCodeAt(i);
hash |= 0; // Convert to 32bit integer
}
return hash;
}
document.getElementById('loadJubla').addEventListener('click', () => {
loadUrl('https://jublaglattbrugg.ch');
});
</script>
<script>
// Check for dark mode preference
const isDarkMode = localStorage.getItem('darkMode') === 'true';
if (isDarkMode) {
document.body.classList.add('dark');
}
</script>
</body>
</html>