/
scripts.js
147 lines (126 loc) · 4.96 KB
/
scripts.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
document.addEventListener('DOMContentLoaded', (event) => {
const body = document.body;
const DARK_THEME = 'dark';
const LIGHT_THEME = 'light';
const TYPING_SPEED = 150;
const DELETING_SPEED = 50;
const WAIT_BEFORE_DELETE = 1500;
const WAIT_BEFORE_TYPE = 1500;
const CURSOR_BLINK_SPEED = 500;
function setTheme(theme) {
body.classList.toggle(DARK_THEME, theme === DARK_THEME);
localStorage.setItem('theme', theme);
}
function prefersDarkScheme() {
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
}
setTheme(prefersDarkScheme() ? DARK_THEME : LIGHT_THEME);
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
setTheme(e.matches ? DARK_THEME : LIGHT_THEME);
});
const typedText = document.getElementById("typedText");
const cursor = document.getElementById("cursor");
const words = ["I'm a full stack developer.", "I'm a programmer.", "I'm a sysadmin.", "I founded/manage multiple communities."];
let wordIndex = 0;
function typeLetter() {
const word = words[wordIndex];
let letterIndex = 0; // Reset letterIndex for each word
function typeNextLetter() {
typedText.textContent += word[letterIndex];
letterIndex++;
if (letterIndex === word.length) {
setTimeout(deleteLetter, WAIT_BEFORE_DELETE);
return;
}
setTimeout(typeNextLetter, TYPING_SPEED);
}
typeNextLetter();
}
function deleteLetter() {
const word = words[wordIndex];
let letterIndex = word.length; // Reset letterIndex for each word
function deleteNextLetter() {
typedText.textContent = word.slice(0, letterIndex - 1);
letterIndex--;
if (letterIndex === 0) {
setTimeout(() => {
wordIndex = (wordIndex + 1) % words.length;
typeLetter();
}, WAIT_BEFORE_TYPE);
return;
}
setTimeout(deleteNextLetter, DELETING_SPEED);
}
deleteNextLetter();
}
typeLetter();
setInterval(() => {
cursor.style.opacity = cursor.style.opacity === "0" ? "1" : "0";
}, CURSOR_BLINK_SPEED);
const languageColors = {
'Python': 'blue',
'JavaScript': 'yellow', // Set a color for JavaScript
'HTML': 'green',
'CSS': 'red',
'Java': 'orange',
};
const defaultColors = ['grey', 'silver', 'brown', 'pink', 'magenta'];
const username = 'computertech312';
const apiUrl = `https://api.github.com/users/${username}/repos`;
fetch(apiUrl)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
const languageData = {};
data.forEach((repo) => {
const { language } = repo;
if (language) {
languageData[language] = (languageData[language] || 0) + 1;
}
});
const ctx = document.getElementById('languageChart').getContext('2d');
const backgroundColors = [];
let defaultColorIndex = 0;
Object.keys(languageData).forEach(language => {
if (languageColors[language]) {
backgroundColors.push(languageColors[language]);
} else {
backgroundColors.push(defaultColors[defaultColorIndex]);
defaultColorIndex = (defaultColorIndex + 1) % defaultColors.length;
}
});
const chart = new Chart(ctx, {
type: 'bar', // Changed from 'horizontalBar'
data: {
labels: Object.keys(languageData),
datasets: [
{
label: 'Top Used Languages',
data: Object.values(languageData),
backgroundColor: backgroundColors,
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
indexAxis: 'y', // Added this line
scales: {
x: { // Changed from 'xAxes'
ticks: {
beginAtZero: true
}
}
}
},
});
})
.catch((error) => {
console.error('Error fetching data:', error);
// Add user-friendly error handling here
});
});