Last active
February 22, 2022 04:01
-
-
Save KaiCode2/12feef43fec79bde1f8a35e3967a6134 to your computer and use it in GitHub Desktop.
A simple snippet of code to add Squarespace website to add an age confirmation pop-up. To add, go to Setting > Advanced > Code Injection and add the below into the header. Note: Change the imageUrl (line #24) and change the ageGateUrl (lines #43, #51) to redirected underage visitors
This file contains 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
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script> | |
<script type="text/javascript"> | |
//document.onload = checkAge(document.URL); | |
function setCookie(name, value, days) { | |
var d = new Date(); | |
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000)); | |
var expires = "expires="+d.toGMTString(); | |
document.cookie = name + "=" + value + "; " + expires + "; path=/"; | |
} | |
var getCookie = function(name) { | |
var value = "; " + document.cookie; | |
var parts = value.split("; " + name + "="); | |
if (parts.length == 2) { | |
return parts.pop().split(";").shift(); | |
} | |
}; | |
function JSconfirm(){ | |
swal.fire({ | |
title: "May we see some ID please?", | |
text: "Please confirm you are of legal age and reside in Canada.", | |
imageUrl: 'https://drive.google.com/uc?id=1BbDT_qawXQHEMRpSfPmLhgwCbsBD08JP', | |
imageWidth: 120, | |
imageHeight: 120, | |
imageAlt: '', | |
closeOnClickOutside: false, | |
closeOnEsc: false, | |
allowEnterKey: false, | |
showCancelButton: true, | |
confirmButtonText: 'Yes', | |
cancelButtonText: 'No ', | |
focusConfirm: false, | |
reverseButtons: true, | |
backdrop: `background-color: #171717EF;` | |
}) | |
.then((isConfirm) => { | |
if (isConfirm) { | |
setCookie('legal', 1, 30); | |
swal.fire({title: "You're all set!", icon:"success", timer: 1400}); | |
} else { | |
ageGateUrl = 'https://www.treehousecannabis.xyz/age-unverified' | |
window.location.href = decodeURIComponent(ageGateUrl); | |
} | |
});; | |
} | |
document.addEventListener('DOMContentLoaded', function() { | |
if (!getCookie('legal')) { | |
ageGateUrl = 'https://www.treehousecannabis.xyz/age-unverified' | |
if (window.location.href == ageGateUrl) return; | |
JSconfirm(); | |
} | |
}); | |
</script> | |
<style> | |
.swal2-modal { | |
background-color: #17332A; | |
} | |
.swal2-styled.swal2-cancel { | |
color: #171717; | |
width: 100; | |
background-color: #F2F7ED; | |
} | |
.swal2-styled.swal2-confirm { | |
color: #F2F7ED; | |
border: none; | |
width: 100; | |
background-color: #308989; | |
} | |
.swal2-title { | |
color: #F2FDF7; | |
} | |
.swal2-content { | |
color: #F2F7ED; | |
} | |
body.swal2-shown > [aria-hidden="true"] { | |
filter: blur(10px); | |
} | |
body > * { | |
transition: 0.1s filter linear; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment