-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
138 lines (116 loc) · 5.61 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
document.addEventListener('DOMContentLoaded', (event) => {
fetchGitHubContributions('ciracinicolo');
startEmojiSlideshow();
const sidebar = document.getElementById('sidebar');
const rightSidebar = document.getElementById('right-sidebar');
const toggleSidebar = document.getElementById('toggle-sidebar');
const toggleRightSidebar = document.getElementById('toggle-right-sidebar');
toggleSidebar.addEventListener('click', () => {
updateSidebarPosition();
sidebar.classList.toggle('show');
});
toggleRightSidebar.addEventListener('click', () => {
updateSidebarPosition();
rightSidebar.classList.toggle('show');
});
window.addEventListener('scroll', updateSidebarPosition);
window.addEventListener('resize', updateSidebarPosition);
const statusBar = document.getElementById('status-bar');
const emojiElement = document.getElementById('emoji');
const handleCommand = createCommandHandler();
let typedText = '';
document.addEventListener('keydown', (event) => {
const key = event.key;
event.preventDefault();
if (key === 'Backspace') {
typedText = typedText.slice(0, -1);
} else if (key === 'Enter') {
handleCommand(typedText);
typedText = '';
} else if (key.length === 1) {
typedText += key;
}
statusBar.innerText = `${emojiElement.innerText} ${typedText}`;
});
});
function isMobile() {
return window.innerWidth <= 768;
}
function updateSidebarPosition() {
if (isMobile()) {
const scrollTop = window.scrollY;
sidebar.style.top = `${scrollTop + 100}px`;
rightSidebar.style.top = `${scrollTop + 100}px`;
}
}
function createCommandHandler() {
return function(command) {
if (command === ':q!') {
window.location.replace("https://github.com/ciracinicolo/ciracinicolo.github.io");
}
};
}
function fetchGitHubContributions(username) {
const apiUrl = `https://api.github.com/users/${username}/repos`;
const prApiUrl = `https://api.github.com/search/issues?q=author%3A${username}`;
const excluded = ["PR_kwDOKzhRRM5x_XAl", "PR_kwDOC6bl6c5rEl9A", "PR_kwDOC6bl6c5oBThX"]
// Fetch all repositories
fetch(apiUrl)
.then(response => response.json())
.then(repos => {
let summary = '';
const forkedRepos = repos.filter(repo => !repo.archived && repo.fork);
const personalRepos = repos.filter(repo => !repo.archived && !repo.fork);
// Process personal repositories
personalRepos.forEach(repo => {
const repoName = repo.name;
const repoUrl = repo.html_url;
const repoDescription = repo.description || 'No description';
summary += `<div class="project-personal"><p><strong><a href="${repoUrl}" target="_blank">${repoName}</a></strong> - ${repoDescription} <em>(Personal Project)</em></p></div>`;
});
fetch(prApiUrl)
.then(response => response.json())
.then(data => {
const prs = data.items.filter(issue => issue.node_id.startsWith('PR') && !excluded.includes(issue.node_id));
// Process forked repositories
let promises = forkedRepos.map(repo => {
return fetch(repo.url)
.then(response => response.json())
.then(repoData => {
const parentUrl = repoData.parent ? repoData.parent.url : '';
const repoName = repo.name;
const repoUrl = repo.html_url;
const repoDescription = repo.description || 'No description';
const repoOwner = repo.owner.login;
const projectType = 'Contribution';
const repoPrs = prs.filter(pr => pr.repository_url === parentUrl);
if (repoPrs.length > 0) {
summary += `<div class="project-contribution"><p><strong><a href="${repoUrl}" target="_blank">${repoName}</a></strong> - ${repoDescription} <em>(${projectType})</em>`;
summary += ' - Pull Requests: <ul>';
repoPrs.forEach(pr => {
const prNumber = pr.number;
summary += `<li><a href="${pr.html_url}" target="_blank">#${prNumber} - ${pr.title}</a></li>`;
});
summary += '</ul>';
summary += `</p></div>`;
}
})
.catch(error => console.error('Error fetching parent repo:', error));
});
Promise.all(promises).then(() => {
document.getElementById('github-summary').innerHTML = summary;
});
})
.catch(error => console.error('Error fetching PRs:', error));
})
.catch(error => console.error('Error fetching GitHub repos:', error));
}
function startEmojiSlideshow() {
const emojis = ['😺', '😸', '😹', '😻', '😼', '😽', '🙀', '😿', '😾'];
let index = 0;
const emojiElement = document.getElementById('emoji');
setInterval(() => {
emojiElement.textContent = emojis[index];
index = (index + 1) % emojis.length;
}, 500);
}