From 76cc8456d23bea8d8426d9f3ae14687a3df63bca Mon Sep 17 00:00:00 2001
From: Fluffy-Bean <michal-gdula@protonmail.com>
Date: Sat, 22 Apr 2023 13:48:06 +0000
Subject: [PATCH] Add clipboard function

---
 onlylegs/static/js/clipboard.js |  8 ++++++++
 onlylegs/templates/group.html   | 13 ++-----------
 onlylegs/templates/image.html   | 10 +---------
 onlylegs/templates/profile.html |  2 +-
 4 files changed, 12 insertions(+), 21 deletions(-)
 create mode 100644 onlylegs/static/js/clipboard.js

diff --git a/onlylegs/static/js/clipboard.js b/onlylegs/static/js/clipboard.js
new file mode 100644
index 0000000..0882f56
--- /dev/null
+++ b/onlylegs/static/js/clipboard.js
@@ -0,0 +1,8 @@
+function copyToClipboard(data) {
+    try {
+        navigator.clipboard.writeText(data)
+        addNotification("Copied to clipboard!", 4);
+    } catch (err) {
+        addNotification("Oh noes, something when wrong D:", 2);
+    }
+}
\ No newline at end of file
diff --git a/onlylegs/templates/group.html b/onlylegs/templates/group.html
index d69530f..c7c3827 100644
--- a/onlylegs/templates/group.html
+++ b/onlylegs/templates/group.html
@@ -9,15 +9,6 @@
     {% endif %}
 
     <script type="text/javascript">
-        function groupShare() {
-            try {
-                navigator.clipboard.writeText(window.location.href)
-                addNotification("Copied link!", 4);
-            } catch (err) {
-                addNotification("Failed to copy link! Are you on HTTP?", 2);
-            }
-        }
-
         {% if current_user.id == group.author.id %}
             function groupDelete() {
                 cancelBtn = document.createElement('button');
@@ -240,7 +231,7 @@
                 <p class="banner-subtitle">{{ images|length }} Images · {{ group.description }}</p>
                 <div class="pill-row">
                     <div>
-                        <button class="pill-item" onclick="groupShare()"><i class="ph ph-export"></i></button>
+                        <button class="pill-item" onclick="copyToClipboard(window.location.href)"><i class="ph ph-export"></i></button>
                     </div>
                     {% if current_user.id == group.author.id %}
                         <div>
@@ -258,7 +249,7 @@
                 <p class="banner-info">By {{ group.author.username }}</p>
                 <div class="pill-row">
                     <div>
-                        <button class="pill-item" onclick="groupShare()"><i class="ph ph-export"></i></button>
+                        <button class="pill-item" onclick="copyToClipboard(window.location.href)"><i class="ph ph-export"></i></button>
                     </div>
                     {% if current_user.id == group.author.id %}
                         <div>
diff --git a/onlylegs/templates/image.html b/onlylegs/templates/image.html
index bb40761..1a546fd 100644
--- a/onlylegs/templates/image.html
+++ b/onlylegs/templates/image.html
@@ -8,14 +8,6 @@
     <meta name="twitter:card" content="summary_large_image">
 
     <script type="text/javascript">
-        function imageShare() {
-            try {
-                navigator.clipboard.writeText(window.location.href)
-                addNotification("Copied link!", 4);
-            } catch (err) {
-                addNotification("Failed to copy link! Are you on HTTP?", 2);
-            }
-        }
         function fullscreen() {
             let info = document.querySelector('.info-container');
             let wrapper = document.querySelector('.image-grid');
@@ -119,7 +111,7 @@
                 {% if next_url %}<div><a class="pill-item" href="{{ next_url }}"><i class="ph ph-arrow-left"></i></a></div>{% endif %}
                 <div>
                     <button class="pill-item" onclick="fullscreen()" id="fullscreenImage"><i class="ph ph-info"></i></button>
-                    <button class="pill-item" onclick="imageShare()"><i class="ph ph-export"></i></button>
+                    <button class="pill-item" onclick="copyToClipboard(window.location.href)"><i class="ph ph-export"></i></button>
                     <a class="pill-item" href="{{ url_for('media_api.media', path='uploads/' + image.filename) }}" download onclick="addNotification('Download started!', 4)"><i class="ph ph-file-arrow-down"></i></a>
                 </div>
                 {% if current_user.id == image.author.id %}
diff --git a/onlylegs/templates/profile.html b/onlylegs/templates/profile.html
index af01581..9dd8dff 100644
--- a/onlylegs/templates/profile.html
+++ b/onlylegs/templates/profile.html
@@ -56,7 +56,7 @@
             <p class="banner-subtitle">{{ images|length }} Images · {{ groups|length }} Groups</p>
             <div class="pill-row">
                 <div>
-                    <button class="pill-item" onclick="profileShare()"><i class="ph ph-export"></i></button>
+                    <button class="pill-item" onclick="copyToClipboard(window.location.href)"><i class="ph ph-export"></i></button>
                     <button class="pill-item" onclick="moreInfo()"><i class="ph ph-info"></i></button>
                 </div>
                 {% if user.id == current_user.id %}