@@ -2,32 +2,38 @@ import eventManager from '../../utils/eventManager.js';
22import * as settings from '../../utils/settings/index.js' ;
33import { isApril , IMAGES } from '../../utils/isApril.js' ;
44
5+ const year = `${ new Date ( ) . getFullYear ( ) } ` ;
56const aprilFools = settings . register ( {
67 name : 'Disable April Fools Jokes' ,
78 key : 'underscript.disable.fishday' ,
89 note : 'Disables *almost* everything.' ,
9- hidden : ( ) => ! isApril ( ) ,
10+ data : { extraValue : year } ,
11+ hidden : ( ) => ! isApril ( ) || isSoftDisabled ( ) ,
1012 onChange ( ) {
1113 toggleFish ( $ ( 'body' ) ) ;
1214 } ,
1315} ) ;
16+ function isSoftDisabled ( ) {
17+ return localStorage . getItem ( aprilFools . key ) === year ;
18+ }
1419
1520const basePath = 'images' ;
1621
1722function toggleFish ( $el ) {
1823 const disabled = aprilFools . value ( ) ;
1924 const search = disabled ? IMAGES : basePath ;
20- const replace = disabled ? [ IMAGES , basePath ] : [ basePath , IMAGES ] ;
25+ const replace = disabled ? basePath : IMAGES ;
2126
2227 $el . find ( `img[src*="undercards.net/${ search } /"],img[src^="/${ search } /"],img[src^="${ search } /"]` ) . each ( ( _ , img ) => {
23- img . src = img . src . replace ( ... replace ) ;
24- } ) ;
28+ img . src = img . src . replace ( search , replace ) ;
29+ } ) . on ( 'error' , ( ) => aprilFools . set ( year ) ) ;
2530 $el . find ( `[style*="url(\\"${ search } /"]` ) . each ( ( i , img ) => {
26- img . style . background = img . style . background . replace ( ... replace ) ;
27- } ) ;
31+ img . style . background = img . style . background . replace ( search , replace ) ;
32+ } ) . on ( 'error' , ( ) => aprilFools . set ( year ) ) ;
2833}
2934
30- if ( isApril ( ) ) {
35+ eventManager . on ( 'undercards:season' , ( ) => {
36+ if ( ! isApril ( ) || isSoftDisabled ( ) ) return ;
3137 eventManager . on ( ':load' , ( ) => {
3238 toggleFish ( $ ( 'body' ) ) ;
3339 } ) ;
@@ -44,4 +50,4 @@ if (isApril()) {
4450 eventManager . on ( 'Home:Refresh' , ( ) => {
4551 toggleFish ( $ ( 'table.spectateTable' ) ) ;
4652 } ) ;
47- }
53+ } ) ;
0 commit comments