From 7b0927060b743764155a6f1cb0a404b773a73ee7 Mon Sep 17 00:00:00 2001 From: Ashley Date: Mon, 7 Aug 2023 19:12:11 +0000 Subject: [PATCH] add optimaztion for code :3 --- html/poketube.ejs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/html/poketube.ejs b/html/poketube.ejs index bfc970b6..91d214c0 100644 --- a/html/poketube.ejs +++ b/html/poketube.ejs @@ -1625,7 +1625,7 @@ if (/[?&]autoplay=/.test(location.search)) { const refreshPage = () => { location.reload(); }; - + // Check if a timer is already set in localStorage const timer = localStorage.getItem('refreshTimer'); @@ -1634,13 +1634,21 @@ if (timer) { clearTimeout(timer); } -// Set a new timer to refresh the page after 1 hour +// Check if it's the first time the user visits the page +const isFirstLoad = localStorage.getItem(userlocalStorageKey) === null; + +// Set a new timer to refresh the page after 1 hour or on the first visit const newTimer = setTimeout(() => { refreshPage(); -}, 60 * 60 * 1000); // 1 hour in milliseconds +}, isFirstLoad ? 0 : 60 * 60 * 1000); // 1 hour in milliseconds // Save the new timer in localStorage localStorage.setItem('refreshTimer', newTimer); + +// Save the first load flag in localStorage if it's the first visit +if (isFirstLoad) { + localStorage.setItem(userlocalStorageKey, 'visited'); +}