Skip to content

Commit 0af6d02

Browse files
authored
Merge pull request #67 from nini22P/main
feat: add a feature that only works on March 32nd
2 parents 6727cdc + e7db943 commit 0af6d02

3 files changed

Lines changed: 43 additions & 24 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
import { usePathname } from 'next/navigation'
5+
6+
function replaceInNode(root: Node) {
7+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT)
8+
let node: Node | null
9+
while ((node = walker.nextNode())) {
10+
if (node.textContent?.includes('WebGAL'))
11+
node.textContent = node.textContent.replace(/WebGAL/g, 'WebG@L')
12+
}
13+
}
14+
15+
const AprilFools = () => {
16+
const pathname = usePathname()
17+
18+
useEffect(() => {
19+
const now = new Date()
20+
if (now.getMonth() !== 3 || now.getDate() !== 1) return
21+
22+
if (document.title.includes('WebGAL'))
23+
document.title = document.title.replace(/WebGAL/g, 'WebG@L')
24+
25+
replaceInNode(document.body)
26+
27+
const observer = new MutationObserver((mutations) => {
28+
mutations.forEach(({ addedNodes }) =>
29+
addedNodes.forEach(node => replaceInNode(node))
30+
)
31+
})
32+
observer.observe(document.body, { childList: true, subtree: true })
33+
34+
return () => observer.disconnect()
35+
}, [pathname])
36+
37+
return null
38+
}
39+
40+
export default AprilFools
41+

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)