-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.html
More file actions
325 lines (279 loc) · 6.97 KB
/
rules.html
File metadata and controls
325 lines (279 loc) · 6.97 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link href='https://fonts.googleapis.com/css?family=EB Garamond' rel='stylesheet'> -->
<title>Hex Dice Rules</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'EB Garamond', monospace;
line-height: 1.6;
color: #333;
background: #f5f5f5;
padding: 0.5rem 0.2rem;
}
.container {
max-width: 900px;
margin: 0 auto;
background: #C3A471EE;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
#markdown-viewer {
line-height: 1.8;
}
#markdown-viewer h1,
#markdown-viewer h2,
#markdown-viewer h3,
#markdown-viewer h4,
#markdown-viewer h5 {
margin-top: 1.5rem;
margin-bottom: 0.75rem;
font-weight: 600;
}
#markdown-viewer h1 {
font-size: 3rem;
border-bottom: 2px solid #333;
padding-bottom: 0.5rem;
}
#markdown-viewer h2 {
font-size: 2rem;
border-bottom: 1px solid #ddd;
padding-bottom: 0.3rem;
}
#markdown-viewer h3 {
font-size: 1.5rem;
}
#markdown-viewer h4 {
font-size: 1.25rem;
}
#markdown-viewer h5 {
font-size: 1.1rem;
}
#markdown-viewer p {
margin-bottom: 1rem;
}
#markdown-viewer ul,
#markdown-viewer ol {
margin-left: 2rem;
margin-bottom: 1rem;
}
#markdown-viewer li {
margin-bottom: 0.5rem;
word-break: break-word;
}
#markdown-viewer table {
width: 100%;
border-collapse: collapse;
margin: 1rem 0;
overflow-x: auto;
display: block;
/*zoom: 0.8;*/
font-size: smaller;
}
#markdown-viewer img {
padding: 1rem;
}
#markdown-viewer th,
#markdown-viewer td {
border: 1px solid #ddd;
padding: 0.5rem;
text-align: left;
}
#markdown-viewer th {
background: #f0f0f0;
font-weight: 600;
}
#markdown-viewer code {
background: #f5f5f5d4;
padding: 0.2rem 0.4rem;
border-radius: 3px;
font-family: monospace;
font-size: 0.9em;
font-weight: bolder;
}
@media (max-width: 480px) {
#markdown-viewer code {
zoom: 0.80;
}
}
#markdown-viewer pre {
background: #e9dcc8d4;
padding: 0.25rem;
border-radius: 4px;
overflow-x: auto;
margin: 1rem 0;
place-self: center;
zoom: 0.9;
}
#markdown-viewer pre code {
background: none;
padding: 0;
letter-spacing: 0.5rem;
}
#markdown-viewer img {
max-width: 100%;
height: auto;
display: block;
margin: 1rem auto;
}
#markdown-viewer blockquote {
border-left: 4px solid #ddd;
padding-left: 1rem;
margin: 1rem 0;
color: #666;
}
#markdown-viewer a {
color: #0366d6;
text-decoration: none;
}
#markdown-viewer a:hover {
text-decoration: underline;
}
.loading {
text-align: center;
padding: 2rem;
color: #666;
}
.error {
color: #d32f2f;
background: #ffebee;
padding: 1rem;
border-radius: 4px;
margin: 1rem 0;
}
.back-link {
display: inline-block;
margin-bottom: 1rem;
color: #574427;
text-decoration: none;
font-weight: bold;
}
.back-link:hover {
text-decoration: underline;
}
/*@media (max-width: 768px) {
body {
padding: 0.5rem 0.25rem;
}
.container {
padding: 1rem;
}
#markdown-viewer h1 {
font-size: 1.5rem;
}
#markdown-viewer h2 {
font-size: 1.25rem;
}
}*/
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url('/assets/infographics/hexdice_intro.jpg') center/cover no-repeat;
opacity: 0.5;
z-index: -1;
}
</style>
</head>
<body>
<div class="container">
<a href="/" class="back-link">← Back to Game</a>
<div id="google_translate_element"></div>
<div id="markdown-viewer">
<div class="loading">Loading rules...</div>
</div>
</div>
<!-- Hidden element to store raw markdown -->
<div id="markdown-content" style="display: none;"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<!-- Load marked library -->
<script src="https://unpkg.com/marked@12.0.0/marked.min.js"></script>
<script>
// Fetch markdown file and render
async function loadAndRenderMarkdown(mdFile) {
const markdownViewer = document.getElementById('markdown-viewer');
const markdownContent = document.getElementById('markdown-content');
console.log('Loading markdown:', mdFile);
try {
const response = await fetch(mdFile);
if (!response.ok) {
throw new Error(`Failed to load rules: ${response.statusText}`);
}
const markdownText = await response.text();
console.log('Markdown loaded, length:', markdownText.length);
// Check if we got HTML page instead of markdown
if (markdownText.startsWith('<!DOCTYPE html>')) {
throw new Error('Server returned HTML instead of markdown.');
}
markdownContent.textContent = markdownText;
let htmlContent = markdownText;
try {
htmlContent = marked.parse(markdownText);
} catch (ex) {console.error('Caught:', ex)}
markdownViewer.innerHTML = htmlContent;
// Intercept internal markdown links
markdownViewer.querySelectorAll('a').forEach(link => {
const href = link.getAttribute('href');
if (href && href.startsWith('/rules?path=')) {
const params = new URLSearchParams(href.split('?')[1]);
const mdPath = params.get('path');
link.addEventListener('click', (e) => {
e.preventDefault();
window.history.pushState({path: mdPath}, '', `?path=${mdPath}`);
loadAndRenderMarkdown(`/${mdPath}`);
});
} else if (href && href.startsWith('/')) {
link.target = '_self';
} else {
link.target = '_blank';
}
});
} catch (error) {
console.error('Error loading markdown:', error);
markdownViewer.innerHTML = `
<div class="error">
<strong>Error loading rules:</strong> ${error.message}<br>
<a href="/">Return to game</a>
</div>
`;
}
}
function DEFAULT_RULE() {
return 'rules/RULES.md';
}
// Handle browser back/forward buttons
window.addEventListener('popstate', (e) => {
const mdPath = e.state?.path || DEFAULT_RULE();
loadAndRenderMarkdown(`/${mdPath}`);
});
// Load markdown when page is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
const params = new URLSearchParams(window.location.search);
const mdPath = params.get('path') || DEFAULT_RULE();
loadAndRenderMarkdown(`/${mdPath}`);
});
} else {
const params = new URLSearchParams(window.location.search);
const mdPath = params.get('path') || DEFAULT_RULE();
loadAndRenderMarkdown(`/${mdPath}`);
}
</script>
</body>
</html>