PageSourceSearch

https://www.arda.or.th/assets/js/text-to-speech.js?v=1790938220

js arda.or.th collected 2026-10-02 10:50:46 UTC 2,186 bytes, 74 lines download raw bytes

1(function () {
2    "use strict";
3
4    if (typeof speechSynthesis === "undefined") return;
5    var myPhrase = "";
6    var voices = [];
7
8    var ready = function (callback) {
9        var d = document,
10            s = d.readyState;
11
12        // DOMContentLoaded was fired
13        if (s == "complete" || s == "loaded" || s == "interactive") {
14            callback();
15        } else {
16            if (d.addEventListener) {
17                d.addEventListener("DOMContentLoaded", callback, false);
18            } else {
19                d.attachEvent("onDOMContentLoaded", callback);
20            }
21        }
22    };
23
24    function populateVoiceList() {
25        voices = speechSynthesis.getVoices();
26    }
27
28    function handler() {
29        var utterThis = new SpeechSynthesisUtterance(myPhrase);
30        // var selectedOption = sessionStorage.getItem("language");
31        // for (var i = 0; i < voices.length; i++) {
32        //     if (voices[i].name === selectedOption) {
33        //         utterThis.voice = voices[i];
34        //     }
35        // }
36        if (utterThis.voice == null) {
37            utterThis.voice = voices.find((v) => v.lang == "th-TH");
38        }
39
40        if (sessionStorage.getItem("sound") == "true") {
41            speechSynthesis.speak(utterThis);
42        }
43    }
44
45    function getSelectionText() {
46        var text = "";
47        if (window.getSelection) {
48            text = window.getSelection().toString();
49        } else if (document.selection && document.selection.type != "Control") {
50            text = document.selection.createRange().text;
51        }
52        // console.log(text)
53        return text;
54    }
55
56    document.onmouseup = function (e) {
57        setTimeout(function () {
58            speechSynthesis.cancel();
59            myPhrase = getSelectionText();
60            handler();
61        }, 1);
62    };
63
64    function start() {
65        populateVoiceList();
66        if (speechSynthesis.onvoiceschanged !== undefined)
67            speechSynthesis.onvoiceschanged = populateVoiceList;
68
69        // voiceSelect.onchange = handler;
70        setTimeout(handler, 75);
71    }
72
73    ready(start);
74})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.