40 lines
1012 B
TypeScript
40 lines
1012 B
TypeScript
import "./disqus";
|
|
import "./app.scss";
|
|
|
|
window.addEventListener("keydown", (ev) => {
|
|
if (ev.key === "s") {
|
|
const s = window.getSelection().toString();
|
|
if (s) {
|
|
speak(s);
|
|
}
|
|
}
|
|
});
|
|
|
|
window.onload = () => {
|
|
for (const a of Array.from(document.getElementsByTagName("a"))) {
|
|
const href = a.href;
|
|
console.log(href);
|
|
const m = /^slide:github:([^/]+)\/([^/]+)\/(.+)$/.exec(href);
|
|
if (m) {
|
|
const url = new URL("https://reveal-md.herokuapp.com/");
|
|
url.searchParams.append("q", `https://raw.githubusercontent.com/${m[1]}/${m[2]}/master/src/resources/${m[3]}`);
|
|
a.href = url.href;
|
|
}
|
|
}
|
|
}
|
|
|
|
function speak(s: string) {
|
|
const allVoices = speechSynthesis.getVoices();
|
|
let vs = allVoices.filter((v) => /zh[-_]cn/i.test(v.lang));
|
|
if (vs.length === 0) {
|
|
vs = allVoices.filter((v) => /zh/i.test(v.lang));
|
|
}
|
|
|
|
if (vs.length > 0) {
|
|
const u = new SpeechSynthesisUtterance(s);
|
|
u.lang = vs[0].lang;
|
|
u.rate = 0.8;
|
|
speechSynthesis.speak(u);
|
|
}
|
|
}
|