Skip to content

add uww toggle #6824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2024
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
16 changes: 16 additions & 0 deletions src/components/Layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ export function Footer() {
dir="ltr">
©{new Date().getFullYear()}
</div>
<div
className="uwu-visible text-xs cursor-pointer hover:text-link hover:dark:text-link-dark hover:underline"
onClick={() => {
// @ts-ignore
window.__setUwu(false);
}}>
no uwu plz
</div>
<div
className="uwu-hidden text-xs cursor-pointer hover:text-link hover:dark:text-link-dark hover:underline"
onClick={() => {
// @ts-ignore
window.__setUwu(true);
}}>
uwu?
</div>
<div className="uwu-visible text-xs">
Logo by
<ExternalLink
Expand Down
72 changes: 47 additions & 25 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,59 @@ const MyDocument = () => {
<script
dangerouslySetInnerHTML={{
__html: `
(function () {
try {
var preferredUwu;
(function () {
try {
let logShown = false;
function setUwu(isUwu) {
try {
preferredUwu = localStorage.getItem('uwu');
} catch (err) { }

const isUwuValue = window.location
&& window.location.search
&& window.location.search.match(/uwu=(true|false)/);

if (isUwuValue) {
const isUwu = isUwuValue[1] === 'true';
if (isUwu) {
try {
localStorage.setItem('uwu', true);
} catch (err) { }
localStorage.setItem('uwu', true);
document.documentElement.classList.add('uwu');
console.log('uwu mode enabled. turn off with ?uwu=false')
console.log('logo credit to @sawaratsuki1004 via https://github.com/SAWARATSUKI/ServiceLogos');
if (!logShown) {
console.log('uwu mode! turn off with ?uwu=0');
console.log('logo credit to @sawaratsuki1004 via https://github.com/SAWARATSUKI/ServiceLogos');
logShown = true;
}
} else {
try {
localStorage.removeItem('uwu', false);
} catch (err) { }
localStorage.removeItem('uwu');
document.documentElement.classList.remove('uwu');
console.log('uwu mode off. turn on with ?uwu');
}
} else if (preferredUwu) {
document.documentElement.classList.add('uwu');
} catch (err) { }
}
window.__setUwu = setUwu;
function checkQueryParam() {
const params = new URLSearchParams(window.location.search);
const value = params.get('uwu');
switch(value) {
case '':
case 'true':
case '1':
return true;
case 'false':
case '0':
return false;
default:
return null;
}
} catch (err) { }
})();
`,
}
function checkLocalStorage() {
try {
return localStorage.getItem('uwu') === 'true';
} catch (err) {
return false;
}
}
const uwuQueryParam = checkQueryParam();
console.log('uwuQueryParam', uwuQueryParam);
if (uwuQueryParam != null) {
setUwu(uwuQueryParam);
} else if (checkLocalStorage()) {
document.documentElement.classList.add('uwu');
}
} catch (err) { }
})();
`,
}}
/>
<script
Expand Down
Loading