|
1 |
| -var path = document.location.pathname; |
| 1 | +var link = document.getElementsByClassName('octicon-link')[0], |
| 2 | + path = document.location.pathname, |
| 3 | + details, |
| 4 | + login, |
| 5 | + url; |
| 6 | + |
2 | 7 | if (m = path.match(/^\/([\w-]+)\??.*?/)) {
|
3 |
| - var login = m[1]; |
| 8 | + login = m[1].trim(); |
4 | 9 | if (-1 === ['timeline', 'languages', 'blog', 'explore'].indexOf(login)) {
|
5 |
| - var url = 'http://coderstats.net/github/' + login.trim() + '/'; |
6 |
| - var details = document.getElementsByClassName('vcard-details'); |
| 10 | + url = 'http://coderstats.net/github/' + login + '/'; |
| 11 | + details = document.getElementsByClassName('vcard-details'); |
7 | 12 | if (details.length > 0) {
|
8 |
| - var link = document.getElementsByClassName('octicon-link')[0]; |
| 13 | + addLink(); |
| 14 | + document.addEventListener('DOMSubtreeModified', navClick, false); |
| 15 | + } |
| 16 | + } |
| 17 | +} |
9 | 18 |
|
10 |
| - var li = document.createElement('li'); |
11 |
| - li.setAttribute('class', 'vcard-detail pt-1'); |
12 |
| - li.setAttribute('itemprop', 'url'); |
13 | 19 |
|
14 |
| - var a = document.createElement('a'); |
15 |
| - a.setAttribute('href', url); |
16 |
| - a.textContent = "CoderStats('" + login + "')"; |
| 20 | +function addLink() { |
| 21 | + let cslink = document.getElementById('coderstats'); |
| 22 | + if (cslink) return; |
17 | 23 |
|
18 |
| - var svg = link.cloneNode(); |
19 |
| - svg.appendChild(link.childNodes[0].cloneNode()) |
| 24 | + var li = document.createElement('li'); |
| 25 | + li.setAttribute('id', 'coderstats'); |
| 26 | + li.setAttribute('class', 'vcard-detail pt-1'); |
| 27 | + li.setAttribute('itemprop', 'url'); |
20 | 28 |
|
21 |
| - li.appendChild(svg); |
22 |
| - li.appendChild(a); |
23 |
| - details[0].appendChild(li); |
24 |
| - } |
25 |
| - } |
26 |
| -} |
| 29 | + var a = document.createElement('a'); |
| 30 | + a.setAttribute('href', url); |
| 31 | + a.textContent = "CoderStats('" + login + "')"; |
| 32 | + |
| 33 | + var svg = link.cloneNode(); |
| 34 | + svg.appendChild(link.childNodes[0].cloneNode()) |
| 35 | + |
| 36 | + li.appendChild(svg); |
| 37 | + li.appendChild(a); |
| 38 | + details[0].appendChild(li); |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +// https://github.com/KyroChi/GitHub-Profile-Fluency/blob/Google-Chrome/chrome/content.js |
| 43 | +function navClick() { |
| 44 | + document.removeEventListener('DOMSubtreeModified', navClick); |
| 45 | + setTimeout(function() { |
| 46 | + addLink(); |
| 47 | + document.addEventListener('DOMSubtreeModified', navClick, false); |
| 48 | + }, 500); |
| 49 | +} |
0 commit comments