22 * Credits: dmorris, zyaro
33 * Modified for Ion (Intranet3) by: 2016jwoglom, 2025azhu
44 */
5+
6+ function encodeBase64 ( str ) {
7+ return btoa ( unescape ( encodeURIComponent ( str ) ) ) ;
8+ }
9+
10+ function decodeBase64 ( str ) {
11+ try {
12+ return decodeURIComponent ( escape ( atob ( str ) ) ) ;
13+ } catch ( e ) {
14+ return null ;
15+ }
16+ }
17+
518$ ( function ( ) {
619 $ ( "head" ) . first ( ) . append ( "<script nomodule src='/static/js/vendor/js.cookie.min.js'></script>" ) ;
720 let enabled = Cookies . get ( "disable-theme" ) == "1" ? false : true ;
821
922 if ( enabled ) {
1023 // Snow streak - How many days in a row the user has seen the theme. Controls size and speed of snow.
11- let dayStreak = Cookies . get ( "dayStreak" ) ;
24+ let dayStreak = decodeBase64 ( Cookies . get ( "dayStreak" ) ) ;
1225 if ( dayStreak == null ) {
13- Cookies . set ( "dayStreak" , 1 , { expires : 5 * 7 } ) ;
1426 dayStreak = 1 ;
27+ Cookies . set ( "dayStreak" , encodeBase64 ( String ( dayStreak ) ) , { expires : 5 * 7 } ) ;
1528 }
1629
1730 let day = new Date ( ) . getDate ( ) ;
@@ -21,8 +34,8 @@ $(function () {
2134 prevDay = day ;
2235 }
2336 if ( prevDay < day ) {
24- Cookies . set ( "dayStreak" , parseInt ( dayStreak ) + 1 , { expires : 5 * 7 } ) ;
2537 dayStreak = parseInt ( dayStreak ) + 1 ;
38+ Cookies . set ( "dayStreak" , encodeBase64 ( String ( dayStreak ) ) , { expires : 5 * 7 } ) ;
2639 Cookies . set ( "prevDay" , day , { expires : 5 * 7 } ) ;
2740 }
2841
@@ -538,12 +551,12 @@ function toggleTheme() {
538551
539552function handleDecreaseSnowStreak ( ) {
540553 if ( confirm ( "Are you sure you want to decrease your snow streak by 1?" ) ) {
541- let dayStreak = Cookies . get ( "dayStreak" ) ;
554+ let dayStreak = decodeBase64 ( Cookies . get ( "dayStreak" ) ) ;
542555 if ( dayStreak <= 1 ) {
543556 alert ( "Your snow streak is already 1 and cannot be decreased further." ) ;
544557 return ;
545558 }
546- Cookies . set ( "dayStreak" , parseInt ( dayStreak ) - 1 , { expires : 5 * 7 } ) ;
559+ Cookies . set ( "dayStreak" , encodeBase64 ( String ( parseInt ( dayStreak ) - 1 ) ) , { expires : 5 * 7 } ) ;
547560 location . reload ( ) ;
548561 }
549562}
0 commit comments