-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforeground.js
220 lines (194 loc) · 4.94 KB
/
foreground.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
212
213
214
215
216
217
218
219
220
const supportedLanguages = {
JavaScript: 1,
Vue: 1,
Java: 1,
TypeScript: 1,
Python: 1,
Go: 1,
HTML: 1,
'C++': 1,
'C#': 1,
CSS: 1,
SCSS: 1,
sass: 1,
Jupyter: 1,
Vim: 1,
VimL: 1,
TeX: 1,
Swift: 1,
Svelte: 1,
Kotlin: 1,
Dart: 1,
Gherkin: 1,
'Objective-C': 1,
R: 1,
Powershell: 1,
Shell: 1,
Cuda: 1,
Lua: 1,
PHP: 1,
Ruby: 1,
CoffeeScript: 1,
Rust: 1,
Dockerfile: 1,
AutoHotkey: 1,
Rebol: 1,
C: 1,
PureBasic: 1,
Makefile: 1,
Visual: 1,
D: 1,
Lisp: 1,
}
function addLanguage(lang, card, span) {
if (span) {
span.classList.add(lang)
span.classList.add('background-none')
}
card.classList.add(lang)
}
function addRepoIcon(card) {
let icon = card.getElementsByTagName('svg')[0]
if (icon) {
icon.classList.remove('color-text-secondary')
icon.classList.remove('color-fg-muted')
}
}
function addLinks(card, lang) {
let links = card.getElementsByTagName('a')
for (let i = 0; i < links.length; i++) {
links[i].classList.add(lang)
links[i].classList.add('background-none')
if (i == 0) {
links[i].classList.add('card-link')
} else {
links[i].classList.add('all-links')
links[i].classList.remove('Link--muted')
links[i].classList.add('medium')
}
}
}
function addOwner(card, lang) {
let owner = card.getElementsByClassName('owner')
if (owner.length > 0) {
owner[0].classList.add(lang)
owner[0].classList.add('background-none')
owner[0].classList.add('bold')
}
}
function addTitle(card, lang) {
let title = card.getElementsByClassName('repo')
title[0].classList.add(lang)
title[0].classList.add('bold')
title[0].classList.add('background-none')
}
function addLabel(card, lang) {
let label = card.getElementsByClassName('Label')
if (label.length > 0) {
label[0].classList.add(lang)
label[0].classList.remove('Label--secondary')
label[0].classList.add('Label')
}
}
function addDescription(card, lang) {
let desc = card.getElementsByClassName('pinned-item-desc')
if (desc.length > 0 && desc[0]) {
desc[0].classList.add(lang)
desc[0].classList.add('desc')
desc[0].classList.add('background-none')
desc[0].classList.remove('color-fg-muted')
}
}
function addForkedText(card) {
let forked = card.getElementsByClassName('color-fg-muted')
if (
forked.length > 0 &&
forked[0].nodeName == 'P' &&
forked[0].hasChildNodes() &&
forked[0].firstElementChild &&
forked[0].firstElementChild.nodeName == 'A'
) {
//Forked Repo Name and Link
forked[0].firstElementChild.classList.add('opacity-10')
//"Forked From" text
forked[0].classList.add('opacity-9')
forked[0].classList.remove('color-fg-muted')
}
}
function addExtraIcons(card, lang) {
let extras = card.getElementsByClassName('pinned-item-meta')
if (extras.length > 0 && extras[0]) {
for (let i = 0; i < extras.length; i++) {
const element = extras[i]
element.classList.add(lang)
element.classList.add('background-none')
element.classList.remove('Link--muted')
}
}
}
function addGrabbers(card, lang) {
let grabbers = card.getElementsByClassName('octicon-grabber')
if (grabbers.length > 0) {
grabbers[0].classList.add(lang)
grabbers[0].classList.add('background-none')
}
}
function addGistIcon(card, lang) {
let codeIcon = card.getElementsByClassName('octicon-code-square')
if (codeIcon.length > 0) {
codeIcon[0].classList.add(lang)
codeIcon[0].classList.add('background-none')
codeIcon[0].classList.remove('color-text-secondary')
}
}
function addGistBackground(card, lang) {
let bgGist = card.getElementsByClassName('rounded-bottom-1')
if (bgGist.length > 0 && bgGist[0]) {
bgGist[0].classList.add(lang)
bgGist[0].classList.add('background-none')
bgGist[0].classList.remove('color-bg-subtle')
}
}
//Get all cards from profile
let cards = document.getElementsByClassName('pinned-item-list-item')
for (const card of cards) {
card.classList.add('card')
//Get programming language for a card
let languageSpan = card.querySelector('[itemprop=programmingLanguage]')
let language = 'none'
if (languageSpan) {
//Get programming language first name
//Composed names like: "Jupyter Notebook" stay as "Jupyter"
language = languageSpan.innerHTML.split(' ')[0]
//Validate if it is a supported language
if (language in supportedLanguages) {
language = language
} else {
language = 'none'
}
}
// Add programming name CSS class to span and card
addLanguage(language, card, languageSpan)
//Card title of Repo
addTitle(card, language)
//Link to repo
addLinks(card, language)
//Public/Private Repo Label
addLabel(card, language)
// Remove default color from Repo Icon
addRepoIcon(card)
//Card description of Repo
addDescription(card, language)
//"Forked From" text
addForkedText(card)
//Owner of repo (for repos not owned by the user)
addOwner(card, language)
//Star and Fork icon
addExtraIcons(card, language)
//Drag and Drop Grabber for repository cards
addGrabbers(card, language)
//Code Icon for gists
addGistIcon(card, language)
//Backgroung for gists preview
addGistBackground(card, language)
}