Skip to content

Commit a309aba

Browse files
committed
feat: add a feature that only works on March 32nd
1 parent 6727cdc commit a309aba

3 files changed

Lines changed: 32 additions & 24 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
import { usePathname } from 'next/navigation'
5+
6+
const AprilFools = () => {
7+
const pathname = usePathname()
8+
9+
useEffect(() => {
10+
const now = new Date()
11+
if (now.getMonth() !== 3 || now.getDate() !== 1) return
12+
13+
if (document.title.includes('WebGAL'))
14+
document.title = document.title.replace(/WebGAL/g, 'WebG@L')
15+
16+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT)
17+
const textNodes: Text[] = []
18+
let node: Node | null
19+
while ((node = walker.nextNode())) textNodes.push(node as Text)
20+
textNodes.forEach(node => {
21+
if (node.textContent?.includes('WebGAL'))
22+
node.textContent = node.textContent.replace(/WebGAL/g, 'WebG@L')
23+
})
24+
}, [pathname])
25+
26+
return null
27+
}
28+
29+
export default AprilFools
30+

app/[locale]/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { i18n } from '../../i18n'
55
import Footer from './components/Footer/Footer'
66
import Navbar from './components/Navbar/Navbar'
77
import { GoogleAnalytics } from '@next/third-parties/google'
8+
import AprilFools from './components/AprilFools/AprilFools'
89

910
const notoSansSC = Noto_Sans_SC({
1011
subsets: ['latin'],
@@ -29,6 +30,7 @@ export default async function LangLayout({ children, params: { locale } }
2930
<html lang={locale} className={notoSansSC.className}>
3031
<body>
3132
<NextIntlClientProvider locale={locale} messages={locales}>
33+
<AprilFools />
3234
<Navbar />
3335
{children}
3436
<Footer />

package-lock.json

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)