Last active
May 25, 2022 12:04
-
-
Save dantetesta/49074fffbda27821efd3925ba89fa574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*BY: ASK JARVIS + DANTE TESTA */ | |
<style> | |
.aberto, .fechado, .lista-horarios{ | |
display: none; | |
} | |
</style> | |
<script> | |
window.onload = function() { | |
var dia_semana = new Date().toLocaleString('pt-BR', {weekday: 'short'}).replace('.', ''); | |
var hora_atual_inicial = dia_semana+'-ini'; | |
var hora_atual_final = dia_semana+'-fim'; | |
var hora_corrente = getCurrentTime(); | |
jQuery('.horarios').each(function(){ | |
var hora_inicial = jQuery(this).find('.'+hora_atual_inicial+' h2').text(); | |
var hora_final = jQuery(this).find('.'+hora_atual_final+' h2').text(); | |
if (isOpen(hora_inicial, hora_final, hora_corrente)) { | |
jQuery(this).find('.aberto').css('display','block'); | |
jQuery(this).find('.fechado').css('display','none'); | |
} else { | |
jQuery(this).find('.aberto').css('display','none'); | |
jQuery(this).find('.fechado').css('display','block'); | |
} | |
}); | |
} | |
function isOpen(start, end, current) { | |
const startTime = start.split(':'); | |
const endTime = end.split(':'); | |
const currentTime = current.split(':'); | |
const startHour = parseInt(startTime[0]); | |
const startMinute = parseInt(startTime[1]); | |
const endHour = parseInt(endTime[0]); | |
const endMinute = parseInt(endTime[1]); | |
const currentHour = parseInt(currentTime[0]); | |
const currentMinute = parseInt(currentTime[1]); | |
if (currentHour >= startHour && currentHour <= endHour) { | |
if (currentHour === startHour && currentMinute < startMinute) { | |
return false; | |
} else if (currentHour === endHour && currentMinute > endMinute) { | |
return false; | |
} else { | |
return true; | |
} | |
} else { | |
return false; | |
} | |
} | |
function getCurrentTime() { | |
const date = new Date(); | |
const hours = date.getHours(); | |
const minutes = date.getMinutes(); | |
return `${hours}:${minutes}`; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment