The objective of this project is to re-create a contributions calendar, as GitHub one does, but use it as playground for draw forms over it.
I will use this functionality to create an Electron app, where you can simulate this board into different ways and colors. Much more comes to my mind but let's see what happens. I use this project to learn and practice more, from algorithms to new enviroments such as Desktop apps.
Name | Type | Description |
---|---|---|
parent | HTMLElement | Parent element to render inside. |
contributions | Object | List to turn calendar dates on. eg. { "4/27/2021": 4, "4/25/2021": 2, } , where numeric value comes from range [0-4] to indicate changes proportion and color intensity. |
-
setContributions(contributions): void
It will replace contributions with entered through new object parameter.
Parameter Type Description contributions Object List to turn calendar dates on. eg. { "4/27/2021": 4, "4/25/2021": 2, }
, where numeric value comes from range[0-4]
to indicate changes proportion and color intensity.
This is a copy my contributions board status.
- Go to a GitHub profile page.
- Open browser inspector by pressing
F12
in your keyboard, also using shortcuts such asfn + F12
orCtrl + Shift + i
. - Copy/paste code below to your browser console. The object will be copied automatically.
- Replace copied object in file
./src/js/contributions.js
. - Build and run desktop app through command
npm start
.
const calendar = document.querySelector(".js-calendar-graph-svg");
const wrapper = calendar.children[0];
const contributions = {};
for(let i = 0; i < wrapper.children.length; i++) {
const child = wrapper.children[i];
if (child.tagName !== "g") continue;
for(let j = 0; j < child.children.length; j++) {
const date = child.children[j];
const year = +date.getAttribute("data-date").split("-")[0];
const month = +date.getAttribute("data-date").split("-")[1];
const day = +date.getAttribute("data-date").split("-")[2];
const formattedDate = new Date(year, month - 1, day);
const level = +date.getAttribute("data-level");
if (level === 0) continue;
contributions[formattedDate.toLocaleDateString("EN")] = level;
}
}
copy(JSON.stringify(contributions));
console.warn("COPIED!");
- Electron
- JavaScript
- CSS Grid
I will appreciate any feedbacks you could give me. Thanks