-
Notifications
You must be signed in to change notification settings - Fork 0
/
teleprompter.html
171 lines (160 loc) · 5.39 KB
/
teleprompter.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Teleprompter by Neil Reyes</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: black;
color: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
overflow: hidden;
}
#teleprompter {
width: 80%;
height: 60%;
overflow: hidden;
position: relative;
border: 2px solid white;
cursor: grab;
}
#text {
position: absolute;
top: 100%;
width: 100%;
text-align: center;
font-size: 3em;
}
.controls {
margin: 10px;
width: 80%;
}
textarea {
width: 100%;
height: 100px;
}
input[type="range"] {
width: calc(80% - 100px);
}
.control-buttons {
margin-top: 10px;
}
.speed-control {
display: flex;
align-items: center;
}
.header {
text-align: center;
margin-bottom: 20px;
}
.header a {
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<!-- Version 1.5 -->
<div class="header">
<h1>Teleprompter</h1>
<a>Neil Reyes' </a>
<a href="https://github.com/neil-re/teleprompter" target="_blank">GitHub Repository</a>
</div>
<div class="controls">
<textarea id="inputText" placeholder="Enter your text here..."></textarea><br>
<label for="fontSize">Font Size:</label>
<input type="number" id="fontSize" value="3" min="1" max="10" step="0.1">em<br>
<div class="speed-control">
<label for="speed">Scroll Speed (px/sec):</label>
<input type="range" id="speed" value="10" min="1" max="120" step="1">
<span id="speedValue">10</span> px/sec
</div>
<div class="control-buttons">
<button onclick="startTeleprompter()">Start</button>
<button onclick="pauseTeleprompter()">Pause</button>
<button onclick="resetTeleprompter()">Reset</button>
</div>
</div>
<div id="teleprompter">
<div id="text"></div>
</div>
<script>
const textElement = document.getElementById('text');
const inputTextElement = document.getElementById('inputText');
const fontSizeElement = document.getElementById('fontSize');
const speedElement = document.getElementById('speed');
const speedValueElement = document.getElementById('speedValue');
let speed = parseFloat(speedElement.value);
const fps = 60; // Frames per second
let scrollAnimationFrame;
let isPaused = false;
let startPosY = 0;
let isDragging = false;
function startTeleprompter() {
textElement.innerHTML = inputTextElement.value.replace(/\n/g, '<br>');
textElement.style.fontSize = `${fontSizeElement.value}em`;
textElement.style.top = '100%';
speed = parseFloat(speedElement.value);
speedValueElement.textContent = speed;
isPaused = false;
scrollText();
}
function scrollText() {
if (!isPaused) {
const pixelsPerFrame = speed / fps;
textElement.style.top = `${parseFloat(textElement.style.top) - pixelsPerFrame}px`;
if (parseFloat(textElement.style.top) + textElement.clientHeight < 0) {
cancelAnimationFrame(scrollAnimationFrame);
return;
}
}
scrollAnimationFrame = requestAnimationFrame(scrollText);
}
function pauseTeleprompter() {
isPaused = !isPaused;
if (!isPaused) {
scrollText();
}
}
function resetTeleprompter() {
cancelAnimationFrame(scrollAnimationFrame);
textElement.style.top = '100%';
}
speedElement.addEventListener('input', () => {
speed = parseFloat(speedElement.value);
speedValueElement.textContent = speed;
});
fontSizeElement.addEventListener('input', () => {
textElement.style.fontSize = `${fontSizeElement.value}em`;
});
// Events to allow manual dragging of the text
textElement.addEventListener('mousedown', (e) => {
isDragging = true;
startPosY = e.clientY - parseFloat(textElement.style.top);
textElement.style.cursor = 'grabbing';
});
textElement.addEventListener('mousemove', (e) => {
if (isDragging) {
textElement.style.top = `${e.clientY - startPosY}px`;
}
});
textElement.addEventListener('mouseup', () => {
isDragging = false;
textElement.style.cursor = 'grab';
});
textElement.addEventListener('mouseleave', () => {
if (isDragging) {
isDragging = false;
textElement.style.cursor = 'grab';
}
});
</script>
</body>
</html>