-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
126 lines (112 loc) · 5.26 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content="Text to Speech">
<meta name="description" content="Lightweight Text to Speech to share with friends">
<meta property="og:site_name" content="Text to Speech">
<meta property="og:locale" content="en_US">
<meta property="og:url" content="http://talk.spaghet.me">
<meta name="twitter:site" content="http://talk.spaghet.me">
<meta data-hid="title" name="title" content="Text to Speech">
<meta data-hid="description" name="description" content="Lightweight Text to Speech to share with friends">
<meta property="og:type" content="website">
<meta property="og:title" content="Text to Speech">
<meta property="og:description" content="Lightweight Text to Speech to share with friends">
<meta property="og:image" content="https://webstockreview.net/images/megaphone-clipart-emoji-10.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Text to Speech">
<meta name="twitter:description" content="Lightweight Text to Speech to share with friends">
<meta name="twitter:image" content="https://webstockreview.net/images/megaphone-clipart-emoji-10.png">
<meta name="twitter:image:alt" content="Megaphone">
<link rel="stylesheet" href="style.css">
<link rel="next" href="usage.html">
</head>
<body>
<div class="container">
<div id="textbox"></div>
<div class="button-group">
<button id="play">Play</button>
<button id="copy">Copy to Clipboard</button>
<label for="hide">
<input type="checkbox" name="hide" id="hide"> hide text from url?
</label>
</div>
<hr>
<a href="/usage.html">Try a new message</a>
<a href="https://mannino.dev" target="_blank" style="font-size: 8px">✨ made by tones ✨</a>
</div>
<script>
window.onload = () => {
let queryString = {};
const textbox = document.querySelector('#textbox');
const playButton = document.querySelector('#play');
const copyButton = document.querySelector('#copy');
const hideButton = document.querySelector('#hide');
copyButton.addEventListener('click', () => {
const textArea = document.createElement("textarea");
textArea.style.position = "fixed";
if (hideButton.checked) {
textArea.textContent = `${window.location.origin}/?code=${btoa(encodeURIComponent(textbox.textContent))}`;
} else {
textArea.textContent = `${window.location.origin}/?message=${encodeURIComponent(textbox.textContent)}`;
}
console.log(textArea.textContent);
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
textArea.setSelectionRange(0, 99999); /*For mobile devices*/
/* Copy the text inside the text field */
try {
document.execCommand("copy");
} catch (err) {
console.log(err);
} finally {
document.body.removeChild(textArea);
}
});
try {
if (window.location.search) {
window.location.search.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { queryString[$1] = $3; }
);
if (!queryString.message && !queryString.code) {
new Error('Wrong query param provided');
} else {
let text;
// Encode things for click 2 copy (to hide)
if (queryString.code) {
console.log('code')
text = decodeURIComponent(atob(queryString.code));
} else {
text = decodeURIComponent(queryString.message).trim().replace(/\+/g, ' ');
}
textbox.textContent = text;
const utterance = new SpeechSynthesisUtterance(text);
playButton.addEventListener('click', () => speechSynthesis.speak(utterance));
// Only works in some browsers. Blocked in chrome
playButton.click();
playButton.focus();
}
} else {
throw new Error('No query params provided');
}
} catch (err) {
console.log(err);
window.location.replace('/usage.html');
}
}
function isBase64(str) {
try {
return btoa(atob(str)) == str;
} catch (err) {
return false;
}
}
</script>
<script data-goatcounter="https://tonymannino.goatcounter.com/count" src="//gc.zgo.at/count.js"></script>
</body>
</html>