n”;
console.log(“mySpeechElements” + mySpeechElements);
var accessibilityBox = document.getElementById(‘accessibility’);
if (accessibilityBox) {
accessibilityBox.innerHTML += mySpeechElements;
}
}
catch(err) {
console.log(“ERROR: ” + err);
}
}
jduyTTS.doRestart = function () {
window.speechSynthesis.cancel();
lastCharIndex=0;
document.getElementById(‘speechPercentRead’).innerHTML = “”;
document.getElementById(‘speechButtonRestart’).style.display = “none”;
}
jduyTTS.toggleValue= function (inputValue) {
if(inputValue == “Speak”) {
inputValue = “Stop”;
}
else {
inputValue= “Speak”;
}
return inputValue;
}
// RETURNS HTML TEXT INSIDE ELEMENTS WITH SPECIFIED IDS
jduyTTS.getMyText = function () {
jduyTTS.deleteAds(); // DELETE ADS FIRST
myText = “”;
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
if (myText == “”) {
if (document.getElementById(‘title-main’)) {
myText += “This Metro Weekly headline reads: ” + (document.getElementById(‘title-main’).innerHTML) + “. [end of headline]. “;
}
if (document.getElementById(‘content-area’)) {
myText += “This post’s content is: ” + (document.getElementById(‘content-area’).innerHTML);
}
// OUTPUT TEXT TO READ TO JS CONSOLE
console.log(myText);
myText = fixText(myText) + ” [End of post.]”;
// TEST
// document.getElementById(‘FatPandaFacebookComments’).innerText = myText;
return myText;
}
else {
// window.alert(“myText exists”);
return myText;
}
}
// FUNCTION REMOVES INCOMPATIBLE AD TEXT
//
jduyTTS.deleteAds = function () {
cleanText = “”;
// INFOLINKS
document.querySelectorAll(‘.IL_BASE’).forEach(function(a) {
a.remove()
})
for (i=0; i<5; i++) {
if (document.getElementById(‘IL_IN_ARTICLE_CONTAINER_’ + i)) {
var element = document.getElementById(‘IL_IN_ARTICLE_CONTAINER_’ + i);
element.parentNode.removeChild(element);
}
}
// MONSTER INSIGHTS
document.querySelectorAll(‘.monsterinsights-inline-popular-posts’).forEach(function(a) {
a.remove()
})
return;
}
// COOKIE FUNCTION VIA — http://www.w3schools.com/js/js_cookies.asp
function setMyCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = “expires=”+d.toUTCString();
document.cookie = cname + “=” + cvalue + “; ” + expires + “; path=/”;
}
function getMyCookie(cname) {
var name = cname + “=”;
var ca = document.cookie.split(‘;’);
for(var i=0; i
msgToSpeak = new SpeechSynthesisUtterance(getJumpToText(inputText,lastCharIndex));
}
else {
msgToSpeak = new SpeechSynthesisUtterance(inputText);
}
msgToSpeak.onstart = function(event) {
document.getElementById(‘mySpeechButton’).value = “Stop”;
document.getElementById(‘speechButtonResume’).style.display = “none”;
document.getElementById(‘speechButtonPause’).style.display = “inline”;
document.getElementById(“speechSpeaker”).src = “https://www.metroweekly.com/wp-content/metroweekly/speaker-on.gif”;
if (lastCharIndex > 0) {
document.getElementById(‘speechButtonRestart’).style.display = “inline”;
}
}
msgToSpeak.onend = function(event) {
document.getElementById(‘mySpeechButton’).value = “Speak”;
document.getElementById(‘speechButtonResume’).style.display = “none”;
document.getElementById(‘speechButtonPause’).style.display = “none”;
document.getElementById(“speechSpeaker”).src = “https://www.metroweekly.com/wp-content/metroweekly/speaker.gif”;
lastCharIndex += tempCharIndex;
if (lastCharIndex > 0) {
document.getElementById(‘speechButtonRestart’).style.display = “inline”;
}
// window.alert(lastCharIndex);
}
msgToSpeak.onpause = function(event) {
document.getElementById(‘speechButtonResume’).style.display = “inline”;
document.getElementById(‘speechButtonPause’).style.display = “none”;
document.getElementById(“speechSpeaker”).src = “https://www.metroweekly.com/wp-content/metroweekly/speaker-pause.gif”;
}
msgToSpeak.onresume = function(event) {
document.getElementById(‘speechButtonResume’).style.display = “none”;
document.getElementById(‘speechButtonPause’).style.display = “inline”;
document.getElementById(“speechSpeaker”).src = “https://www.metroweekly.com/wp-content/metroweekly/speaker-on.gif”;
}
msgToSpeak.onboundary = function(event) {
tempCharIndex = event.charIndex;
document.getElementById(“speechPercentRead”).innerHTML = getPercentRead();
}
window.onbeforeunload = function () {
window.speechSynthesis.cancel();
}
window.onunload = function () {
window.speechSynthesis.cancel();
}
if (Number(getMyCookie(‘speechRate’)) > 0) {
msgToSpeak.rate = getMyCookie(‘speechRate’)/10;
}
else {
msgToSpeak.rate = mySpeechRate;
}
/* if (this.DEST_LANG != “”) {
msgToSpeak.lang = this.DEST_LANG;
}
*/ window.speechSynthesis.speak(msgToSpeak);
}
}
catch (err) {
console.log(“ERROR: ” + err);
}
}
function getPercentRead() {
var percentRead=0;
var output = “”;
percentRead = 100-(Math.round(((myText.length – (lastCharIndex + tempCharIndex)) / myText.length)*100));
if (percentRead > 0) {
output = percentRead + ‘% ‘;
}
else {
output = “”;
}
return output;
}
function getJumpToText(myText,lastCharIndex) {
var jumpToText = “”;
jumpToText = myText.substring(lastCharIndex,myText.length);
return jumpToText;
}
function fixText(stringInput) {
var output = stringInput;
output = output.replace(/(</p>
)/ig,”[image caption.]</p>n
“);
output = output.replace(/(</p>)/ig,”[endparagraph] “);
output = output.replace(/(</h1>)/ig,”. “);
output = output.replace(/(</h2>)/ig,”. “);
output = output.replace(/(</h3>)/ig,”. “);
output = output.replace(/(</h4>)/ig,”. “);
output = output.replace(/(</h5>)/ig,”. “);
output = output.replace(/(</h6>)/ig,”. “);
output = output.replace(/(</li>)/ig,”. “);
output = output.replace(/(</td>)/ig,”. “);
output = output.replace(/(</div>)/ig,”. “);
output = output.replace(/(</ol>)/ig,”. “);
output = output.replace(/(</ul>)/ig,”. “);
output = output.replace(/()/ig,”. “);
output = output.replace(/(&)/ig,” and “);
output = output.replace(/()/ig,”. “);
output = output.replace(/( Va.)/g,”Virginia. “);
output = output.replace(/(LGBTQI)/g,”el gee be tee kew eye”);
output = output.replace(/( Md.)/g,”Maryland. “);
output = output.replace(/’/g ,”‘”); // ANGLE APOS
output = output.replace(/“/g ,”””); // ANGLE OPEN QUOTE
output = output.replace(/”/g ,”””); // ANGLE CLOSE QUOTE
output = output.replace(/D.C./g,”dee cee”);
output = output.replace(/(
end of table. “);
output = output.replace(/r/g ,”n”);
output = output.replace(/(n)+/g ,”n”);
output = output.replace(/n/g ,” “);
output = output.replace(/</p>