-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
211 lines (197 loc) · 6.99 KB
/
index.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
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
206
207
208
209
210
211
// jshint esversion: 6
// Initab logo animation
$(".initab-logo").hover(function() {
$(".initab-logo").attr("src", "images/initab_logo_hover.svg");
}, function() {
$(".initab-logo").attr("src", "images/initab_logo.svg");
});
// JSON parser
function parseJSON(file, callback) {
const f = new XMLHttpRequest();
f.open("GET", file, true);
f.onreadystatechange = function () {
if(f.readyState === 4) {
if(f.status === 200 || f.status == 0) {
callback(JSON.parse(f.responseText));
}
}
};
f.send(null);
}
// Update Reddit News Feed
function updateRedditFeeds(json) {
let feeds = json.feeds;
feeds.forEach(function(feed) {
const title = feed.title;
const author = feed.postBy;
const score = feed.score;
const link = feed.link;
const comment = feed.comment;
const html = "<div class=\"reddit-feed content-font\"><a class=\"feed-link\" href=\"" +
link + "\"><p class=\"feed-title\">" +
title +
"</p><p><span class=\"posted-by\">Posted by: </span>" +
"<span class=\"feed-author\">" +
author +
"</span></p><p class=\"feed-score\">Reddit Score: " +
score +
"</p>" +
(comment.length == 0?
"</a></div>":
"</a><a class=\"feed-comments\" href=\"" + comment +"\">Link to Comments</a></div>");
$(".left").append(html);
});
}
parseJSON("JSON/reddit_feed.json", updateRedditFeeds);
// Update Javascript History
function updateJSHistory(json) {
let histories = json.history;
histories.forEach(function(history) {
const link = history.link;
const favicon = history.favicon;
const title = history.title;
const time = history.time;
const html = "<div class=\"js-history content-font\"><a class=\"history-link\" href=\"" +
link +
"\"><img class=\"history-favicon\" src=\"" +
favicon +
"\">" +
title +
"</a><p class=\"history-time\">" +
time +
"</p></div>";
$(".javascript-history").append(html);
});
}
parseJSON("JSON/js_history.json", updateJSHistory);
// Update Date-Time
function updateDateTime() {
const now = new Date();
$(".hour").text(now.getHours()>12?
now.getHours()-12 :
(now.getHours() === 0? 12: now.getHours()));
$(".minute").text(String(now.getMinutes()).length === 1?
"0"+now.getMinutes() :
now.getMinutes());
$(".am-pm").text(now.getHours()<12? "AM" : "PM");
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
$(".month").text(months[now.getMonth()]);
$(".day").text(now.getDate());
$(".year").text(now.getYear()+1900);
setTimeout(updateDateTime, 500);
}
updateDateTime();
// Reposition Date-Time
$(window).resize(repositionDateTime);
repositionDateTime();
function repositionDateTime() {
let newBottom = 100*$(window).height()/370-154;
newBottom = newBottom>100? 100:newBottom;
$(".date-time").css("bottom", newBottom+"px");
}
// Custom Links Hint
$(".hide-hint").click(function() {
$(".hint").addClass("hidden");
});
// Switch Github-Gitlab
let isGithub = true;
let isGithubIssues = true;
let isGitlabIssues = true;
$(".switch-git").click(function() {
isGithub = !isGithub;
if(isGithub) {
$(".git-history>.description").html("<i class=\"fab fa-github-alt\"></i>GITHUB ISSUES HISTORY");
$(".switch-git").text("switch to gitlab");
$(".pull-merge").html("<p>PULL REQUESTS</p><i class=\"pull-merge-caret pull-merge-caret-github hidden-caret fas fa-caret-up\">");
trackCaret(isGithubIssues);
} else {
$(".git-history>.description").html("<i class=\"fab fa-gitlab\"></i>GITLAB ISSUES HISTORY");
$(".switch-git").text("switch to github");
$(".pull-merge").html("<p>MERGE REQUESTS</p><i class=\"pull-merge-caret pull-merge-caret-github hidden-caret fas fa-caret-up\">");
trackCaret(isGitlabIssues);
}
});
function trackCaret(isGitIssues) {
if(isGitIssues) {
$(".issues-caret").removeClass("hidden-caret");
$(".pull-merge-caret").addClass("hidden-caret");
if(isGithub) {
parseJSON("JSON/github_issues.json", updateIssues);
} else {
parseJSON("JSON/gitlab_issues.json", updateIssues);
}
} else {
$(".issues-caret").addClass("hidden-caret");
$(".pull-merge-caret").removeClass("hidden-caret");
if(isGithub) {
parseJSON("JSON/github_pull_requests.json", updatePullMergeRequests);
} else {
parseJSON("JSON/gitlab_merge_requests.json", updatePullMergeRequests);
}
}
}
// Switch Issues - Pull-Merge-Requests
$(".issues").click(function() {
if(isGithub) {
isGithubIssues = true;
parseJSON("JSON/github_issues.json", updateIssues);
} else {
isGitlabIssues = true;
parseJSON("JSON/gitlab_issues.json", updateIssues);
}
$(".issues-caret").removeClass("hidden-caret");
$(".pull-merge-caret").addClass("hidden-caret");
});
$(".pull-merge").click(function() {
if(isGithub) {
isGithubIssues = false;
parseJSON("JSON/github_pull_requests.json", updatePullMergeRequests);
} else {
isGitlabIssues = false;
parseJSON("JSON/gitlab_merge_requests.json", updatePullMergeRequests);
}
$(".issues-caret").addClass("hidden-caret");
$(".pull-merge-caret").removeClass("hidden-caret");
});
// Initialize Git Issues
function updateIssues(json) {
$("div").remove(".git-entry");
let issues = json.issues;
issues.forEach(function(issue) {
const link = issue.link;
const repo = issue.repo;
const number = issue.number;
const title = issue.title;
const html = "<div class=\"git-entry content-font\"><a class=\"github-issue-link\" href=\"" +
link + "\"><p class=\"issue-repo\">Repo: " +
repo +
"</p><p class=\"issue-number\">Issue #" +
number +
"</p><p class=\"issue-title\">" +
title +
"</p></a></div>";
$(".git-history").append(html);
});
}
parseJSON("JSON/github_issues.json", updateIssues);
// Update Git Pull Request
function updatePullMergeRequests(json) {
$("div").remove(".git-entry");
let requests = json.requests;
requests.forEach(function(request) {
const link = request.link;
const repo = request.repo;
const number = request.number;
const title = request.title;
const html = "<div class=\"git-entry content-font\"><a class=\"github-request-link\" href=\"" +
link + "\"><p class=\"request-repo\">Repo: " +
repo +
"</p><p class=\"request-number\">" +
(isGithub? "Pull Request #" : "Merge Request !") +
number +
"</p><p class=\"request-title\">" +
title +
"</p></a></div>";
$(".git-history").append(html);
});
}