From cf4cc3b5c32644b1a44c0463b025833b01c8095f Mon Sep 17 00:00:00 2001 From: Altafur Rahman Date: Sun, 12 Jan 2025 02:11:48 +0600 Subject: [PATCH] feat: add badges for project and repository view counts with copy functionality (#3215) --- README.md | 2 +- .../templates/projects/project_detail.html | 55 +++++++++++++++++++ website/templates/projects/repo_detail.html | 54 +++++++++++++++++- 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d7abd354..f01845402 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

Build GitHub stars

-Views +Views Everything is on our homepage diff --git a/website/templates/projects/project_detail.html b/website/templates/projects/project_detail.html index 32a038e31..53c64920d 100644 --- a/website/templates/projects/project_detail.html +++ b/website/templates/projects/project_detail.html @@ -158,6 +158,27 @@

{{ project.name }}

+ +
+

Project View Count Badge

+
+ +
+
HTML:
+
+ + +
+
+
+
@@ -287,3 +308,37 @@

Project Timeline

{% endblock content %} +{% block after_js %} + +{% endblock %} diff --git a/website/templates/projects/repo_detail.html b/website/templates/projects/repo_detail.html index acc4ec346..95ef68032 100644 --- a/website/templates/projects/repo_detail.html +++ b/website/templates/projects/repo_detail.html @@ -72,6 +72,27 @@

{{ repo.name }}

+ +
+

Repository View Count Badge

+
+ +
+
HTML:
+
+ + +
+
+
+
@@ -740,7 +761,38 @@

-const refreshSection = async (button, section) => { + function copyToClipboard(elementId) { + const element = document.getElementById(elementId); + + // Select the text + element.select(); + element.setSelectionRange(0, 99999); // For mobile devices + + // Copy the text + try { + navigator.clipboard.writeText(element.value).then(() => { + // Get the button + const button = element.nextElementSibling; + const originalText = button.textContent; + + // Change button style to show success + button.textContent = 'Copied!'; + button.classList.remove('bg-red-500', 'hover:bg-red-600'); + button.classList.add('bg-green-500', 'hover:bg-green-600'); + + // Reset button after 2 seconds + setTimeout(() => { + button.textContent = originalText; + button.classList.remove('bg-green-500', 'hover:bg-green-600'); + button.classList.add('bg-red-500', 'hover:bg-red-600'); + }, 2000); + }); + } catch (err) { + console.error('Failed to copy text: ', err); + } + } + + const refreshSection = async (button, section) => { if (button.classList.contains('refresh_spinner')) { return; }