-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
147 lines (121 loc) · 3.73 KB
/
script.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
function meowLog(...input) {
console.log('=^..^= < Meow!\n' + input.map(item => typeof item === 'object' ? JSON.stringify(item, null, 2) : item).join('\n'));
}
const now = new Date();
meowLog('Now loading...');
meowLog('Please wait...')
const body = document.body;
async function fetchJson(path) {
meowLog(`Try to fetch ${path}.`);
const response = await fetch(path);
if (!response.ok) return console.error(`Failed to fetch ${path}.`);
const rawData = await response.text();
const data = JSON.parse(rawData);
meowLog(`Successfully fetched ${path}.`, data);
return data;
};
async function fetchText(path) {
meowLog(`Try to fetch ${path}.`);
const response = await fetch(path);
if (!response.ok) return console.error(`Failed to fetch ${path}.`);
const rawData = await response.text();
let data = rawData;
if (data.endsWith('\n')) data = data.slice(0, -1);
data = data.replace(/\n/g, '<br>');
meowLog(`Successfully fetched ${path}.`, data);
return data;
};
const fakeLink = document.getElementById("ca-fake");
if (fakeLink) {
fakeLink.remove();
meowLog('Successfully removed!')
}
const bio = document.getElementById('bio');
if (bio) {
(async () => {
const text = await fetchText('/bio.txt');
if (text) {
bio.textContent = null;
bio.innerHTML = text;
}
})();
}
(async () => {
const author = document.createElement('div');
author.className = 'author';
const home = document.createElement('a');
home.className = 'home';
home.href = '/';
const logo = document.createElement('img');
logo.src = '/img/logo.png';
logo.alt = 'Home';
logo.title = 'Home';
home.appendChild(logo);
author.appendChild(home);
const list = document.createElement('div');
list.className = 'list';
list.textContent = 'Extra Links:';
author.appendChild(list);
try {
const links = await fetchJson('/author-links.json');
for (const link of links) {
const a = document.createElement('a');
if (link.class) a.className = link.class;
a.href = link.url;
a.textContent = link.title;
a.target = '_blank';
list.appendChild(a);
}
body.appendChild(author);
} catch (e) {
console.error(e);
}
})();
const list = document.getElementById('links-list');
if (list) {
(async () => {
try {
const links = await fetchJson('/links.json');
for (const link of links) {
const li = document.createElement('li');
const a = document.createElement('a');
a.href = link.url;
a.textContent = link.title;
a.target = '_blank';
li.appendChild(a);
list.appendChild(li);
}
} catch (e) {
console.error(e);
}
})();
}
const footer = document.createElement('footer');
footer.innerHTML = `<p>© 2022 - ${new Date().getFullYear()} otoneko. All rights reserved.</p>`;
body.appendChild(footer);
document.addEventListener("DOMContentLoaded", async function () {
const typedOutputs = document.querySelectorAll('.typing');
for (const typedOutput of typedOutputs) {
const textToType = typedOutput.getAttribute('content');
const cooldown = Math.min(300, 5 * 1000 / textToType.length);
meowLog(`Cooldown for typing "${textToType}":\n${cooldown} ms`);
let index = 0;
let cursorInterval;
async function typeText() {
if (index < textToType.length) {
if (textToType.charAt(index) === ';') {
typedOutput.innerHTML += '<br>';
} else {
typedOutput.innerHTML += textToType.charAt(index);
}
index++;
setTimeout(typeText, cooldown);
} else {
clearInterval(cursorInterval);
typedOutput.classList.add('no-cursor');
}
}
await typeText();
}
});
meowLog(`Successfully loaded! Total time: ${new Date() - now}`);