Created
July 25, 2023 02:37
-
-
Save joshua-koehler/f7e97f9f09bc59e7049eecd261b303fd to your computer and use it in GitHub Desktop.
Close website on Christian Sabbath on the client side
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> | |
function replacelinks() { | |
document.querySelectorAll('a').forEach(el => el.href = "/resources-links/website-closed-for-the-sabbath"); | |
} | |
function close() { | |
const closedOnSabbathUrl = "https://gisbornefpchurch.org.nz/resources-links/website-closed-for-the-sabbath"; | |
const d = new Date(); | |
// is Sabbath in local time or in NZ | |
const isSabbath = d.getDay() === 0 || (d.getUTCDay() === 6 && d.getUTCHours() >= 12) || (d.getUTCDay() === 0 && d.getUTCHours() < 12) | |
if(window.location.href != closedOnSabbathUrl && isSabbath){ | |
setTimeout(replacelinks, 800); | |
window.location.replace(closedOnSabbathUrl); | |
} | |
if(window.location.href == closedOnSabbathUrl && isSabbath){ | |
setTimeout(replacelinks, 800); | |
} | |
} | |
close(); | |
setInterval(close, 500); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script does two things:
If it's the Sabbath on the user's local, or the Sabbath in NZ:
1. Redirect to Website Closed for Sabbath page
2. Replace all href links to point to the Website Closed for Sabbath page so the user can't navigate away from the page
I have this script run every 500ms to check.
Put this script in the head tags of a site, and adjust the UTC offset for the location your server is in.