Skip to content

Commit

Permalink
No longer request cookies if the user has refused
Browse files Browse the repository at this point in the history
  • Loading branch information
Romitou committed May 9, 2024
1 parent da86ac7 commit ec32950
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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
2 changes: 1 addition & 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()) {
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 Down

0 comments on commit ec32950

Please sign in to comment.