diff --git a/assets/js/scripts.js b/assets/js/scripts.js
deleted file mode 100644
index a26c6f9..0000000
--- a/assets/js/scripts.js
+++ /dev/null
@@ -1,29 +0,0 @@
-"use strict";
-
-let synth = window.speechSynthesis;
-
-function initSpeak() {
- if (synth && document.querySelector('.content')) {
- document.querySelector('#speakBtn').style.display = '';
- stopSpeak();
- }
-}
-
-function speak() {
- stopSpeak();
- let voices = synth.getVoices().filter(voice => voice.lang.startsWith(document.querySelector('html').lang));
- if (voices.length == 0) return;
- document.querySelector('#speakBtn').innerHTML = "Stop speaking!";
- let utterThis = new SpeechSynthesisUtterance(document.querySelector('.content').textContent);
- utterThis.voice = voices[0];
- utterThis.onerror = stopSpeak;
- utterThis.onend = stopSpeak;
- synth.speak(utterThis);
-}
-
-function stopSpeak() {
- synth.cancel();
- document.querySelector('#speakBtn').innerHTML = "Read to me, please.";
-}
-
-window.onload = initSpeak();
\ No newline at end of file
diff --git a/assets/js/speak.js b/assets/js/speak.js
new file mode 100644
index 0000000..9503fc9
--- /dev/null
+++ b/assets/js/speak.js
@@ -0,0 +1,35 @@
+"use strict";
+
+let synth = window.speechSynthesis;
+let voice;
+if (synth) {
+ voice = synth.getVoices().filter(voice => voice.lang.startsWith(document.querySelector('html').lang))[0];
+}
+
+function initSpeak() {
+ if (voice) {
+ let speakBtn = document.querySelector('#speakBtn');
+ speakBtn.style.display = '';
+ speakBtn.innerHTML = "Read to me, please.";
+ }
+}
+
+function speak() {
+ console.log("Start speaking")
+ document.querySelector('#speakBtn').innerHTML = "Stop speaking!";
+ let textContent = document.querySelector('.content').innerText;
+ let utterThis = new SpeechSynthesisUtterance(textContent);
+ utterThis.voice = voice;
+ utterThis.onerror = stopSpeak;
+ utterThis.onend = stopSpeak;
+ synth.speak(utterThis);
+}
+
+function stopSpeak() {
+ console.log("Stop speaking")
+ synth.cancel();
+ document.querySelector('#speakBtn').innerHTML = "Read to me, please.";
+}
+
+initSpeak();
+window.onbeforeunload = function () { stopSpeak(); }
\ No newline at end of file
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index abd2c63..6573cc6 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -41,7 +41,5 @@
{{ partialCached "footer" . }}
{{ partialCached "custombodyend" . }}
- {{ $scripts := resources.Get "js/scripts.js" | minify | fingerprint }}
-