Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer request cookies if the user has refused #61

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions docs/templates/js/functions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
let isCookiesAccepted = getCookie("cookies-accepted") === "true";

// <> Cookies

// Returns whether the user has accepted the cookies or not, or undefined if the user hasn't chosen yet
function isCookiesAccepted() {
const cookie = getCookie("cookies-accepted");
if (!cookie) {
return undefined;
}
return Boolean(cookie);
}

function setCookie(cname, cvalue, exdays, force = false) {
if (!isCookiesAccepted && !force)
if (!isCookiesAccepted() && !force)
return;

const d = new Date();
Expand Down Expand Up @@ -37,7 +45,7 @@ function getCookie(cname) {
* @param {double} exdays time in days
*/
function setStorageItem(item, value, exdays, force = false) {
if (!isCookiesAccepted && !force)
if (!isCookiesAccepted() && !force)
return;

const d = new Date();
Expand Down
3 changes: 2 additions & 1 deletion docs/templates/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ if (examples) {
// Example Collapse </>

// <> Cookies Accecpt
if (!isCookiesAccepted) {
if (isCookiesAccepted() === undefined) {
document.body.insertAdjacentHTML('beforeend', `<div id="cookies-bar"> <p> We use cookies and local storage to enhance your browsing experience and store github related statistics. By clicking "Accept", you consent to our use of cookies and local storage. </p><div style="padding: 10px; white-space: nowrap;"> <button id="cookies-accept">Accept</button> <button id="cookies-deny">Deny</button> </div></div>`);
}

Expand All @@ -402,6 +402,7 @@ if (cookiesAccept && cookiesDeny) {
cookiesBar.remove();
});
cookiesDeny.addEventListener('click', () => {
setCookie('cookies-accepted', false, 99, true);
cookiesBar.remove();
});
}
Expand Down