Skip to content

Commit 3d5f7ef

Browse files
committed
fix: update april fools setting
1 parent bbef73c commit 3d5f7ef

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

src/base/vanilla/aprilFools.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
11
import eventManager from '../../utils/eventManager.js';
22
import * as settings from '../../utils/settings/index.js';
3-
import { global, globalSet } from '../../utils/global.js';
3+
import { isApril, IMAGES } from '../../utils/isApril.js';
44

5-
const setting = settings.register({
5+
const aprilFools = settings.register({
66
name: 'Disable April Fools Jokes',
77
key: 'underscript.disable.fishday',
88
note: 'Disables *almost* everything.',
9-
hidden: () => global('fish', { throws: false }) === undefined,
10-
refresh: true,
9+
hidden: () => !isApril(),
10+
onChange() {
11+
toggleFish($('body'));
12+
},
1113
});
12-
if (setting.value()) {
13-
eventManager.on(':preload', () => globalSet('fish', false, { throws: false }));
14+
15+
const basePath = 'images';
16+
17+
function toggleFish($el) {
18+
const disabled = aprilFools.value();
19+
const search = disabled ? IMAGES : basePath;
20+
const replace = disabled ? [IMAGES, basePath] : [basePath, IMAGES];
21+
22+
$el.find(`img[src*="/${search}/"],img[src^="${search}/"]`).each((index, img) => {
23+
img.src = img.src.replace(...replace);
24+
});
25+
$el.find(`[style*="url(\\"${search}/"]`).each((i, img) => {
26+
img.style.background = img.style.background.replace(...replace);
27+
});
28+
}
29+
30+
if (isApril()) {
31+
eventManager.on(':load', () => {
32+
toggleFish($('body'));
33+
});
34+
eventManager.on('func:appendCard', (card, container) => {
35+
toggleFish(container);
36+
});
37+
eventManager.on('Chat:getMessage', ({ chatMessage }) => {
38+
const { id } = JSON.parse(chatMessage);
39+
toggleFish($(`#message-${id}`));
40+
});
41+
eventManager.on('Chat:getHistory', ({ room }) => {
42+
toggleFish($(`#${room}`));
43+
});
1444
}

0 commit comments

Comments
 (0)