Added a TTL parameter to setCookie()

This commit is contained in:
Veloman Yunkan 2023-02-09 16:23:59 +01:00
parent 514d6e6514
commit c85466995d
2 changed files with 12 additions and 8 deletions

View File

@ -46,10 +46,14 @@
return (url); return (url);
} }
function setCookie(cookieName, cookieValue) { function setCookie(cookieName, cookieValue, ttl) {
let exp = "";
if ( ttl ) {
const date = new Date(); const date = new Date();
date.setTime(date.getTime() + oneDayDelta); date.setTime(date.getTime() + ttl);
document.cookie = `${cookieName}=${cookieValue};expires=${date.toUTCString()};sameSite=Strict`; exp = `expires=${date.toUTCString()};`;
}
document.cookie = `${cookieName}=${cookieValue};${exp}sameSite=Strict`;
} }
function getCookie(cookieName) { function getCookie(cookieName) {
@ -375,7 +379,7 @@
if (filterType) { if (filterType) {
params.set(filterType, filterValue); params.set(filterType, filterValue);
window.history.pushState({}, null, `?${params.toString()}`); window.history.pushState({}, null, `?${params.toString()}`);
setCookie(filterCookieName, params.toString()); setCookie(filterCookieName, params.toString(), oneDayDelta);
} }
updateFilterColors(); updateFilterColors();
updateFeedLink(); updateFeedLink();
@ -520,7 +524,7 @@
} }
} }
updateFeedLink(); updateFeedLink();
setCookie(filterCookieName, params.toString()); setCookie(filterCookieName, params.toString(), oneDayDelta);
}; };
// required by i18n.js:setUserLanguage() // required by i18n.js:setUserLanguage()

View File

@ -63,7 +63,7 @@ const ResourceCollection resources200Compressible{
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.css" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.css" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=ac5767d8" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=ac5767d8" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.js" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.js" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=c333bdba" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=2f15ed7d" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/isotope.pkgd.min.js" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/isotope.pkgd.min.js" },
@ -284,7 +284,7 @@ R"EXPECTEDRESULT( href="/ROOT%23%3F/skin/index.css?cacheid=ac5767d8"
<script type="text/javascript" src="/ROOT%23%3F/skin/languages.js?cacheid=fe100348" defer></script> <script type="text/javascript" src="/ROOT%23%3F/skin/languages.js?cacheid=fe100348" defer></script>
<script src="/ROOT%23%3F/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script> <script src="/ROOT%23%3F/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script>
<script src="/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3"></script> <script src="/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3"></script>
<script type="text/javascript" src="/ROOT%23%3F/skin/index.js?cacheid=c333bdba" defer></script> <script type="text/javascript" src="/ROOT%23%3F/skin/index.js?cacheid=2f15ed7d" defer></script>
<img src="/ROOT%23%3F/skin/feed.png?cacheid=56a672b1" class="feedLogo" alt="Library OPDS Feed" aria-label="Library OPDS Feed" title="Library OPDS Feed"> <img src="/ROOT%23%3F/skin/feed.png?cacheid=56a672b1" class="feedLogo" alt="Library OPDS Feed" aria-label="Library OPDS Feed" title="Library OPDS Feed">
)EXPECTEDRESULT" )EXPECTEDRESULT"
}, },