Use a GraphQL query (GitHub API v4) and a ContributionsCollection object.
Define from by now minus one year, and to by 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 to then call, as in here:
query ContributionsView($username: String!, $from: DateTime!, $to: DateTime!) {
user(login: $username) {
contributionsCollection(from: $from, to: $to) {
totalCommitContributions
totalIssueContributions
totalPullRequestContributions
totalPullRequestReviewContributions
}
}
}
Once the script works outside your Blogger page, you can include it with a <script src=...> element.
I've tried many solutions and I improved one to get the following which works the best for me:
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();
}
I suggest using the unofficial Github Contributions API located at this site
Here is an example
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