-
Notifications
You must be signed in to change notification settings - Fork 2
/
speech.min.js
1 lines (1 loc) · 3.87 KB
/
speech.min.js
1
!function(){var e=document.querySelector(".speech"),n=document.querySelector(".start"),t=document.querySelector(".stop"),o=document.querySelector(".main"),i=document.querySelector(".statusBar"),r=document.querySelector(".instructionBtn"),c=document.querySelector(".instructionClose"),s=document.querySelector(".smallText"),l=document.querySelectorAll(".markText"),a=document.querySelector(".clear"),u=document.querySelector(".notSupport");window.SpeechRecognition||window.webkitSpeechRecognition?(window.SpeechRecognition=window.SpeechRecognition||window.webkitSpeechRecognition,u.classList.add("hide")):u.classList.add("show");var d=new SpeechRecognition;d.interimResults=!0,d.onresult=(e=>{if(e.results[0].isFinal){var n=document.createElement("span"),t=document.createElement("p");if(n.innerHTML=t.innerHTML=e.results[0][0].transcript,n.innerHTML.includes("open alert")&&alert("alert box open!"),n.innerHTML.includes("line break")&&(n.innerHTML="<p></p>",console.log(n.innerHTML)),n.innerHTML.includes("paragraph break")&&(n.innerHTML="<br><br>",console.log(n.innerHTML)),n.innerHTML.includes("full stop")&&(n.innerHTML=n.innerHTML.replace(/(full stop)/g,". ")),n.innerHTML.includes("comma")&&(n.innerHTML=", "),n.innerHTML.includes("exclamation sign")&&(n.innerHTML=n.innerHTML.replace(/(exclamation sign)/g,"! ")),["green","purple","yellow","white","tomato","tan","thistle","wheat","lime"].map(e=>{n.innerHTML.toLowerCase().trim()===e?document.body.style.background=e:console.log("no match!")}),t.innerHTML.includes("delete now")){var i=Array.from(document.querySelectorAll(".main span"));i.splice(this.length-1,2),o.innerHTML="",i.map(e=>{""===e.innerHTML?console.log(e):o.appendChild(e)})}else t.innerHTML.includes("send email")?(()=>{if(""===o.innerText)alert("No text is there for sending email!\nPlease click 'Start' button to speak.\nYou're great. You can do it. Just Yell !");else{var e,n,t,i,r,c=Array.from(document.querySelectorAll(".main span"));c.map((o,s)=>{"<p></p>"===o.innerHTML&&(t=s),e=c.slice(0,t),n=c.slice(t+1,c.length),i=e.map(e=>e.innerHTML),r=n.map(e=>e.innerHTML)}),window.open("mailto:[email protected]?subject="+i.join(" ")+"&body="+r.join(" ").replace(/(<br><br>)/g,"%0D"),"_self")}})():t.innerHTML.includes("send Gmail")?(()=>{if(""===o.innerText)alert("No text is there for sending email!\nPlease click 'Start' button to speak.\nYou're great. You can do it. Just Yell !");else{var e,n,t,i,r,c=Array.from(document.querySelectorAll(".main span"));c.map((o,s)=>{"<p></p>"===o.innerHTML&&(t=s),e=c.slice(0,t),n=c.slice(t+1,c.length),i=e.map(e=>e.innerHTML),r=n.map(e=>e.innerHTML)}),window.open("https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&[email protected]&su="+i.join(" ")+"&body="+r.join(" ").replace(/(<br><br>)/g,"%0D")+"&[email protected]&[email protected]","_blank")}})():o.appendChild(n)}}),d.onend=(()=>{t.classList.contains("speechEnd")?d.stop():d.start()}),d.onnomatch=(()=>{console.log("Not Match!! Louder")}),n.onclick=(()=>{d.start(),e.innerHTML="",n.classList.add("disable"),n.tabIndex="-1",t.classList.remove("speechEnd")}),t.onclick=(()=>{d.stop(),e.innerHTML="( Click start button & talk )",n.classList.remove("disable"),n.tabIndex="0",t.classList.add("speechEnd")}),a.onclick=(()=>o.innerHTML=""),d.onspeechstart=(()=>{console.log("speech start"),i.classList.add("statusActive")}),d.onspeechend=(()=>{console.log("speech start"),i.classList.remove("statusActive")}),d.onaudiostart=(()=>{console.log("audio start")}),s.onmouseover=(()=>{Array.from(l).map(e=>e.style.outline="2px solid red")}),s.onmouseout=(()=>{Array.from(l).map(e=>e.style.outline="0")}),r.onclick=(()=>{document.querySelector(".instructionContainer").classList.add("show"),document.querySelector(".instructionContainer").classList.remove("hide"),c.tabIndex=0}),c.onclick=(()=>{document.querySelector(".instructionContainer").classList.add("hide"),document.querySelector(".instructionContainer").classList.remove("show"),c.tabIndex=-1})}();