(function () {
var scriptName = "embed.js"; //name of this script, used to get reference to own tag
var jQuery; //noconflict reference to jquery
var jqueryPath = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.1/jquery.min.js";
var jqueryVersion = "1.12.1";
var scriptTag; //reference to the html script tag
/******** Get reference to self (scriptTag) *********/
var allScripts = document.getElementsByTagName('script');
var targetScripts = [];
for (var i in allScripts) {
var name = allScripts[i].src
if(name && name.indexOf(scriptName) > 0)
targetScripts.push(allScripts[i]);
}
scriptTag = targetScripts[targetScripts.length - 1];
audiomeIsLoaging = false;
/******** helper function to load external scripts *********/
function loadScript(src, onLoad) {
var script_tag = document.createElement('script');
script_tag.setAttribute("type", "text/javascript");
script_tag.setAttribute("src", src);
if (script_tag.readyState) {
script_tag.onreadystatechange = function () {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
onLoad();
}
};
} else {
script_tag.onload = onLoad;
}
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
}
/******** helper function to load external css *********/
function loadCss(href) {
var link_tag = document.createElement('link');
link_tag.setAttribute("type", "text/css");
link_tag.setAttribute("rel", "stylesheet");
link_tag.setAttribute("href", href);
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(link_tag);
}
/******** load jquery into 'jQuery' variable then call main ********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== jqueryVersion) {
loadScript(jqueryPath, initjQuery);
} else {
initjQuery();
}
function initjQuery() {
jQuery = window.jQuery.noConflict(true);
main();
}
function audiomeConsoleLog(strlog) {
if (audiomeLog == true) {
//console.log(strlog);
}
}
function VejaTambemStart(objcontent){
console.log ("VejaTambemIni INI")
var VT_RemoteUrl = 'https://vejatambem.com.br'
var VT_HostName = getHostName(document.location)
if (VT_HostName == "localhost") {
VT_RemoteUrl = "http://localhost:8080"
}
if (VT_HostName.indexOf("ngrok") > 0 ) {
VT_RemoteUrl = "http://localhost:8080"
}
VT_windowPathName = window.location.pathname;
var currentLocation = window.location.protocol + '//' + window.location.hostname + window.location.pathname
var VT_windowImage = jQuery('meta[property=og\\:image]').attr('content');
var url = VT_RemoteUrl + "/widget/" + objcontent.audiomeClientId + VT_windowPathName;
formData = {
'ContentTitle' : objcontent.audioMeTitle,
'ContentDescription' : objcontent.audioMeExcerpt,
'fullContent': objcontent.audiomeFullcontent,
'clienteId' : objcontent.audiomeClientId ,
'domain' : getHostName(document.location),
'fullPath' : currentLocation,
'ContentPic' : VT_windowImage,
}
jQuery.post( url,formData)
.done(function( data ) {
console.log("status -> " + data.status)
var contaFor = 0;
data.related.forEach(function(element) {
contaFor = contaFor + 1
if (contaFor <= 10 ) {
console.log("related Title-> " + element.ContentTitle);
console.log("related fullURL-> " + element.fullURL);
console.log("related Score-> " + element.ScoreRelated);
console.log("======================================= ");
}
});
});
}
function readMeAudioEnd(){
// console.log("--> readMeAudioEnd INIT <--");
jQuery("#readmeerror").append("
ReadMeAudioEnd ")
audiomePlayCount = audiomePlayCount + 1;
if (audiomePlayCount <= audiomeMp3List.length - 1) {
//console.log('Next file');
audiomeAudioSeek = 0
audiomeSeekPercent = 0
playAudioTTS(audiomeMp3List[audiomePlayCount])
} else {
rewindAudioTTS();
audiomeConsoleLog('Finished! Playlist');
}
}
function playAudioTTS(mp3) {
// console.log("--> playAudioTTS INIT <--");
jQuery("#readmeerror").append("
playAudioTTS ")
FireAnalytics("PlayAudio");
FireAnalyticsClienteReadme("PlayAudio");
jQuery("#audiomebtn-loader").hide();
if (audiomeSeekPercent > 0) {
audioMeProgress = audiomeSeekPercent * audiomeTotalTime;
audiomePlayCount = 0;
audiomeAudioSeek = audioMeProgress;
var audiomeAcumulador = 0
for ( i = 0 ; i < audiomeMp3List.length ; i++ ) {
audiomeAcumulador = audiomeAcumulador + audiomeMp3List[i].TotalSeconds
if (audiomeAcumulador < audioMeProgress) {
audiomePlayCount = i + 1;
audiomeAudioSeek = audioMeProgress - audiomeAcumulador
}
}
}
// console.log("--> PLAY <--");
// console.log("--> src --> " + audiomeMp3List[audiomePlayCount]);
// console.log("--> PlayCount --> " + audiomePlayCount);
// console.log("--> Seek --> " + audiomeAudioSeek);
readmeTTSAudio.src = audiomeMp3List[audiomePlayCount].url + "#t=" + audiomeAudioSeek
//readmeTTSAudio.src = "http://www.readme.com/file.mp3";
// console.log(" --> SRCLOAD ok");
var playPromise = readmeTTSAudio.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
readmeTTSAudio.playbackRate = readmeAudioSpeed
// Automatic playback started!
// Show playing UI.
// console.log("automatic play started");
})
.catch(error => {
// Auto-play was prevented
// Show paused UI.
audiomeErrorCount = audiomeErrorCount + 1;
// console.log("UPS, automatic play ERROR");
FireAnalytics("playPromise Error");
if (audiomeErrorCount < 6) {
// console.log("UPS, automatic play ERROR - TRY AGAIN " + audiomeErrorCount);
FireAnalytics("playPromise Error retry - " + audiomeErrorCount);
playAudioTTS(audiomeMp3List[audiomePlayCount]);
} else {
// console.log("UPS, automatic play ERROR - DIE");
FireAnalytics("playPromise Error DIE - ");
audiomeLoadAudio = false
audiomeIsLoaging = false
audiomeErrorCount = 0;
rewindAudioTTS();
}
});
}
FireAnalyticsClienteReadme("PlayAudio");
FireAnalytics("PlayAudio");
}
function playSponsoredAudioTTS(){
readmeTTSAudioSponsored.src = audiomeSponsoredAudio.SponsorFileName
console.log(" --> SPONSOR SPOT ok");
var playPromise = readmeTTSAudioSponsored.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
// Automatic playback started!
// Show playing UI.
// console.log("automatic SPONSOR play started");
})
.catch(error => {
// Auto-play was prevented
// Show paused UI.
audiomeSponsorErrorCount = audiomeSponsorErrorCount + 1;
// console.log("UPS, automatic SPONSOR play ERROR");
FireAnalytics("playPromise SPONSOR Error");
if (audiomeSponsorErrorCount < 3) {
// console.log("UPS, automatic SPONSOR play ERROR - TRY AGAIN " + audiomeSponsorErrorCount);
FireAnalytics("playPromise SPONSOR Error retry - " + audiomeSponsorErrorCount);
playSponsoredAudioTTS();
} else {
// console.log("UPS, automatic SPONSOR play ERROR - DIE");
FireAnalytics("playPromise SPONSOR Error DIE - ");
playAudioTTS(audiomeMp3List[audiomePlayCount]);
}
});
}
}
function playSponsoredSpotTTS(){
//readmeTTSSpotSponsored.src = "" + "http://localhost:27080/img/" + audiomeSponsoredSpot.banerKey
readmeTTSSpotSponsored.src = audiomeSponsoredSpot.SponsorFileName
// console.log(" --> SPONSOR SRCLOAD ok");
var playPromise = readmeTTSSpotSponsored.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
// Automatic playback started!
// Show playing UI.
// console.log("automatic SPONSOR SPOT play started");
})
.catch(error => {
// Auto-play was prevented
// Show paused UI.
audiomeSpotErrorCount = audiomeSpotErrorCount + 1;
// console.log("UPS, automatic SPONSOR SPOT play ERROR");
FireAnalytics("playPromise SPONSOR SPOT Error");
if (audiomeSpotErrorCount < 3) {
// console.log("UPS, automatic SPONSOR play ERROR - TRY AGAIN " + audiomeSpotErrorCount);
FireAnalytics("playPromise SPONSOR Error retry - " + audiomeSpotErrorCount);
playSponsoredSpotTTS();
} else {
// console.log("UPS, automatic SPONSOR play ERROR - DIE");
FireAnalytics("playPromise SPONSOR Error DIE - ");
playAudioTTS(audiomeMp3List[audiomePlayCount]);
}
});
}
}
function pauseAudioTTS() {
console.log("--> pauseAudioTTS INIT <--");
jQuery("#audiomeProgressBarAlpha").stop();
readmeTTSAudio.pause();
audiomeStatus = "pause"
jQuery("#audiomebtn-loader").hide();
jQuery("#audiomebtn-pause").hide();
jQuery("#audiomebtn-play").show();
//audiomeAudioSeek = audiomeHowlerList[audiomePlayCount].seek();
audiomeAudioSeek = readmeTTSAudio.currentTime;
// console.log('audiomeAudioSeek - ' + audiomeAudioSeek)
// console.log('audiomePlayCount - ' + audiomePlayCount)
jQuery("#audiomebtn-loader").hide();
setTimeout(function(){
audiomeIsLoaging = false;
}, 500);
}
function rewindAudioTTS() {
// console.log("--> rewindAudioTTS INIT <--");
FireAnalytics("EndAudio");
FireAnalyticsClienteReadme("EndAudio");
jQuery("#audiomeProgressBarAlpha").stop();
audiomePlayCount = 0
audiomeAudioSeek = 0
readmeTTSAudio.pause;
audiomeStatus = "pause";
jQuery("#audiomebtn-loader").hide();
jQuery("#audiomebtn-pause").hide();
jQuery("#audiomebtn-play").show();
FireAnalytics("EndAudio");
FireAnalyticsClienteReadme("EndAudio");
}
function audioMeCalculatetotalTime() {
// console.log("--> audioMeCalculatetotalTime INIT <--");
var audioCount = 0
contaAudios = audiomeMp3List.length;
contaLoaded = 0;
audiomeMp3List.forEach(function(element) {
var audiotimmer = new Audio();
audiotimmer.src = element.url;
audiotimmer.addEventListener('loadedmetadata', (event) => {
var source = audiotimmer.src;
// console.log("source -> " + source)
var TotalSeconds = parseInt(audiotimmer.duration);
audiomeTotalTime = audiomeTotalTime + TotalSeconds
// console.log( "Seconds - " + TotalSeconds);
// console.log( "audiomeTotalTime - " + audiomeTotalTime);
audioCount = audioCount + 1
audiomeMp3List.forEach(function(item) {
if (item.url == audiotimmer.src) {
item.TotalSeconds = audiotimmer.duration;
}
});
if (audioCount >= audiomeMp3List.length){
var minutes = parseInt(audiomeTotalTime / 60, 10);
var seconds = parseInt(audiomeTotalTime % 60);
if (minutes < 10 ) {minutes = "0" + minutes}
if (seconds < 10 ) {seconds = "0" + seconds}
audiomeTotalTimeDisplay = minutes + ":" + seconds ;
// console.log( "TotalTime display - " + audiomeTotalTimeDisplay);
audiomeMp3List.forEach(function(x) {
// console.log("audiomeMp3List.url " + x.url)
// console.log("audiomeMp3List.TotalSeconds " + x.TotalSeconds)
});
}
contaLoaded = contaLoaded + 1;
if(contaLoaded >= contaAudios && contaAudios > 0) // Significa que termonou o load dos audios
{
if (audiomeSponsoredBannerFlag == "ON") {
// mostra o banner patrocinado
console.log("Show Sponsored Banner")
var img = new Image();
img.src = audiomeSponsoredBanner.SponsorFileName;
img.id = "audiomeSponsoredImage"
var link = document.createElement("a");
link.id = "audiomeSponsoredLink"; // Create a
element
link.href = audiomeSponsoredBanner.bannerClick
link.target = "_blank"
document.getElementById('audiome-container').appendChild(link);
document.getElementById('audiomeSponsoredLink').appendChild(img);
jQuery("#audiomeSponsoredLink").fadeIn();
document.getElementById("audiomeSponsoredLink").addEventListener("click", audiomeSponsorClick);
}
if ( audiomeSponsoredAudioFlag == "ON") {
playSponsoredAudioTTS();
} else if ( audiomeSponsoredSpotFlag == "ON") {
playSponsoredSpotTTS()
} else {
playAudioTTS(audiomeMp3List[0]);
}
// audiomeHowlerList[0].play();
}
},0);
});
}
function AddPauseToContent(content, classname, tagname){
if (strip(tagname) != "") {
var x = document.getElementsByTagName(tagname);
////console.log("AddPauseToContent -> TAG " + tagname)
}
if (strip(classname) != "") {
var x = document.getElementsByClassName(classname);
////console.log("AddPauseToContent -> CLASS " + classname)
}
var i;
for (i = 0; i < x.length; i++) {
text = x[i].textContent.trim()
////console.log (classname + tagname + " -> " + text)
if (strip(text) != ""){
var replace = strip(text);
var re = new RegExp(replace,"g");
content = content.replace( re , text + '. ');
}
}
return content
}
function getHostName(fullurl){
var url = fullurl;
var hostname = (new URL(url)).hostname;
// console.log("hostname -> " + hostname)
return hostname;
}
function getTextElementByClass(classname){
var textbyclass = ""
var x = document.getElementsByClassName(classname);
var i;
for (i = 0; i < x.length; i++) {
textbyclass = x[i].textContent.trim() + " "
}
return textbyclass;
}
function getTextElementByTag(tagname){
var textbyclass = ""
var x = document.getElementsByTagName(tagname);
var i;
//for (i = 0; i < x.length; i++) {
// textbyclass = x[i].textContent.trim() + " "
//}
textbyclass = x[0].textContent.trim() + " "
return textbyclass;
}
function HideElementByAttribute(documentClone, atribute, value){
console.log("HideElementByAttribute")
var seletor = '[' + atribute + '="' + value + '"]';
var x = documentClone.querySelectorAll(seletor);
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
console.log("HideElementByAttribute 1")
}
return documentClone;
}
function HideElementByClass(documentClone, classname){
var x = documentClone.getElementsByClassName(classname);
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
return documentClone;
}
function HideElementByTagName(documentClone, tagname){
var x = documentClone.getElementsByTagName(tagname);
var i;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
return documentClone;
}
function HideElementByID(documentClone, idname){
// console.log(" HideElementByID -> " + idname)
var x = documentClone.getElementById(idname);
if (x != null ) {
x.style.display = "none";
}
return documentClone;
}
function HideElementByTEXT(documentClone, text, tag){
console.log(" HideElementByTEXT -> " + text)
//const text = 'Hello world';
const matches = [];
for (const div of documentClone.querySelectorAll(tag)) {
if (div.text = text) {
div.style.display = "none"
console.log("HideElementByTEXT FOUND ")
}
}
return documentClone;
}
const format = num => {
const n = String(num),
p = n.indexOf('.')
return n.replace(
/\d(?=(?:\d{3})+(?:\.|$))/g,
(m, i) => p < 0 || i < p ? `${m},` : m
)
}
function getLogValueFromCurrentURL(varName) {
const params = new URLSearchParams(window.location.search);
return params.get(varName);
}
function ReadabilityAjust(textIn){
textOut = textIn
textOut = textOut.trim()
textOut = textOut.replace(/\n{2,}/g, ' ');
// textOut = textOut.replace(/\n/g, '. ');
// textOut = textOut.replace(/\. \./g, '. ');
textOut = textOut.replace(/\s{2,}/g, ' ');
textOut = textOut.replace(/\.{2,}/g, '.');
textOut = textOut.replace(/\&/g, ' E ');
var str = textOut
var regex = /(\.)([ABCDEFGHIJKLMNOPQRSTUVXYZ])/g;
textOut = str.replace(regex, "$1 $2");
textOut = textOut.replace(/\#/g, ' ');
textOut = textOut.replace(/\{/g, ' ');
textOut = textOut.replace(/\}/g, ' ');
textOut = textOut.replace(/\“/g, '');
textOut = textOut.replace(/\”/g, '');
textOut = textOut.replace(/\[/g, '');
textOut = textOut.replace(/\]/g, '');
return textOut;
}
function strip(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent||tmp.innerText;
}
function clearString(mystring) {
return mystring.replace(/&/g, "&").replace(/>/g, ">").replace(/ LoadReadability INIT <--");
var documentClone = document.cloneNode(true);
// bloqueios padrao
documentClone = HideElementByID(documentClone, "audiome-container");
documentClone = HideElementByClass(documentClone, "twitter-tweet");
documentClone = HideElementByClass(documentClone, "instagram-media");
documentClone = HideElementByID(documentClone, "fb-root");
documentClone = HideElementByID(documentClone, "comments");
documentClone = HideElementByClass(documentClone, "OUTBRAIN");
documentClone = HideElementByID(documentClone, "taboola-below-article-thumbnails");
documentClone = HideElementByTagName(documentClone, "figcaption");
documentClone = HideElementByTagName(documentClone, "img");
documentClone = HideElementByTagName(documentClone, "figure");
// bloqueios do cliente
//documentClone = HideElementByTagName(documentClone, "span");
documentClone = HideElementByTagName(documentClone, "h1");
documentClone = HideElementByClass(documentClone, "post-interna__resumo");
documentClone = HideElementByClass(documentClone, "post-interna__data");
documentClone = HideElementByID(documentClone, "post-progresso");
documentClone = HideElementByClass(documentClone, "post-interna__tags-post");
documentClone = HideElementByClass(documentClone, "post-interna__paginacao");
documentClone = HideElementByClass(documentClone, "post-interna__categoria");
article = new Readability(documentClone).parse();
articlecontent = article.content.replace(/
/g, ".
");
articlecontent = articlecontent.replace(/<\/li>/g, ". ");
articlecontent = articlecontent.replace(/<\/h2>/g, ". ");
articlecontent = articlecontent.replace(/<\/h3>/g, ". ");
articlecontent = articlecontent.replace(/<\/p>/g, ".