consent check page
All checks were successful
/ build (push) Successful in 30s

This commit is contained in:
Nycki 2025-06-30 14:28:06 -07:00
parent 130bdd2df3
commit f235ca54ce
4 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,10 @@
---
layout: base.njk
title: Kitty and Bunny Fortune
subtitle: since they're not related, it'll be ok!
permalink: /characters/fortunes/
---
<script src="/first-time.js"></script>
<script>firstTime.check('horny');</script>
If you're here, you're in >:3

View file

@ -0,0 +1,15 @@
---
layout: base.njk
title: horny check
permalink: /first-time-horny/
---
<script src="/first-time.js"></script>
You've requested a page that might have something horny on it. Something R-18. Something not safe for work, even. It's probably just cartoon boobs.
Are you AN ADULT and you WANT TO SEE THAT?
<button onclick="firstTime.grant('horny')">Yes, I'm an adult and I want to see that.</button>
<button onclick="firstTime.leave()">No thanks, get me out of here.</button>
<button onclick="localStorage.removeItem('first-time-horny'); firstTime.leave()">Clear this setting.</button>

95
static/first-time.js Normal file
View file

@ -0,0 +1,95 @@
/**
* first-time.js by Nick "Nycki" Lamicela, 2025.
*
* A simple script for redirecting the user to a "first time here" page, for example, a nsfw content opt-in page.
*
* You may use this on your site, with or without attribution.
*/
const firstTime = {};
/**
* Check if the user has opted into this gate. If not, redirect to gate page.
*
* Usage: in the head of each protected page.
*
* <head>
* <script src="/firstTime.js"></script>
* <script>firstTime.check("consent");</script>
* </head>
*/
firstTime.check = function (key='default', href=`/first-time-${key}/`) {
const currentSetting = localStorage.getItem(`first-time-${key}`);
if (currentSetting === 'granted') {
// do nothing
return;
} else {
// redirect to gate
const nextPage = window.location;
window.location.replace(`${href}?next=${nextPage}`);
}
};
/**
* Grant the user access to this gate.
*
* Usage: on the gate page.
*
* <head>
* <script src="/firstTime.js"></script>
* </head>
* <body>
* <button onclick="firstTime.grant('consent')">I Consent</button>
* </body>
*/
firstTime.grant = function (key='default') {
// save preference
localStorage.setItem(`first-time-${key}`, 'granted');
// redirect back to original page
let nextPage = '/';
const queries = (window.location.search || '').slice(1).split('&');
for (const query of queries) {
const [k, v] = query.split('=', 2);
if (k == 'next') {
nextPage = v;
}
}
window.location.replace(nextPage);
};
/**
* "No thanks" button for leaving a gate.
*
* Optional: on the gate page, after the consent button.
*
* <head>
* <script src="/firstTime.js"></script>
* </head>
* <body>
* <button onclick="firstTime.grant('consent')">I Consent</button>
* <button onclick="firstTime.leave('/index.html')">No Thanks</button>
* </body>
*/
firstTime.leave = function (href='/') {
window.location.replace(href);
};
/**
* "Clear settings" button for resetting a gate.
*
* Optional: on the gate page.
*
* <head>
* <script src="/firstTime.js"></script>
* </head>
* <body>
* <button onclick="firstTime.grant('consent')">I Consent</button>
* <button onclick="firstTime.leave()">No Thanks</button>
* <button onclick="firstTime.clear('consent'); firstTime.leave()">Clear this setting.</button>
* </body>
*/
firstTime.clear = function (key='default') {
localStorage.removeItem(`first-time-${key}`);
};