2
2
* Credits: dmorris, zyaro
3
3
* Modified for Ion (Intranet3) by: 2016jwoglom, 2025azhu
4
4
*/
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
+
5
18
$ ( function ( ) {
6
19
$ ( "head" ) . first ( ) . append ( "<script nomodule src='/static/js/vendor/js.cookie.min.js'></script>" ) ;
7
20
let enabled = Cookies . get ( "disable-theme" ) == "1" ? false : true ;
8
21
9
22
if ( enabled ) {
10
23
// 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" ) ) ;
12
25
if ( dayStreak == null ) {
13
- Cookies . set ( "dayStreak" , 1 , { expires : 5 * 7 } ) ;
14
26
dayStreak = 1 ;
27
+ Cookies . set ( "dayStreak" , encodeBase64 ( String ( dayStreak ) ) , { expires : 5 * 7 } ) ;
15
28
}
16
29
17
30
let day = new Date ( ) . getDate ( ) ;
@@ -21,8 +34,8 @@ $(function () {
21
34
prevDay = day ;
22
35
}
23
36
if ( prevDay < day ) {
24
- Cookies . set ( "dayStreak" , parseInt ( dayStreak ) + 1 , { expires : 5 * 7 } ) ;
25
37
dayStreak = parseInt ( dayStreak ) + 1 ;
38
+ Cookies . set ( "dayStreak" , encodeBase64 ( String ( dayStreak ) ) , { expires : 5 * 7 } ) ;
26
39
Cookies . set ( "prevDay" , day , { expires : 5 * 7 } ) ;
27
40
}
28
41
@@ -538,12 +551,12 @@ function toggleTheme() {
538
551
539
552
function handleDecreaseSnowStreak ( ) {
540
553
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" ) ) ;
542
555
if ( dayStreak <= 1 ) {
543
556
alert ( "Your snow streak is already 1 and cannot be decreased further." ) ;
544
557
return ;
545
558
}
546
- Cookies . set ( "dayStreak" , parseInt ( dayStreak ) - 1 , { expires : 5 * 7 } ) ;
559
+ Cookies . set ( "dayStreak" , encodeBase64 ( String ( parseInt ( dayStreak ) - 1 ) ) , { expires : 5 * 7 } ) ;
547
560
location . reload ( ) ;
548
561
}
549
562
}
0 commit comments