Skip to content

Commit

Permalink
add uww toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed May 1, 2024
1 parent 7062b8d commit ddf6fe4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
14 changes: 14 additions & 0 deletions src/components/Layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,20 @@ 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={() => {
window.__setUwu(false);

Check failure on line 291 in src/components/Layout/Footer.tsx

View workflow job for this annotation

GitHub Actions / Lint on node 20.x and ubuntu-latest

Property '__setUwu' does not exist on type 'Window & typeof globalThis'.
}}>
no uwu plz
</div>
<div
className="uwu-hidden text-xs cursor-pointer hover:text-link hover:dark:text-link-dark hover:underline"
onClick={() => {
window.__setUwu(true);

Check failure on line 298 in src/components/Layout/Footer.tsx

View workflow job for this annotation

GitHub Actions / Lint on node 20.x and ubuntu-latest

Property '__setUwu' does not exist on type 'Window & typeof globalThis'.
}}>
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

0 comments on commit ddf6fe4

Please sign in to comment.