Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy to clipboard button #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ <h1 class="title">TOTP Token Generator</h1>
<progress class="progress is-info is-small" v-bind:value="period - updatingIn" :max="period"></progress>
</div>

<div class="tile is-ancestor">
<div class="tile is-ancestor is-vertical">
<div class="tile box">
<p class="title is-size-1 has-text-centered" style="margin: auto">{{ token }}</p>
<textarea
class="title is-size-1 has-text-centered"
style="margin: auto; border: none; overflow: hidden; outline: none; box-shadow: none; resize: none;"
rows="1"
readonly
ref="tokenInput"
>{{ token }}</textarea>
</div>
<div class="tile button is-fullwidth" @click='copyToClipboard'>
Copy to clipboard
</div>
<p class="tag">
Or refresh the page to select the token
</p>
</div>

</div>
Expand Down
9 changes: 9 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ new Vue({

mounted: function () {
this.update();
this.$nextTick(function () {
this.copyToClipboard();
})

this.intervalHandle = setInterval(this.update, 1000);
},
Expand All @@ -59,6 +62,12 @@ new Vue({
update: function () {
this.updatingIn = this.period - (getCurrentSeconds() % this.period);
this.token = truncateTo(this.totp.generate(), this.digits);
},
copyToClipboard: function() {
if (!this.$refs.tokenInput) return;

this.$refs.tokenInput.select();
document.execCommand('copy');
}
}
});