Skip to content

Commit

Permalink
override lastVisit date
Browse files Browse the repository at this point in the history
  • Loading branch information
aorcsik committed Feb 20, 2024
1 parent 285d116 commit 8475172
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/js/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ import { loadCss } from "./common";

loadCss(require("../css/changelog.css"));

const now = new Date();
let lastVisitedDate = now;
const url = new URL(document.location.href);
const overrideLastVisit = url.searchParams.get("lastVisit");
const queryLoadMore = url.searchParams.get("loadMore");

let lastVisitedDate = new Date();
let newLastVisitDate = lastVisitedDate;

/** @type {string} */
const cookieName = "changelogLastVisit";
const cookiePattern = new RegExp(`${cookieName}=([^;]+);?`);
const cookieMatch = document.cookie.match(cookiePattern);
if (cookieMatch) lastVisitedDate = new Date(cookieMatch[1]);
if (cookieMatch) {
lastVisitedDate = new Date(decodeURIComponent(cookieMatch[1]));
}

if (overrideLastVisit) {
lastVisitedDate.setDate(lastVisitedDate.getDate() - parseInt(overrideLastVisit));
newLastVisitDate = lastVisitedDate;
}

const expires = new Date();
expires.setMonth(expires.getMonth() + 12);
let domain = '.bitrise.io';
if (window.location.host.match('localhost')) domain = 'localhost';
const cookieValue = encodeURIComponent(String(now))
if (window.location.host.match('localhost')) domain = null;
const cookieValue = encodeURIComponent(String(newLastVisitDate))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
document.cookie = `${cookieName}=${cookieValue};expires=${expires};domain=${domain};`;

const url = new URL(document.location.href);
const queryLastVisit = url.searchParams.get("lastVisit");
if (queryLastVisit) {
lastVisitedDate = new Date();
lastVisitedDate.setDate(lastVisitedDate.getDate() - parseInt(queryLastVisit));
}
const queryLoadMore = url.searchParams.get("loadMore");
document.cookie = `${cookieName}=${cookieValue};expires=${expires};` + (domain ? `domain=${domain};` : "");

/** @type {string} */
const apiBase = document.location.hostname.match(/(localhost|127\.0\.0\.1)/) ? "" : "https://bitrise.io";
Expand Down

0 comments on commit 8475172

Please sign in to comment.