Skip to content

Commit

Permalink
fix: generate code and copy to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sameemul-haque committed Apr 25, 2024
1 parent 0ae670b commit 62a11da
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
11 changes: 3 additions & 8 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,18 @@ <h2>GitHub Contribution Graph Customizer</h2>
</ul>
</div>
</div>
<button class="generate-btn" onclick="">Generate</button>
<button class="generate-btn" onclick="generateCode()">Generate</button>
<div class="code-container">
<div class="code-editor">
<div class="code-header"><svg xmlns="http://www.w3.org/2000/svg" fill="#26a641" viewBox="0 0 115.77 122.88"
class="code-icon" xml:space="preserve">
<div class="code-header"><svg onclick="copyCode()" xmlns="http://www.w3.org/2000/svg" fill="#26a641"
viewBox="0 0 115.77 122.88" class="code-icon" xml:space="preserve">
<path
d="M89.62 13.96v7.73h12.2v.02c3.85.01 7.34 1.57 9.86 4.1 2.5 2.51 4.06 5.98 4.07 9.82h.02v73.3h-.02c-.01 3.84-1.57 7.33-4.1 9.86-2.51 2.5-5.98 4.06-9.82 4.07v.02H40.1v-.02c-3.84-.01-7.34-1.57-9.86-4.1-2.5-2.51-4.06-5.98-4.07-9.82h-.02V92.51h-12.2v-.02c-3.84-.01-7.34-1.57-9.86-4.1-2.5-2.51-4.06-5.98-4.07-9.82H0V13.95h.02c.01-3.85 1.58-7.34 4.1-9.86C6.63 1.59 10.1.03 13.94.02V0h61.73v.02c3.85.01 7.34 1.57 9.86 4.1 2.5 2.51 4.06 5.98 4.07 9.82h.02zm-10.58 7.73v-7.75h.02c0-.91-.39-1.75-1.01-2.37-.61-.61-1.46-1-2.37-1v.02H13.95v-.02c-.91 0-1.75.39-2.37 1.01-.61.61-1 1.46-1 2.37h.02v64.62h-.02c0 .91.39 1.75 1.01 2.37.61.61 1.46 1 2.37 1v-.02h12.2V35.64h.02c.01-3.85 1.58-7.34 4.1-9.86 2.51-2.5 5.98-4.06 9.82-4.07v-.02zm26.14 87.23V35.63h.02c0-.91-.39-1.75-1.01-2.37-.61-.61-1.46-1-2.37-1v.02H40.09v-.02c-.91 0-1.75.39-2.37 1.01-.61.61-1 1.46-1 2.37h.02v73.3h-.02c0 .91.39 1.75 1.01 2.37.61.61 1.46 1 2.37 1v-.02h61.73v.02c.91 0 1.75-.39 2.37-1.01.61-.61 1-1.46 1-2.37h-.02z"
style="fill-rule:evenodd;clip-rule:evenodd" />
</svg>
</div>
<div class="editor-content">
<code class="code">
<p><span class="color-1"> git commit --allow-empty --date=<span class="color-2">"27 Oct 2022"</span> --allow-empty-message -m "" </span><span class="color-2">&&</span></p>
<p><span class="color-1"> git commit --allow-empty --date=<span class="color-2">"28 Oct 2022"</span> --allow-empty-message -m "" </span><span class="color-2">&&</span></p>
<p><span class="color-1"> git commit --allow-empty --date=<span class="color-2">"29 Oct 2022"</span> --allow-empty-message -m "" </span><span class="color-2">&&</span></p>
<p><span class="color-1"> git commit --allow-empty --date=<span class="color-2">"30 Oct 2022"</span> --allow-empty-message -m "" </span><span class="color-2">&&</span></p>
<p><span class="color-1"> git commit --allow-empty --date=<span class="color-2">"31 Oct 2022"</span> --allow-empty-message -m "" </span></p>

