|
1 | 1 | import eventManager from '../../utils/eventManager.js'; |
2 | 2 | import * as settings from '../../utils/settings/index.js'; |
3 | | -import { global, globalSet } from '../../utils/global.js'; |
| 3 | +import { isApril, IMAGES } from '../../utils/isApril.js'; |
4 | 4 |
|
5 | | -const setting = settings.register({ |
| 5 | +const aprilFools = settings.register({ |
6 | 6 | name: 'Disable April Fools Jokes', |
7 | 7 | key: 'underscript.disable.fishday', |
8 | 8 | note: 'Disables *almost* everything.', |
9 | | - hidden: () => global('fish', { throws: false }) === undefined, |
10 | | - refresh: true, |
| 9 | + hidden: () => !isApril(), |
| 10 | + onChange() { |
| 11 | + toggleFish($('body')); |
| 12 | + }, |
11 | 13 | }); |
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 | + }); |
14 | 44 | } |
0 commit comments