Skip to content

Commit

Permalink
add clipboard button
Browse files Browse the repository at this point in the history
  • Loading branch information
dieseltravis committed Dec 11, 2024
1 parent 0a02377 commit 2e5881e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions public/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const process = function (funs, day, part) {
const input = document.getElementById('input' + part);
const getInput = document.querySelector('#input' + part + ' + .get-input');
const answer = document.getElementById('part' + part);
const clip = document.getElementById('clip' + part);
const button = document.getElementById('button' + part);

getInput.addEventListener('click', async (ev) => {
Expand All @@ -24,6 +25,7 @@ const process = function (funs, day, part) {

// fun time
answer.innerText = funs(day, part)(input.value);
clip.style.display = 'inline-block';

console.timeEnd(timer);
html.classList.remove('wait');
Expand All @@ -32,6 +34,10 @@ const process = function (funs, day, part) {
};

button.addEventListener('click', onevent);
clip.addEventListener('click', function (ev) {
ev.preventDefault();
navigator.clipboard.writeText(answer.innerText);
});
};

const day = function (funs, day) {
Expand Down
4 changes: 2 additions & 2 deletions views/day.ntl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<form method="POST" action="/day{{day}}part1">
<textarea id="input1" name="input" placeholder="puzzle input" cols="40" rows="5"></textarea>
<a href="//adventofcode.com/{{year}}/day/{{day_num}}/input" target="_blank" class="get-input">get input</a>
<code id="part1"></code>
<code id="part1"></code><button id="clip1" style="display:none">📋</button>
<input id="button1" type="button" value="run in client" />
<input type="submit" value="run on server" />
</form>
Expand All @@ -43,7 +43,7 @@
<form method="POST" action="/day{{day}}part2">
<textarea id="input2" name="input" placeholder="puzzle input" cols="40" rows="5"></textarea>
<a href="//adventofcode.com/{{year}}/day/{{day_num}}/input" target="_blank" class="get-input">get input</a>
<code id="part2"></code>
<code id="part2"></code><button id="clip2" style="display:none">📋</button>
<input id="button2" type="button" value="run in client" />
<input type="submit" value="run on server" />
</form>
Expand Down

0 comments on commit 2e5881e

Please sign in to comment.