-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.js
More file actions
205 lines (191 loc) · 7.83 KB
/
git.js
File metadata and controls
205 lines (191 loc) · 7.83 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
let githubToken = 'dsds'
let githubUsername = 'PawanSirsat'
let squares = document.querySelector('.squares')
const months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
]
// Fetch the contribution data for the user PawanSirsat
document.addEventListener('DOMContentLoaded', function () {
const fetchButton = document.getElementById('fetch-button')
const usernameInput = document.getElementById('username')
const userInfoDiv = document.getElementById('user-info')
async function getUserData(username) {
const response2 = await fetch('contributions.json')
if (!response2.ok) {
throw new Error('Failed to fetch JSON data')
}
const data1 = await response2.json()
console.log(data1)
const countributions = data1.years
if (username) {
fetch(`https://api.github.com/users/${username}`)
.then((response) => response.json())
.then((data) => {
datesegments = data.created_at.split('T').shift().split('-')
console.log(data)
userInfoDiv.innerHTML = ` <div class="profile-header">
<img id="avatar" src="${data.avatar_url}" alt="">
<div class="profile-info-wrapper">
<div class="profile-name">
<h2 id="name">${data.name}</h2>
<a href="${
data.html_url
}" target="_blank" rel="noopener noreferrer" id="user">@${
data.login
}</a>
</div>
<p id="date">Joined ${datesegments[2]} ${
months[datesegments[1] - 1]
} ${datesegments[0]}</p>
</div>
</div>
<p id="bio">${data.bio}</p>
<div class="profile-stats-wrapper">
<div class="profile-stat">
<p class="stat-title">Repos</p>
<p id="repos" class="stat-value">${
data.public_repos
}</p>
</div>
<div class="profile-stat">
<p class="stat-title">${data1.years[0].year}</p>
<p id="repos" class="stat-value">${
data1.years[0].total
}</p>
</div>
<div class="profile-stat">
<p class="stat-title">Followers</p>
<p id="followers" class="stat-value">${
data.followers
}</p>
</div>
<div class="profile-stat">
<p class="stat-title">Following</p>
<p id="following" class="stat-value">${
data.following
}</p>
</div>
</div>
<div class="profile-bottom-wrapper">
<div class="profile-info">
<div class="bottom-icons" style="opacity: 0.5;"><img width="20" height="20" src="https://img.icons8.com/ios-filled/50/FFFFFF/marker.png" alt="marker"/></div>
<p id="location" style="opacity: 0.5;">${
data.location
}</p>
</div>
<div class="profile-info">
<div class="bottom-icons" style="opacity: 0.5;"><img width="20" height="20" src="https://img.icons8.com/ios-filled/50/FFFFFF/link--v1.png" alt="link--v1"/></div>
<a href="${
data.blog
}" id="page" style="opacity: 0.5;">${
data.blog
}</a>
</div>
<div class="profile-info">
<div class="bottom-icons"><img width="20" height="20" src="https://img.icons8.com/ios-filled/50/FFFFFF/twitter.png" alt="twitter"/></div>
<a href="https://twitter.com/${
data.twitter_username
}" id="twitter">${data.twitter_username}</a>
</div>
<div class="profile-info">
<div class="bottom-icons" style="opacity: 0.5;"><img width="20" height="20" src="https://img.icons8.com/pastel-glyph/64/FFFFFF/company--v1.png" alt="company--v1"/></div>
<p id="company" style="opacity: 0.5;">${
data.company
}</p>
</div>
</div>
`
})
.catch((error) => {
userInfoDiv.innerHTML = `<p>Error: User not found</p>`
})
}
}
fetchButton.addEventListener('click', function () {
const username = usernameInput.value
squares.innerHTML = ''
githubUsername = username
getGitHubContributions()
getUserData(username)
})
// Automatically load data for a default GitHub user when the page loads
const defaultUsername = 'PawanSirsat'
getUserData(defaultUsername)
})
let query = `
query($userName: String!) {
user(login: $userName) {
contributionsCollection {
contributionCalendar {
totalContributions
weeks {
contributionDays {
contributionCount
date
}
}
}
}
}
}
`
async function getGitHubContributions() {
try {
const response = await fetch('contributions.json') // Assuming the JSON file is in the same directory
if (!response.ok) {
throw new Error('Failed to fetch JSON data')
}
const data = await response.json()
const contributions = data.contributions.reverse() // Reverse the order of contributions
contributions.forEach((contribution) => {
const date = new Date(contribution.date)
const day = date.getDate()
const contributionCount = contribution.count
const square = document.createElement('li')
square.dataset.level = contributionCount
square.style.backgroundColor = contribution.color
squares.appendChild(square)
})
} catch (error) {
console.error('Error loading JSON data:', error)
}
}
getGitHubContributions()
// JavaScript code to scroll the container to the right on page load
window.addEventListener('load', function () {
const container = document.querySelector('.graph.ContributionCalendar-label')
if (container) {
const currentDate = new Date()
const currentMonth = currentDate.getMonth() + 1 // Adding 1 because getMonth() returns a zero-based index
// Define the scroll percentage for each month
const scrollPositions = {
1: 0, // January
2: 0, // February
3: 0, // March
4: 0, // April
5: 0, // May
6: 30, // June
7: 30, // July
8: 40, // August
9: 40, // September
10: 40, // October
11: 45, // November
12: 100, // December
}
const scrollPercentage = scrollPositions[currentMonth]
if (scrollPercentage !== undefined) {
// Scroll to the specified percentage of the container's width
container.scrollLeft = (container.scrollWidth * scrollPercentage) / 100
}
}
})