From 0acd8874518c29c9e58d4054fc58bf5840be788a Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Mon, 6 Jul 2026 17:53:23 +0800 Subject: [PATCH] Add a copy function for the SHA256 checksum --- include/layout.inc | 7 +++++++ include/version.inc | 5 +++-- js/common.js | 15 +++++++++++++++ pre-release-builds.php | 6 ++---- releases/index.php | 9 ++------- styles/theme-base.css | 41 +++++++++++++++++++++++++++++++++++------ 6 files changed, 64 insertions(+), 19 deletions(-) diff --git a/include/layout.inc b/include/layout.inc index 30550b6a65..98f3fb095f 100644 --- a/include/layout.inc +++ b/include/layout.inc @@ -504,6 +504,13 @@ function site_footer(array $config = []): void require __DIR__ . "/footer.inc"; } +function sha256_html(string $checksum): string +{ + $checksum = htmlspecialchars($checksum, ENT_QUOTES, 'UTF-8'); + + return '' . $checksum . ''; +} + function get_nav_items(): array { return [ new NavItem( diff --git a/include/version.inc b/include/version.inc index 31e4ff7a8a..65d338d94d 100644 --- a/include/version.inc +++ b/include/version.inc @@ -139,8 +139,9 @@ function show_source_releases() ', $rel['md5'], ''; - if (isset($rel['sha256'])) echo '', $rel['sha256'], ''; + if (isset($rel['sha256'])) { + echo sha256_html($rel['sha256']); + } ?>
diff --git a/js/common.js b/js/common.js
index 86b4862fd5..fe45d50041 100644
--- a/js/common.js
+++ b/js/common.js
@@ -879,3 +879,18 @@ function applyTheme(theme) {
}
applyTheme(savedTheme)
+
+const downloads = document.querySelector('.downloads');
+downloads?.addEventListener('click', function (event) {
+ var button = event.target.closest('.sha256-copy');
+ if (!button || !navigator.clipboard) {
+ return;
+ }
+
+ navigator.clipboard.writeText(button.dataset.copyText).then(function () {
+ button.textContent = 'Copied';
+ setTimeout(function () {
+ button.textContent = 'Copy';
+ }, 1500);
+ });
+});
diff --git a/pre-release-builds.php b/pre-release-builds.php
index 868ed84d50..80c9d8585c 100644
--- a/pre-release-builds.php
+++ b/pre-release-builds.php
@@ -97,9 +97,8 @@
-
-
+
No checksum value available)
@@ -189,7 +188,7 @@
}
if ($includeSha && $sha !== '') {
- $parts[] = '' . htmlspecialchars($sha, ENT_QUOTES, 'UTF-8') . '';
+ $parts[] = sha256_html($sha);
}
return '
\n";
- $linebreak = '';
- foreach (['md5', 'sha256'] as $cs) {
- if (isset($src[$cs])) {
- echo $linebreak;
- echo "{$cs}: {$src[$cs]}\n";
- $linebreak = "
";
- }
+ if (isset($src['sha256'])) {
+ echo sha256_html($src['sha256']), "\n";
}
} else {
echo "{$src['name']}";
diff --git a/styles/theme-base.css b/styles/theme-base.css
index faeab9d6b4..cfd83fd345 100644
--- a/styles/theme-base.css
+++ b/styles/theme-base.css
@@ -783,20 +783,49 @@ fieldset {
.content-header .changelog {
color:#369;
}
-.content-box .md5sum, .content-box .sha256 {
+.content-box .sha256,
+.downloads .sha256 {
display: block;
font: normal 0.875rem/1.5rem "Fira Mono", "Source Code Pro", monospace;
overflow: hidden;
text-overflow: ellipsis;
}
-.content-box .md5sum:before {
- content: "md5: ";
- font-family: var(--font-family-sans-serif);
-}
-.content-box .sha256:before {
+.content-box .sha256:before,
+.downloads .sha256:before {
content: "sha256: ";
font-family: var(--font-family-sans-serif);
}
+.content-box .sha256-row,
+.downloads .sha256-row {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+}
+.content-box .sha256-row .sha256,
+.downloads .sha256-row .sha256 {
+ min-width: 0;
+}
+.content-box .sha256-copy,
+.downloads .sha256-copy {
+ border: 1px solid var(--dark-blue-color);
+ border-radius: 30px;
+ background-color: var(--dark-blue-color);
+ color: #fff;
+ padding: 0.2rem 0.65rem;
+ font-size: 0.75rem;
+ line-height: 1rem;
+ cursor: pointer;
+ min-width: 4.25rem;
+ text-align: center;
+ white-space: nowrap;
+}
+.content-box .sha256-copy:hover,
+.content-box .sha256-copy:focus,
+.downloads .sha256-copy:hover,
+.downloads .sha256-copy:focus {
+ border-color: var(--dark-magenta-color);
+ background-color: var(--dark-magenta-color);
+}
.content-box .releasedate {
float: right;
font-size: 0.9rem;