</code>
</div>
Expand Down
61 changes: 55 additions & 6 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ document.addEventListener("DOMContentLoaded", function () {
if (currentDate.getFullYear() < startDate.getFullYear()) {
square.classList.add("previous-year");
}

dateforgitlist = [];
squaresContainer.appendChild(square);
if (!square.classList.contains("previous-year")) {
Expand All @@ -50,9 +50,9 @@ document.addEventListener("DOMContentLoaded", function () {
const options = { year: "numeric", month: "short", day: "numeric" };
dateforgit = new Date(square.getAttribute("data-date")).toLocaleDateString("en", options);
dateforgitlist.push(dateforgit);
console.log("dateforgit:",dateforgit);
console.log("dateforgitlist: ",dateforgitlist);
console.log("dateforgit:", dateforgit);
console.log("dateforgitlist: ", dateforgitlist);

increaseLevel(square, currentLevel);
});

Expand All @@ -66,8 +66,8 @@ document.addEventListener("DOMContentLoaded", function () {
if (index > -1) {
dateforgitlist.splice(index, 1);
}
console.log("dateforgit:",dateforgit);
console.log("dateforgitlist: ",dateforgitlist);
console.log("dateforgit:", dateforgit);
console.log("dateforgitlist: ", dateforgitlist);
});

square.addEventListener("mouseover", function (event) {
Expand Down Expand Up @@ -103,3 +103,52 @@ document.addEventListener("DOMContentLoaded", function () {
}
}
});

function generateCode() {
const dateList = dateforgitlist;
if (dateList.length === 0) {
alert("Don't try to play a fool with me Nikesh!");
return;
}
const codeContainer = document.querySelector(".code");
codeContainer.innerHTML = "";

dateList.forEach(date => {
const codeLine = document.createElement("p");
codeLine.innerHTML = `<span class="color-1"> git commit --allow-empty --date=<span class="color-2">"${date}"</span> --allow-empty-message -m "" </span><span class="color-2">&&</span>`;
codeContainer.appendChild(codeLine);

});

if (codeContainer.lastElementChild) {
lastLine = codeContainer.lastElementChild;
lastLine.removeChild(lastLine.lastElementChild);
}

const codeContainerElement = document.querySelector(".code-container");
codeContainerElement.style.display = "block";
}

function copyCode() {
const codeContainer = document.querySelector(".code");
const codeValue = codeContainer.innerText;
const codeText = document.createElement('textarea');
codeText.value = codeValue;
document.body.appendChild(codeText);

codeText.select();
codeText.setSelectionRange(0, 99999); // For mobile devices
navigator.clipboard.writeText(codeText.value);
document.body.removeChild(codeText);

const codeHeader = document.querySelector(".code-header");
const codeIcon = codeHeader.querySelector(".code-icon");
codeIcon.setAttribute("fill", "#26a641");
codeIcon.innerHTML = `<svg fill="#26a641" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M18.063 5.674a1 1 0 0 1 .263 1.39l-7.5 11a1 1 0 0 1-1.533.143l-4.5-4.5a1 1 0 1 1 1.414-1.414l3.647 3.646 6.82-10.002a1 1 0 0 1 1.39-.263Z"/></svg>`;

setTimeout(function () {
codeIcon.setAttribute("fill", "#26a641");
codeIcon.innerHTML = `<path d="M89.62 13.96v7.73h12.2v.02c3.85.01 7.34 1.57 9.86 4.1 2.5 2.51 4.06 5.98 4.07 9.82h.02v73.3h-.02c-.01 3.84-1.57 7.33-4.1 9.86-2.51 2.5-5.98 4.06-9.82 4.07v.02H40.1v-.02c-3.84-.01-7.34-1.57-9.86-4.1-2.5-2.51-4.06-5.98-4.07-9.82h-.02V92.51h-12.2v-.02c-3.84-.01-7.34-1.57-9.86-4.1-2.5-2.51-4.06-5.98-4.07-9.82H0V13.95h.02c.01-3.85 1.58-7.34 4.1-9.86C6.63 1.59 10.1.03 13.94.02V0h61.73v.02c3.85.01 7.34 1.57 9.86 4.1 2.5 2.51 4.06 5.98 4.07 9.82h.02zm-10.58 7.73v-7.75h.02c0-.91-.39-1.75-1.01-2.37-.61-.61-1.46-1-2.37-1v.02H13.95v-.02c-.91 0-1.75.39-2.37 1.01-.61.61-1 1.46-1 2.37h.02v64.62h-.02c0 .91.39 1.75 1.01 2.37.61.61 1.46 1 2.37 1v-.02h12.2V35.64h.02c.01-3.85 1.58-7.34 4.1-9.86 2.51-2.5 5.98-4.06 9.82-4.07v-.02zm26.14 87.23V35.63h.02c0-.91-.39-1.75-1.01-2.37-.61-.61-1.46-1-2.37-1v.02H40.09v-.02c-.91 0-1.75.39-2.37 1.01-.61.61-1 1.46-1 2.37h.02v73.3h-.02c0 .91.39 1.75 1.01 2.37.61.61 1.46 1 2.37 1v-.02h61.73v.02c.91 0 1.75-.39 2.37-1.01.61-.61 1-1.46 1-2.37h-.02z" style="fill-rule:evenodd;clip-rule:evenodd"/>`;
}, 3000);

}
4 changes: 3 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ h2 {
}

.generate-btn {
float: right;
display: block;
margin-left: auto;
padding: 8px;
font-weight: 600;
border: #0e4429 1px solid;
Expand Down Expand Up @@ -159,6 +160,7 @@ li {
}

.code-container {
display: none;
margin-top: 1rem;
margin-bottom: 1rem;
max-width: 600px;
Expand Down

0 comments on commit 62a11da

Please sign in to comment.