Execute the JS code and you will get this:
Created
February 17, 2022 10:01
-
-
Save paxbun/619ce037e4b974b467b55beefba0dc83 to your computer and use it in GitHub Desktop.
Share your GitHub contributions in Wordle style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2022 Chanjung Kim (paxbun). | |
const numCommits = ( | |
Array.from( | |
document.querySelector("svg.js-calendar-graph-svg g") | |
.querySelectorAll("g") | |
).map(g => | |
Array.from(g.querySelectorAll("rect")) | |
.map(r => parseInt(r.getAttribute("data-count"))) | |
) | |
); | |
const rectangles = Array.from("⬛🟥🟧"); | |
const thresholds = [0, 10, 20]; | |
const joined = rectangles.map((rect, idx) => [rect, thresholds[idx]]); | |
const formattedNumCommits = ( | |
numCommits.map(row => | |
row.map(numCommit => { | |
for (const [rect, thres] of joined) { | |
if (numCommit <= thres) | |
return rect; | |
} | |
return "🟩"; | |
}) | |
) | |
); | |
const today = new Date().toLocaleDateString(); | |
const output = ( | |
`GitHub Commits ${today} | |
${formattedNumCommits.map(row => row.join("")).join("\n")}`); | |
const copyButton = document.createElement("summary"); | |
copyButton.setAttribute("class", "btn-link Link--muted mt-1 pinned-items-setting-link"); | |
copyButton.addEventListener("click", () => { | |
navigator.clipboard.writeText(output); | |
}); | |
copyButton.appendChild(document.createTextNode("Copy contributions")); | |
const contributionsElem = document.querySelector("div.js-yearly-contributions div"); | |
contributionsElem.appendChild(copyButton); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment