Free javascript Hosting


user-episode-actions-off.js

Uploaded on Feb 14 2022 23:34 by 275541906e

function convertHMS(value, full = true) {
const sec = parseInt(value, 10); // convert value to number if it's string
let hours = Math.floor(sec / 3600); // get hours
let minutes = Math.floor((sec - (hours * 3600)) / 60); // get minutes
let seconds = sec - (hours * 3600) - (minutes * 60); // get seconds
// add 0 if value < 10; Example: 2 => 02
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
if ( full == true ) {
return hours+':'+minutes+':'+seconds; // Return is HH : MM : SS
} else {
return minutes+':'+seconds; // Return is MM : SS
}
}

function percentage(full, compare) {
calculate = (compare*100);
calculate = calculate/full;
return Math.round(calculate);
}

function salvaTempo(_time, epid) {
let salvaTempoLS = localStorage.getItem('sirius_continue_watching');

if ( salvaTempoLS == null ) {
localStorage.setItem('sirius_continue_watching', JSON.stringify({}));
let salvaTempoLS = JSON.parse(localStorage.getItem('sirius_continue_watching'));

salvaTempoLS[epid] = {'current_time': _time};

localStorage.setItem('sirius_continue_watching', JSON.stringify(salvaTempoLS));
} else {
salvaTempoLS = JSON.parse(salvaTempoLS);

if ( Object.keys(salvaTempoLS).length > 0 && epid in salvaTempoLS ) {
salvaTempoLS[epid].current_time = _time;
localStorage.setItem('sirius_continue_watching', JSON.stringify(salvaTempoLS));
} else {
salvaTempoLS[epid] = {'current_time': _time};
// console.log(salvaTempoLS);
localStorage.setItem('sirius_continue_watching', JSON.stringify(salvaTempoLS));
}
}
}

function recuperaTempo(epid) {
let recuperaTempoLS = localStorage.getItem('sirius_continue_watching');

if ( recuperaTempoLS != null ) {
recuperaTempoLS = JSON.parse(recuperaTempoLS);
if ( Object.keys(recuperaTempoLS).length > 0 && epid in recuperaTempoLS ) {
return recuperaTempoLS[epid].current_time;
} else {
return false;
}
} else {
return false;
}
}

// When click in next ep button
$(document).on('click', '.rteam_autoplaynext', function(e){
e.preventDefault();
window.top.location.href = next_ep;
});

var isSeeked = false,
epi_duration = 0,
epi_current_time = 0;

$(document).ready(function(){
jwplayer().on('ready', function() {
// Somente se houver proximo ep
if ( next_ep ) {
$('#player').append(`<a href="${next_ep}" class="rteam_autoplaynext"></a>`);
}

// Play
jwplayer().on('play', function() {
if ( isSeeked == false ) {
isSeeked = true;

if ( typeof continueWatching !== 'undefined' ) {
recuperaTempo = recuperaTempo(current_episode_id);
if ( recuperaTempo ) {
jwplayer().seek(recuperaTempo);
} else if ( continueWatching !== false ) {
jwplayer().seek(continueWatching);
}
} else {
recuperaTempo = recuperaTempo(current_episode_id);
if ( recuperaTempo ) {
jwplayer().seek(recuperaTempo);
}
}
}
});

jwplayer().on('complete', function() {
// Somente se houver proximo ep
if ( next_ep ) {
$('.rteam_autoplaynext').removeClass('active');

window.top.location.href = next_ep;
}
});

// On Time
jwplayer().on('time', function(event) {
if ( epi_duration <= 0 ) {
// console.log('armazenei a duração do vídeo')
epi_duration = event.duration;
}

// Pega o tempo atual do vídeo
if ( epi_duration > 0 && epi_current_time <= epi_duration && !isNaN(Math.round(event.currentTime)) && epi_current_time != Math.round(event.currentTime) ) {
epi_current_time = Math.round(event.currentTime);
// console.log(`tempo que passou: ${convertHMS(epi_current_time)} e você já assistiu ${percentage(epi_duration, epi_current_time)}% e assistiu ${percentage(epi_duration, realTime)}% realmente`)
}

// Somente se houver proximo ep
if ( next_ep && epi_duration > 0 && (epi_duration - epi_current_time) <= 30 ) {
if ( !$('.rteam_autoplaynext').hasClass('.active') ) {
$('.rteam_autoplaynext').addClass('active');
}

$('.rteam_autoplaynext').html(`Próximo Episódio em ${convertHMS(epi_duration-epi_current_time, false)}`);
}

// Salva o tempo do ep
if ( event.currentTime != null && event.duration != null && (event.duration-event.currentTime) > 30 ) {
salvaTempo(event.currentTime, current_episode_id);
}
});
});
});

Back to list