|
10 | 10 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
11 | 11 | <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
12 | 12 | <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
| 13 | +<style> |
| 14 | + body { |
| 15 | + word-break: break-all; |
| 16 | + } |
| 17 | +</style> |
13 | 18 | <body>
|
14 | 19 |
|
15 | 20 | <div id="app" class="container">
|
|
44 | 49 | <div id="information">
|
45 | 50 | <ul class="list-group mx-auto mb-5">
|
46 | 51 | <li class="list-group-item" v-for="x in data">
|
47 |
| - <p><strong>Repo:</strong>{{x['Repos']}}</p> |
48 |
| - <p><strong>Description:</strong>{{x['description']}}</p> |
49 |
| - <p><strong>URL:</strong> <a href="{{x['html_url']}}">{{x['html_url']}}</a></p> |
| 52 | + <p><strong>Repo:</strong> {{x['name']}}</p> |
| 53 | + <p><strong>Description:</strong> {{x['description']}}</p> |
| 54 | + <p><strong>URL:</strong> <a :href="x['html_url']" target="_blank">{{x['html_url']}}</a></p> |
50 | 55 | </li>
|
51 | 56 | </ul>
|
52 |
| - |
| 57 | + <h3 style="text-align: center;display: none" id="no_more"> |
| 58 | + No more repos |
| 59 | + </h3> |
| 60 | + <br> |
53 | 61 | </div>
|
54 | 62 |
|
55 | 63 |
|
56 | 64 | </div>
|
57 | 65 |
|
58 | 66 | <script>
|
59 | 67 | window.page = 0;
|
| 68 | + window.username = undefined; |
| 69 | + window.max = false; |
60 | 70 | function get_repos(username) {
|
61 |
| - $.get(`https://api.github.com/users/${username}/repos?page=${window.page + 1}`, function(data){ |
| 71 | + if (window.username === username){ |
62 | 72 | window.page += 1;
|
63 |
| - console.log(data) |
64 |
| - $("#Wrong_Username").css("display", "none") |
| 73 | + if (window.max){ |
| 74 | + |
| 75 | + return ; |
| 76 | + } |
| 77 | + |
| 78 | + }else { |
| 79 | + window.page = 0; |
| 80 | + window.username = username; |
| 81 | + window.max = false; |
| 82 | + } |
| 83 | + |
| 84 | + $.get(`https://api.github.com/users/${username}/repos?page=${window.page + 1}`, function(data){ |
| 85 | + console.log(data); |
| 86 | + |
| 87 | + if (data.length === 0){ |
| 88 | + $("#no_more").css("display", ""); |
| 89 | + window.max = true; |
| 90 | + }else { |
| 91 | + $("#no_more").css("display", "none"); |
| 92 | + } |
| 93 | + |
| 94 | + if (window.page === 0){ |
| 95 | + myObject.$data.data = data; |
| 96 | + }else { |
| 97 | + myObject.$data.data = myObject.$data.data.concat(data); |
| 98 | + } |
| 99 | + $("#Wrong_Username").css("display", "none"); |
65 | 100 | }).fail(function() {
|
66 | 101 | console.log("Problem")
|
67 | 102 | $('#Wrong_Username').css("display", "")
|
|
74 | 109 | data: [],
|
75 | 110 | }
|
76 | 111 | })
|
| 112 | + |
| 113 | + $(window).scroll(function() { |
| 114 | + if(Math.ceil($(window).scrollTop()) === Math.ceil(($(document).height() - $(window).height()))) { |
| 115 | + get_repos(window.username) |
| 116 | + } |
| 117 | + }); |
| 118 | + |
| 119 | + $('#submit').on("click", function (){ |
| 120 | + const username = $("#username").val(); |
| 121 | + get_repos(username) |
| 122 | + }) |
77 | 123 | </script>
|
78 | 124 |
|
79 | 125 | </body>
|
|
0 commit comments