Skip to content

Commit a2eaaf3

Browse files
committed
Add a copy function for the SHA256 checksum
1 parent 1d4f635 commit a2eaaf3

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

include/version.inc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,15 @@ function show_source_releases()
139139
<?php download_link($rel['filename'], $rel['filename']); ?>
140140
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
141141
<?php
142-
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
143-
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
142+
if (isset($rel['md5'])) {
143+
echo '<span class="md5sum">', $rel['md5'], '</span>';
144+
}
145+
if (isset($rel['sha256'])) {
146+
echo '<span class="sha256-row">';
147+
echo '<span class="sha256">', $rel['sha256'], '</span>';
148+
echo '<button type="button" class="sha256-copy" data-copy-text="', $rel['sha256'], '" aria-label="Copy sha256 checksum">Copy</button>';
149+
echo '</span>';
150+
}
144151
?>
145152
<?php if (isset($rel['note']) && $rel['note']): ?>
146153
<p>
@@ -161,5 +168,20 @@ function show_source_releases()
161168
</div>
162169
<?php endforeach; ?>
163170
<?php endforeach; /* major releases loop end */ ?>
171+
<script>
172+
document.addEventListener('click', function (event) {
173+
var button = event.target.closest('.sha256-copy');
174+
if (!button || !navigator.clipboard) {
175+
return console.error('Clipboard API not available');
176+
}
177+
178+
navigator.clipboard.writeText(button.dataset.copyText).then(function () {
179+
button.textContent = 'Copied';
180+
setTimeout(function () {
181+
button.textContent = 'Copy';
182+
}, 3000);
183+
});
184+
});
185+
</script>
164186
<?php
165187
}

styles/theme-base.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,32 @@ fieldset {
797797
content: "sha256: ";
798798
font-family: var(--font-family-sans-serif);
799799
}
800+
.content-box .sha256-row {
801+
display: flex;
802+
align-items: center;
803+
gap: 0.5rem;
804+
}
805+
.content-box .sha256-row .sha256 {
806+
min-width: 0;
807+
}
808+
.content-box .sha256-copy {
809+
border: 1px solid var(--dark-blue-color);
810+
border-radius: 30px;
811+
background-color: var(--dark-blue-color);
812+
color: #fff;
813+
padding: 0.2rem 0.65rem;
814+
font-size: 0.75rem;
815+
line-height: 1rem;
816+
cursor: pointer;
817+
min-width: 4.25rem;
818+
text-align: center;
819+
white-space: nowrap;
820+
}
821+
.content-box .sha256-copy:hover,
822+
.content-box .sha256-copy:focus {
823+
border-color: var(--dark-magenta-color);
824+
background-color: var(--dark-magenta-color);
825+
}
800826
.content-box .releasedate {
801827
float: right;
802828
font-size: 0.9rem;

0 commit comments

Comments
 (0)