|
1 | | -varpath=document.location.pathname, |
2 | | -details, |
3 | | -login, |
4 | | -url; |
5 | | - |
6 | | -if(m=path.match(/^\/([\w-]+)\??.*?/)){ |
7 | | -login=m[1].trim(); |
8 | | -if(-1===['timeline','languages','blog','explore'].indexOf(login)){ |
9 | | -url='http://coderstats.github.io/github#'+login; |
10 | | -details=document.getElementsByClassName('vcard-details'); |
11 | | -if(details.length>0){ |
12 | | -addLink(); |
13 | | -document.addEventListener('DOMSubtreeModified',navClick,false); |
14 | | -} |
| 1 | +constmeta_profile=document.querySelector('meta[property="profile:username"]'); |
| 2 | +if(login=meta_profile.getAttribute('content')){ |
| 3 | +if(details=document.getElementsByClassName('vcard-details')){ |
| 4 | +addLink('http://coderstats.github.io/github#'+login); |
15 | 5 | } |
16 | 6 | } |
17 | 7 |
|
18 | 8 |
|
19 | | -functionaddLink(){ |
20 | | -letcslink=document.getElementById('coderstats'); |
| 9 | +functionaddLink(url){ |
| 10 | +constcslink=document.getElementById('coderstats'); |
21 | 11 | if(cslink)return; |
22 | 12 |
|
23 | | -varli=document.createElement('li'); |
| 13 | +constli=document.createElement('li'); |
24 | 14 | li.setAttribute('id','coderstats'); |
25 | 15 | li.setAttribute('class','vcard-detail pt-1'); |
26 | 16 | li.setAttribute('itemprop','url'); |
27 | 17 |
|
28 | | -letspan=document.createElement('span'); |
| 18 | +constspan=document.createElement('span'); |
29 | 19 | span.setAttribute('class','octicon'); |
30 | 20 | span.setAttribute('style','margin-top:-2px;'); |
31 | 21 | span.textContent="📊"; |
32 | 22 | li.appendChild(span) |
33 | 23 |
|
34 | | -leta=document.createElement('a'); |
| 24 | +consta=document.createElement('a'); |
35 | 25 | a.setAttribute('href',url); |
36 | 26 | a.textContent="CoderStats('"+login+"')"; |
37 | 27 |
|
38 | 28 | li.appendChild(a); |
39 | 29 | details[0].appendChild(li); |
40 | 30 | } |
41 | | - |
42 | | - |
43 | | -// https://github.com/KyroChi/GitHub-Profile-Fluency/blob/Google-Chrome/chrome/content.js |
44 | | -functionnavClick(){ |
45 | | -document.removeEventListener('DOMSubtreeModified',navClick); |
46 | | -setTimeout(function(){ |
47 | | -addLink(); |
48 | | -document.addEventListener('DOMSubtreeModified',navClick,false); |
49 | | -},500); |
50 | | -} |