Utilice una consulta de GraphQL ( API de GitHub v4 ) y un objeto ContributionsCollection .
Defina from now menos un año, y to now .
var to = new Date(); var year = to.getFullYear(); var month = to.getMonth(); var day = to.getDate(); var from = new Date(year - 1, month, day);Use graphql.js para luego llamar, como aquí :
query ContributionsView($username: String!, $from: DateTime!, $to: DateTime!) { user(login: $username) { contributionsCollection(from: $from, to: $to) { totalCommitContributions totalIssueContributions totalPullRequestContributions totalPullRequestReviewContributions } } } Una vez que el script funciona fuera de su página de Blogger, puede incluirlo con un elemento <script src=...> .
Probé muchas soluciones y mejoré una para obtener la siguiente que funciona mejor para mí:
function get_contribution() { profile_url = "https://cors-anywhere.herokuapp.com/https://github.com/users/USERNAME/contributions"; var xhr = new XMLHttpRequest(); xhr.responseType = 'document'; xhr.open('GET', profile_url, true); xhr.onload = function () { if (this.status == 200) { var response = xhr.responseXML.getElementsByClassName('f4 text-normal mb-2')[0].innerText; // get only the numbers in response contribution = response.replace(/[^0-9]/g, ''); // The number of contributions is now saved in the contribution variable } }; xhr.send(); } onload = function(){ get_contribution(); }Sugiero usar la Github Contributions API no oficial que se encuentra en este sitio
Aquí hay un ejemplo
async function getContributions(username) { var data = await (await fetch(`https://corsanywhere.herokuapp.com/https://github-contributions-api.deno.dev/${username}.json`)).json(); console.log(data.totalContributions) } getContributions("octocat") // Returns 0, as Octocat has zero contributions