Skip to content

Instantly share code, notes, and snippets.

@paxbun
Created February 17, 2022 10:01
Show Gist options
  • Select an option

  • Save paxbun/619ce037e4b974b467b55beefba0dc83 to your computer and use it in GitHub Desktop.

Select an option

Save paxbun/619ce037e4b974b467b55beefba0dc83 to your computer and use it in GitHub Desktop.

Revisions

  1. paxbun created this gist Feb 17, 2022.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Execute the JS code and you will get this:

    ![image](https://user-images.githubusercontent.com/17005454/154452109-1f80b54c-1bf1-422d-a2c5-b40c04ba340a.png)
    40 changes: 40 additions & 0 deletions wordle.js
    Original 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);