Skip to content

Instantly share code, notes, and snippets.

@joshua-koehler
Created July 25, 2023 02:37
Show Gist options
  • Save joshua-koehler/f7e97f9f09bc59e7049eecd261b303fd to your computer and use it in GitHub Desktop.
Save joshua-koehler/f7e97f9f09bc59e7049eecd261b303fd to your computer and use it in GitHub Desktop.
Close website on Christian Sabbath on the client side
<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>
@joshua-koehler
Copy link
Author

joshua-koehler commented Jul 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment