-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
183 lines (150 loc) · 4.2 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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Takahashi Slides</title>
<style>
@font-face {
font-family: 'Gothic A1';
src: url('font.ttf'); /* If it's not available, it's ignored */
}
body {
height: 40vh;
margin: 30vh;
display: flex;
align-items: center;
justify-content: center;
font-size: 10vmin;
font-family: 'Gothic A1', sans-serif;
font-weight: 700;
line-height: 1.2em;
text-rendering: optimizeLegibility;
user-select: none;
color: black;
background-color: white;
}
body.dark {
color: white;
background-color: black;
}
</style>
<script>
const searchParams = new URL(window.location).searchParams;
async function readSlides() {
let rawSlides;
const sourceUrl = searchParams.get('url');
if (sourceUrl) {
try {
rawSlides = await (await fetch(sourceUrl)).text();
} catch (e) {
document.body.textContent = 'network error';
throw e;
}
} else {
rawSlides = document.getElementById('presentation')?.innerHTML?.trim();
}
if (!rawSlides) {
rawSlides = 'To present something, create a "<script id="presentation">" element or use "?url=[URL to plaintext]"';
}
const slides =
rawSlides
.split('\n')
.map(row => row.trim())
.map(row => row.replaceAll('\\n', '\n'))
.filter(row => row.length >= 1);
return slides;
}
function showSlide(slides, index) {
searchParams.set('slide', index);
history.replaceState(null, '', `${window.location.pathname}?${searchParams.toString()}`);
document.title = slides[index];
document.body.textContent = slides[index];
function resizeToFit(fontSize) {
document.body.style.fontSize = `${fontSize}vmin`;
const textIsTooBig =
document.body.clientWidth < document.body.scrollWidth
|| document.body.clientHeight < document.body.scrollHeight;
if (textIsTooBig) {
resizeToFit(fontSize * 0.9);
}
}
resizeToFit(50);
};
function listenToUserInput(callback) {
const leftKeys = new Set(['a', 'A', 'w', 'W', 'h', 'H', 'k', 'K', 'ArrowLeft']);
const rightKeys = new Set(['d', 'D', 's', 'S', 'l', 'L', 'j', 'J', 'ArrowRight', ' ']);
const resetKeys = new Set(['0']);
window.addEventListener('keydown', (event) => {
if (event.ctrlKey) {
// We don't want to react to the user pressing Ctrl+C for example
// because that's counterintuitive
return;
}
if (leftKeys.has(event.key)) {
callback('previous');
} else if (rightKeys.has(event.key)) {
callback('next');
} else if (resetKeys.has(event.key)) {
callback('reset');
}
});
window.addEventListener('mousedown', (event) => {
const leftMouseButtonClicked = event.which === 1;
if (leftMouseButtonClicked) {
callback('next');
}
});
window.addEventListener('touchstart', (event) => {
if (event.touches.length >= 2) {
callback('previous');
}
});
}
window.onload = async function main() {
if (searchParams.get('dark')) {
document.body.classList.add('dark');
}
const slides = await readSlides();
let currentSlideIndex = Number(searchParams.get('slide'));
showSlide(slides, currentSlideIndex);
listenToUserInput((action) => {
if (action === 'next') {
currentSlideIndex += 1;
} else if (action === 'previous') {
currentSlideIndex -= 1;
} else if (action === 'reset') {
currentSlideIndex = 0;
}
// Clamp
currentSlideIndex = Math.min(slides.length - 1, Math.max(0, currentSlideIndex));
showSlide(slides, currentSlideIndex);
});
};
</script>
</head>
<body>
...
</body>
<script type="text/plain" id="presentation">
Click or tap
to change slides
S/D/J/L work too
So do spacebar and right arrow key
And to go back
press left/W/A/H/K
or tap with two fingers
Push zero to reset
Presentation text is embedded in the source or linked in the URL
Takahashi method = concise slides
No images
No graphs
No videos
Takahashi lets the presenter speak
The slideshow is just an aid
Not a means in itself
This is actually a terrible example of the method because it grabs the readers attention 100%
But I hope it lets you see the point of this tool
Thanks!
</script>
</html>