Skip to content

Commit

Permalink
feat: Hice banner cookie by default. Save in localstorage user cookie…
Browse files Browse the repository at this point in the history
… preferences
  • Loading branch information
povedica committed Nov 23, 2023
1 parent 29c70a0 commit 8919644
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions css/game.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ body, html {
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
z-index: 1000;
font-family: Arial, sans-serif; /* Fuente más moderna */
display: none;
}

/* Estilo para el modal */
Expand Down
27 changes: 24 additions & 3 deletions js/CookieLegal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const cookiePolicyVersion = "1.0";

function openModal() {
var modal = document.getElementById("cookiePolicyModal");
var contentContainer = document.getElementById("cookiePolicyContent");

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
contentContainer.innerHTML = xhr.responseText;
modal.style.display = "block";
Expand All @@ -20,9 +22,28 @@ function closeModal() {
function acceptCookies() {
// Aquí va el código para manejar la aceptación de cookies
document.getElementById('cookieConsentPopup').style.display = 'none';
setCookieConsentInLocalStorage(true);
}

function rejectCookies() {
// Aquí va el código para manejar el rechazo de cookies
document.getElementById('cookieConsentPopup').style.display = 'none';
}
setCookieConsentInLocalStorage(false)
}

function setCookieConsentInLocalStorage(consent) {
const consentData = {
consented: consent,
version: cookiePolicyVersion,
date: new Date().toISOString()
};
localStorage.setItem('cookieConsent', JSON.stringify(consentData));
}

window.onload = function () {
const consentString = localStorage.getItem('cookieConsent');

if (!consentString) {
document.getElementById('cookieConsentPopup').style.display = 'block';
return;
}
};

0 comments on commit 8919644

Please sign in to comment.