Use Javascript to get the list of a user's Github repositories

后端 未结 4 1841
迷失自我
迷失自我 2021-02-04 19:58

First of all, thanks for reading.

I am hosting my current projects on GitHub. Using GitHub Pages, I ]host my personal blog, you can reach the blog here.

On the b

4条回答
  •  情深已故
    2021-02-04 20:53

    Extending to @JColebrand's answer with the JQuery shortcut to XMLHttpRequest, $.getJson() , here is an API Call that works in 2020.

        user = 'tik9'
            apirepo = `https://api.github.com/users/${user}`
            
       listrepos = document.createElement('ul')
            document.getElementById('github').appendChild(listrepos)
            $.getJSON(apirepo + '/repos', function (data) {
                console.log('data now', data)
    
                function compare(a, b) {
                    if (a.watchers > b.watchers) {
                        return -1
                    }
                    if (a.watchers < b.watchers) {
                        return 1
                    }
                    return 0
                }
    
                data.sort(compare)
                data.forEach(v => {
    
                    listItemRepo = document.createElement('li')
                    listrepos.appendChild(listItemRepo)
                    hlink = document.createElement('a')
                    listItemRepo.appendChild(hlink)
                    hlink.textContent = `${v.description} | Stars: ${v.watchers}`
                    hlink.href = v.html_url
                })
            })
    
    
        
    
    
    

    Github Repositories

提交回复
热议问题