-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
173 lines (153 loc) · 5.71 KB
/
script.js
File metadata and controls
173 lines (153 loc) · 5.71 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
window.addEventListener('scroll', function() {
const navbarName = document.getElementById('navbar-name');
if (window.scrollY > 100) {
navbarName.classList.remove('opacity-0');
navbarName.classList.add('opacity-100');
} else {
navbarName.classList.remove('opacity-100');
navbarName.classList.add('opacity-0');
}
});
setTimeout(function() {
const profilePic = document.getElementById('profile-pic');
if (profilePic) {
profilePic.src = 'sus.jpeg';
}
}, 180000);
function show(id) {
var element = document.getElementById(id);
if (element && element.style) {
if (element.style.display === "none") {
element.style.display = "block";
} else {
element.style.display = "none";
}
}
}
async function fetchLastCommitDate() {
const owner = 'Arielogg';
const repo = 'Arielogg.github.io';
const url = `https://api.github.com/repos/${owner}/${repo}/commits`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`GitHub API error: ${response.status}`);
}
const commits = await response.json();
if (commits && commits.length > 0) {
const lastCommitDateStr = commits[0].commit.committer.date;
const lastCommitDate = new Date(lastCommitDateStr);
const options = { year: 'numeric', month: 'long', day: 'numeric' };
const formattedDate = lastCommitDate.toLocaleDateString('en-US', options);
const lastUpdatedElement = document.getElementById('lastUpdated');
if (lastUpdatedElement) {
lastUpdatedElement.textContent = 'Last updated: ' + formattedDate;
}
} else {
const lastUpdatedElement = document.getElementById('lastUpdated');
if (lastUpdatedElement) {
lastUpdatedElement.textContent = 'Last updated: N/A';
}
}
} catch (error) {
console.error('Failed to fetch last commit date:', error);
const lastUpdatedElement = document.getElementById('lastUpdated');
if (lastUpdatedElement) {
lastUpdatedElement.textContent = 'Last updated: Error fetching date';
}
}
}
// Theme management
let themeToggleCount = 0;
function initTheme() {
const savedTheme = localStorage.getItem('theme');
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedTheme === 'dark' || (!savedTheme && systemPrefersDark)) {
document.documentElement.classList.add('dark');
updateThemeIcon('dark');
} else {
document.documentElement.classList.remove('dark');
updateThemeIcon('light');
}
}
function updateThemeIcon(theme) {
const themeIcon = document.getElementById('theme-icon');
if (!themeIcon) return;
if (theme === 'stetienne') {
themeIcon.className = 'fas fa-futbol';
} else if (theme === 'dark') {
themeIcon.className = 'fas fa-sun';
} else {
themeIcon.className = 'fas fa-moon';
}
}
function toggleTheme() {
const isStetienne = document.documentElement.classList.contains('stetienne');
const mainName = document.getElementById('main-name');
if (isStetienne) {
document.documentElement.classList.remove('stetienne');
localStorage.setItem('theme', 'light');
updateThemeIcon('light');
if (mainName) mainName.innerHTML = "Hey, I'm Ariel<br>Guerra-Adames";
themeToggleCount = 0;
return;
}
themeToggleCount++;
if (themeToggleCount === 3) {
document.documentElement.classList.remove('dark');
document.documentElement.classList.add('stetienne');
localStorage.removeItem('theme');
updateThemeIcon('stetienne');
if (mainName) mainName.innerHTML = "Hey, Je suis vert et fier™";
themeToggleCount = 0;
return;
}
const isDark = document.documentElement.classList.contains('dark');
if (isDark) {
document.documentElement.classList.remove('dark');
localStorage.setItem('theme', 'light');
updateThemeIcon('light');
} else {
document.documentElement.classList.add('dark');
localStorage.setItem('theme', 'dark');
updateThemeIcon('dark');
}
}
// Initialize theme on page load
document.addEventListener('DOMContentLoaded', function() {
initTheme();
// Add theme toggle event listener
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', toggleTheme);
}
// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function(e) {
if (!localStorage.getItem('theme')) {
if (e.matches) {
document.documentElement.classList.add('dark');
updateThemeIcon(true);
} else {
document.documentElement.classList.remove('dark');
updateThemeIcon(false);
}
}
});
fetchLastCommitDate();
// Fish song on click
const fish = document.getElementById('spinning-fish');
const fishAudio = document.getElementById('fish-audio');
if (fish && fishAudio) {
fish.addEventListener('click', function() {
console.log('Fish clicked! Audio paused:', fishAudio.paused);
if (fishAudio.paused) {
fishAudio.play()
.then(() => console.log('Audio playing'))
.catch(error => console.error('Audio play error:', error));
} else {
fishAudio.pause();
console.log('Audio paused');
}
});
}
});