Skip to content

Instantly share code, notes, and snippets.

@xandreafonso
Last active May 15, 2024 19:36
Show Gist options
  • Save xandreafonso/f873bafcf0add9b76700bc85f98116fc to your computer and use it in GitHub Desktop.
Save xandreafonso/f873bafcf0add9b76700bc85f98116fc to your computer and use it in GitHub Desktop.
Script delay Elementor plugin for Wordpress
<script>
/**
* - Use este parâmetro na URL para evitar o delay: videodelay=false
* - Use a classe CSS "video-delay" em todos os componentes e/ou seções que deseja esconder no delay.
* - Use a classe CSS "video-delay-reverse" em todos os componentes que ficaram ativos apenas durante o tempo de delay.
**/
// Abaixo tem-se as variáveis que armazenam o minuto e o segundo exato do vídeo em que se termina o delay.
const videoMinute = 14
const videoSecond = 18
const hideElements = () => {
const elements = document.querySelectorAll('.video-delay');
elements.forEach(e => e.style.display = 'none');
const elementsReverse = document.querySelectorAll('.video-delay-reverse');
elementsReverse.forEach(e => e.style.display = 'block');
const show = () => {
elements.forEach(e => e.style.display = 'block');
elementsReverse.forEach(e => e.style.display = 'none');
createCookie('video-delay', 'video-delay', 60)
};
const secondsToDelay = (60 * videoMinute) + videoSecond;
setTimeout(show, 1000 * secondsToDelay);
};
document.addEventListener("DOMContentLoaded", () => {
const urlParams = new URLSearchParams(window.location.search);
const delayParam = urlParams.get('videodelay');
const hideReverse = () => document.querySelectorAll('.video-delay-reverse').forEach(e => e.style.display = 'none');
if (delayParam === "false") {
hideReverse();
} else {
const cookieValue = getCookie('video-delay');
if (cookieValue) hideReverse();
else hideElements();
}
});
function createCookie(name, value, days) {
const now = new Date();
now.setTime(now.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "expires=" + now.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
function eraseCookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
function getCookie(name) {
const cookieArray = document.cookie.split(";");
for(let i = 0; i < cookieArray.length; i++) {
let cookieAttr = cookieArray[i];
while (cookieAttr.charAt(0) == " ") cookieAttr = cookieAttr.substring(1);
if (cookieAttr.indexOf(name) == 0) return cookieAttr.substring((name + "=").length, cookieAttr.length);
}
return "";
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment