1(() => { 2 const audioElement = document.createElement('audio'); 3 const vorlesenButton = document.getElementById("vorlesenbutton"); 4 const downloadbutton = document.getElementById("downloadenbutton"); 5 const s3loader = document.getElementById("s3loader"); 6 const sprachwahlElement = document.getElementById("sprachwahl"); 7 const voicetextElement = document.getElementById('voicetext'); 8 9 const supportsMp3 = () => !!(audioElement.canPlayType && audioElement.canPlayType('audio/mpeg;').replace(/no/, '')); 10 11 const enableButtons = (enable) => { 12 vorlesenButton.disabled = !enable; 13 vorlesenButton.value = enable ? "Read" : "Creating..."; 14 }; 15 16 const addAudioEventListeners = (audio) => { 17 audio.addEventListener("playing", () => enableButtons(true)); 18 audio.addEventListener("ended", () => enableButtons(true)); 19 audio.addEventListener('error', failed); 20 21 function failed(e) { 22 switch (e.target.error.code) { 23 case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED: 24 alert('Audio file is corrupt. Please check your message for invalid characters.'); 25 enableButtons(true); 26 break; 27 } 28 } 29 }; 30 31 // Helper function to check for S3 file status and update the interface accordingly 32 const checkForS3 = (s3file, silent) => { 33 const requestBody = new URLSearchParams({ 'id': s3file }); 34 fetch('https://ttsmp3.com/inc/checks3.php', { 35 method: 'POST', 36 body: requestBody 37 }) 38 .then(response => response.text()) 39 .then(s3checker => { 40 if (s3checker == 0) { 41 setTimeout(() => checkForS3(s3file, silent), 2000); 42 } else { 43 const s3filepath = `https://s3.ca-central-1.amazonaws.com/ttsmp3files/${s3file}.mp3`; 44 45 const myaudio = new Audio(s3filepath); 46 s3loader.style.display = "none"; 47 addAudioEventListeners(myaudio); 48 49 if (!silent) { 50 myaudio.play(); 51 } else { 52 goToDownload(s3file, "s3"); 53 enableButtons(true); 54 } 55 } 56 }).catch(error => { 57 alert('An error occurred while checking the file status.'); 58 enableButtons(true); 59 }); 60 }; 61 62 63 const playsound = (silent) => { 64 if (!supportsMp3()) { 65 alert("Sorry, your current browser does not support playing MP3 files. Please switch to a different browser."); 66 return; 67 } 68 69 enableButtons(false); 70 71 const voicetext = encodeURIComponent(voicetextElement.value.replace(/&/g, " and ")); 72 if (!voicetext) { 73 alert("Please input text."); 74 enableButtons(true); 75 return; 76 } 77 78 const lang = sprachwahlElement.value; 79 const params = `msg=${voicetext}&lang=${lang}&source=ttsmp3`; 80 81 fetch('https://ttsmp3.com/makemp3_new.php', { 82 method: 'POST', 83 headers: new Headers({'Content-type': 'application/x-www-form-urlencoded'}), 84 body: params 85 }) 86 .then(response => response.json()) 87 .then(soundarray => { 88 89 if (soundarray["Error"] == 0) { 90 if (soundarray["tasktype"] != "s3") { 91 console.log("direct processing"); 92 var myaudio = new Audio(soundarray["URL"]); 93 myaudio.addEventListener("playing", function() 94 { 95 document.getElementById("vorlesenbutton").disabled = false; 96 document.getElementById("vorlesenbutton").value = "Reading..."; 97 }); 98 myaudio.addEventListener("ended", function() 99 { 100 document.getElementById("vorlesenbutton").disabled = false; 101 document.getElementById("vorlesenbutton").value = "Read"; 102 }); 103 myaudio.addEventListener('error', function failed(e) { 104 switch (e.target.error.code) { 105 case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED: 106 alert('Your audio file was created but is corrupt. Please check your message for invalid characters.'); 107 enableButtons(true); 108 break; 109 } 110 }, true); 111 if (silent == 0) { 112 myaudio.play(); 113 } 114 else { 115 goToDownload(soundarray["MP3"], "direct"); 116 enableButtons(true); 117 } 118 } 119 else { 120 console.log("task processing"); 121 document.getElementById("s3loader").style.display = "block"; 122 checkfors3(soundarray["s3task"], silent); 123 124 } 125 } 126 else { 127 alert(soundarray['Error']); 128 if (soundarray['Error'] == "Usage Limit exceeded") { 129 window.location = "https://ttsmp3.com/register?click=jsredirect"; 130 } 131 enableButtons(true); 132 } 133 }) 134 .catch(error => { 135 console.log(error); 136 alert('An error occurred while creating the audio file.'); 137 enableButtons(true); 138 }); 139 }; 140 141 142 vorlesenButton.addEventListener('click', () => playsound(false)); 143 downloadbutton.addEventListener('click', () => playsound(true)); 144 145 const goToDownload = (fileId, location = 'direct') => { 146 if (!supportsMp3()) { 147 alert("Your browser cannot play MP3 files."); 148 return; 149 } 150 151 let urlString = `https://ttsmp3.com/dlmp3.php?mp3=${fileId}&location=${location}`; 152 fetch(urlString) 153 .then(response => { 154 if (!response.ok) { 155 throw new Error('Network response was not ok'); 156 } 157 return response.blob(); 158 }) 159 .then(blob => { 160 let today = new Date(); 161 let date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate(); 162 let time = today.getHours() + "-" + today.getMinutes() + "-" + today.getSeconds(); 163 let filename = `ttsMP3.com_VoiceText_${date}_${time}.mp3`; 164 165 // The saveAs function is from the FileSaver library 166 saveAs(blob, filename); 167 }) 168 .catch(error => { 169 console.error('Unable to start download:', error); 170 }); 171 }; 172 173})(); 174 175 176 177function dontsubmit() { 178 return false; 179}
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.