Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/[locale]/components/AprilFools/AprilFools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use client'

import { useEffect } from 'react'
import { usePathname } from 'next/navigation'

function replaceInNode(root: Node) {
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT)
let node: Node | null
while ((node = walker.nextNode())) {
if (node.textContent?.includes('WebGAL'))
node.textContent = node.textContent.replace(/WebGAL/g, 'WebG@L')
}
}

const AprilFools = () => {
const pathname = usePathname()

useEffect(() => {
const now = new Date()
if (now.getMonth() !== 3 || now.getDate() !== 1) return

if (document.title.includes('WebGAL'))
document.title = document.title.replace(/WebGAL/g, 'WebG@L')

replaceInNode(document.body)

const observer = new MutationObserver((mutations) => {
mutations.forEach(({ addedNodes }) =>
addedNodes.forEach(node => replaceInNode(node))
)
})
observer.observe(document.body, { childList: true, subtree: true })

return () => observer.disconnect()
}, [pathname])
Comment on lines +18 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The text replacement logic only runs when the component mounts or the pathname changes. This means that any content loaded asynchronously or updated via client-side state changes after the initial render will not be affected by the prank. To ensure all instances of "WebGAL" are replaced, even in dynamically updated content, consider using a MutationObserver to monitor DOM changes.


return null
}

export default AprilFools

2 changes: 2 additions & 0 deletions app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { i18n } from '../../i18n'
import Footer from './components/Footer/Footer'
import Navbar from './components/Navbar/Navbar'
import { GoogleAnalytics } from '@next/third-parties/google'
import AprilFools from './components/AprilFools/AprilFools'

const notoSansSC = Noto_Sans_SC({
subsets: ['latin'],
Expand All @@ -29,6 +30,7 @@ export default async function LangLayout({ children, params: { locale } }
<html lang={locale} className={notoSansSC.className}>
<body>
<NextIntlClientProvider locale={locale} messages={locales}>
<AprilFools />
<Navbar />
{children}
<Footer />
Expand Down
24 changes: 0 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading