Created
February 17, 2022 10:01
-
-
Save paxbun/619ce037e4b974b467b55beefba0dc83 to your computer and use it in GitHub Desktop.
Revisions
-
paxbun created this gist
Feb 17, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Execute the JS code and you will get this:  This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ // 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);