1- // Image Slideshow
1+ // Slideshow
22const imagePath = 'assets/' ;
33const len = 23 ;
44const images = Array . from ( { length : len } , ( _ , i ) => `side${ i + 1 } .gif` ) ;
@@ -13,17 +13,29 @@ function seededRandom(seed) {
1313 return x - Math . floor ( x ) ;
1414}
1515
16+ function getDailyDefaultSlideIndex ( ) {
17+ const seed = getSeed ( ) ;
18+ return Math . floor ( seededRandom ( seed ) * len ) + 1 ;
19+ }
20+
1621let slideIndex = localStorage . getItem ( 'slideIndex' ) ;
22+ const dailyDefaultSlideIndex = getDailyDefaultSlideIndex ( ) ;
23+
1724if ( ! slideIndex ) {
18- const seed = getSeed ( ) ;
19- slideIndex = Math . floor ( seededRandom ( seed ) * len ) + 1 ;
25+ slideIndex = dailyDefaultSlideIndex ;
2026 localStorage . setItem ( 'slideIndex' , slideIndex ) ;
2127} else {
2228 slideIndex = parseInt ( slideIndex , 10 ) ;
29+ const lastAccessedDate = localStorage . getItem ( 'lastAccessedDate' ) ;
30+ const currentDate = new Date ( ) . toDateString ( ) ;
31+ if ( lastAccessedDate !== currentDate ) {
32+ slideIndex = dailyDefaultSlideIndex ;
33+ localStorage . setItem ( 'slideIndex' , slideIndex ) ;
34+ }
2335}
2436
37+ localStorage . setItem ( 'lastAccessedDate' , new Date ( ) . toDateString ( ) ) ;
2538const slideshow = document . getElementById ( 'slideshow' ) ;
26-
2739images . forEach ( ( img , i ) => {
2840 slideshow . innerHTML += `<div class="mySlides"><img src="${ imagePath } ${ img } " style="cursor:pointer;" onclick="changeSlide(1)"></div>` ;
2941} ) ;
@@ -41,26 +53,23 @@ function setSlide(n) {
4153 } ) ;
4254 localStorage . setItem ( 'slideIndex' , slideIndex ) ;
4355}
56+
4457setSlide ( slideIndex ) ;
4558
46- // Time and Date
59+ // Clock
4760function updateClock ( ) {
4861 const now = new Date ( ) ;
49- const dateString = now . toLocaleString ( 'en-GB' , {
50- weekday : 'long' ,
51- day : '2-digit' ,
52- month : '2-digit' ,
53- year : 'numeric' ,
54- hour : '2-digit' ,
55- minute : '2-digit' ,
56- second : '2-digit'
57- } ) . replace ( / , / g, '' ) ;
62+ const day = now . toLocaleDateString ( 'en-GB' , { weekday : 'long' } ) ;
63+ const dayOfMonth = String ( now . getDate ( ) ) . padStart ( 2 , '0' ) ;
64+ const month = String ( now . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
65+ const year = now . getFullYear ( ) ;
66+ const time = now . toLocaleTimeString ( 'en-GB' , { hour : '2-digit' , minute : '2-digit' , second : '2-digit' } ) ;
67+ const dateString = `${ day . charAt ( 0 ) . toUpperCase ( ) + day . slice ( 1 ) . toLowerCase ( ) } ${ dayOfMonth } -${ month } -${ year } ${ time } ` ;
5868 document . getElementById ( 'codes' ) . textContent = dateString ;
5969 setTimeout ( updateClock , 1000 ) ;
6070}
6171updateClock ( ) ;
6272
63-
6473// Background Animation
6574const canvasBody = document . getElementById ( "canvas" ) ;
6675const drawArea = canvasBody . getContext ( "2d" ) ;
0 commit comments