-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.html
150 lines (129 loc) · 4.89 KB
/
user.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CODES20 - GISTS</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="icon" href="logo.png"/>
<style>
body {
background-color: #000;
color: #fff;
}
.card {
background-color: #111;
color: #fff;
border: none;
border-radius: 8px;
margin: 10px;
}
.card-title {
color: #17a2b8;
}
.card-text {
color: #ccc;
}
.btn-primary {
background-color: #17a2b8;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Codes20</a>
<a class="my-4" id="username">---SH20RAJ---</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="../">Code</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Terms & Conditions</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row" id="gistList"></div>
</div>
<script>
// username = 'sh20raj'; // Replace with the GitHub username
let username;
let refreshUsername = () => {
if(localStorage.username){
username = localStorage.username;
} else {
localStorage.username = prompt("Enter Your GitHub Username :- \n ", "ForGettingGists i.e. SH20RAJ");
username = localStorage.username ;
}
document.getElementById('username').innerHTML = "---"+username+"---";
}
refreshUsername();
const apiUrl = `https://api.github.com/users/${username}/gists`;
function fetchGistsWithCodes20() {
fetch(apiUrl)
.then(response => response.json())
.then(gists => {
const filteredGists = gists.filter(gist => {
return Object.keys(gist.files).some(fileName => fileName == 'codes20.md');
});
displayGists(filteredGists);
})
.catch(error => {
console.error('An error occurred:', error);
});
}
function displayGists(gists) {
const gistList = document.getElementById('gistList');
gists.forEach(gist => {
const description = gist.description || 'No description';
const date = calculateRelativeTime(gist.updated_at);
const username = gist.owner.login;
const postHTML = `
<div class="col-md-4">
<div class="card mb-3">
<div class="card-body">
<h5 class="card-title">${description}</h5>
<p class="card-text">Updated ${date}</p>
<p class="card-text">GitHub Username: ${username}</p>
<a href="https://codes20.github.io./${gist.id}" class="btn btn-primary">Open Code .</a>
<a target="_" href="https://gist.github.com/${gist.id}" class="btn btn-success">Open GIST</a>
</div>
</div>
</div>
`;
gistList.innerHTML += postHTML;
});
}
function calculateRelativeTime(dateString) {
const date = new Date(dateString);
const now = new Date();
const diff = now - date;
const seconds = Math.floor(diff / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
if (days > 1) {
return `${days} days ago`;
} else if (hours > 1) {
return `${hours} hours ago`;
} else if (minutes > 1) {
return `${minutes} minutes ago`;
} else {
return `${seconds} seconds ago`;
}
}
fetchGistsWithCodes20();
</script>
</body>
</html>