Skip to content

Commit 4201491

Browse files
committed
fix: disable april fools setting automatically
1 parent 17e234e commit 4201491

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/base/vanilla/aprilFools.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,38 @@ import eventManager from '../../utils/eventManager.js';
22
import * as settings from '../../utils/settings/index.js';
33
import { isApril, IMAGES } from '../../utils/isApril.js';
44

5+
const year = `${new Date().getFullYear()}`;
56
const 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

1520
const basePath = 'images';
1621

1722
function 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+
});

src/utils/season.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ eventManager.on('translation:loaded', () => {
2222

2323
season = Number(seasonKey.substring(startsWith.length, seasonKey.indexOf('-', startsWith.length)));
2424
sessionStorage.setItem('undercards.season', season);
25+
eventManager.singleton.emit('undercards:season', season);
2526
});

src/utils/settings/types/boolean.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export default class extends Setting {
55
super(name);
66
}
77

8-
value(val) {
8+
value(val, { extraValue } = {}) {
99
if (typeof val === 'boolean') return val;
10-
return ['1', 'true', 1].includes(val);
10+
return ['1', 'true', 1, `${extraValue}`].includes(val);
1111
}
1212

1313
element(value, update, {

0 commit comments

Comments
 (0)