Repository navigation
Expand file tree
/
Copy pathaaaahhhh.ts
More file actions
122 lines (104 loc) · 3.62 KB
/
Copy pathaaaahhhh.ts
File metadata and controls
122 lines (104 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/** Public path of the image every other image is swapped for by the easter egg. */
export const aaaahhhhImage = '/images/aaaahhhh/aaaahhhh.webp';
/** Replaces all images and background images on the page with the AAAAHHHH image. */
export function imageAAAAHHHH(): void {
const docs = document.querySelectorAll<HTMLElement>('div[style]');
for (const doc of docs) {
if (doc.style.backgroundImage) {
doc.style.backgroundImage = `url(${aaaahhhhImage})`;
}
}
const imgs = document.getElementsByTagName('img');
for (const img of imgs) {
if (img.src) {
img.src = aaaahhhhImage;
}
if (img.srcset) {
img.srcset = aaaahhhhImage;
}
}
// The starry background paints via CSS rather than an <img>, so it needs handling separately.
const skyElement = document.getElementById('sky');
if (skyElement) {
skyElement.style.backgroundImage = `url(${aaaahhhhImage})`;
skyElement.style.backgroundRepeat = 'no-repeat';
skyElement.style.backgroundSize = 'cover';
}
}
/**
* Converts string characters to A or H based on position.
* First half of characters become 'A', second half become 'H'.
* Preserves spaces and capitalization.
* @param aaaaahhhh - The input string to transform
* @returns Transformed string with A/H characters
*/
export function convertAAAAHH(aaaaahhhh: string): string {
let newAAAAHHHH = '';
const AAAAHHHHlength: number = aaaaahhhh.length;
const splitAAAAHHHH = aaaaahhhh.split('');
for (let i = 0; i < AAAAHHHHlength; i += 1) {
if (splitAAAAHHHH[i] === ' ') {
newAAAAHHHH += ' ';
} else {
const toUpper = splitAAAAHHHH[i].toUpperCase();
const isUpper = toUpper === splitAAAAHHHH[i];
let whichLetter: string = i < AAAAHHHHlength / 2 ? 'a' : 'h';
whichLetter = isUpper ? whichLetter.toUpperCase() : whichLetter;
newAAAAHHHH += whichLetter;
}
}
if (!newAAAAHHHH || newAAAAHHHH.length === 0) {
newAAAAHHHH = aaaaahhhh;
}
return newAAAAHHHH;
}
/**
* Transforms all text elements on the page to AAAAHHHH format.
*
* Rewrites only the direct `#text` children of each element, so nested markup is reached through
* its own entry in the tag list rather than through its parent. Also removes `#description-Carousel`
* and unhides `#no-motion-description`, each behind a presence check, so a page without them is
* transformed the same way.
*/
export function textAAAAHHHH(): void {
const docs = [
...document.getElementsByTagName('span'),
...document.getElementsByTagName('p'),
...document.getElementsByTagName('h1'),
...document.getElementsByTagName('h2'),
...document.getElementsByTagName('h3'),
...document.getElementsByTagName('button'),
];
for (let i = 0; i < docs.length; i += 1) {
if (docs[i]?.childNodes) {
for (let c = 0; c < docs[i].childNodes.length; c += 1) {
if (docs[i].childNodes[c].nodeName === '#text') {
const text = docs[i].childNodes[c].textContent;
if (text) {
const newText = convertAAAAHH(text);
docs[i].childNodes[c].textContent = newText;
}
}
}
}
}
const carouselElement = document.getElementById('description-Carousel');
if (carouselElement) {
carouselElement.remove();
}
const noMotionDescriptionElement = document.getElementById('no-motion-description');
if (noMotionDescriptionElement) {
noMotionDescriptionElement.removeAttribute('hidden');
}
}
/**
* Transforms entire page into AAAAHHHH format by calling image and text transformations.
*
* Mutates the live document and cannot be undone short of a reload, and touches `document` directly,
* so it runs only on the client.
*/
export function aaaahhhh(): void {
imageAAAAHHHH();
textAAAAHHHH();
document.title = "Alexander Sullivan's AAAAHHHHH";
}