From a07a31a2bbe56a463edf57f5e911390fc183f1fe Mon Sep 17 00:00:00 2001
From: shortcutme <tamas@zeronet.io>
Date: Thu, 19 Jul 2018 20:42:04 +0200
Subject: [PATCH] Copy site url with peers link to sidebar

---
 plugins/Sidebar/SidebarPlugin.py     | 10 +++++++++-
 plugins/Sidebar/media/Sidebar.coffee | 13 +++++++++++++
 plugins/Sidebar/media/all.js         | 15 +++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/plugins/Sidebar/SidebarPlugin.py b/plugins/Sidebar/SidebarPlugin.py
index bb4fd1bf..6ef218b5 100644
--- a/plugins/Sidebar/SidebarPlugin.py
+++ b/plugins/Sidebar/SidebarPlugin.py
@@ -115,9 +115,17 @@ class UiWebsocketPlugin(object):
         else:
             local_html = ""
 
+        copy_link = "http://127.0.0.1:43110/%s/?zeronet_peers=%s" % (
+            site.content_manager.contents["content.json"].get("domain", site.address),
+            ",".join([peer.key for peer in site.getConnectablePeers(20, allow_private=False)])
+        )
+
         body.append(_(u"""
             <li>
-             <label>{_[Peers]}</label>
+             <label>
+              {_[Peers]}
+              <small><a href='{copy_link}' id='link-copypeers' class='link-right'>{_[Copy to clipboard]}</a></small>
+             </label>
              <ul class='graph'>
               <li style='width: 100%' class='total back-black' title="{_[Total peers]}"></li>
               <li style='width: {percent_connectable:.0%}' class='connectable back-blue' title='{_[Connectable peers]}'></li>
diff --git a/plugins/Sidebar/media/Sidebar.coffee b/plugins/Sidebar/media/Sidebar.coffee
index 74601c1d..e3bc6f0c 100644
--- a/plugins/Sidebar/media/Sidebar.coffee
+++ b/plugins/Sidebar/media/Sidebar.coffee
@@ -358,6 +358,19 @@ class Sidebar extends Class
 			@wrapper.ws.cmd "serverShowdirectory", ["site", @wrapper.site_info.address]
 			return false
 
+		# Copy site with peers
+		@tag.find("#link-copypeers").off("click touchend").on "click touchend", (e) =>
+			copy_text = e.currentTarget.href
+			handler = (e) =>
+				e.clipboardData.setData('text/plain', copy_text)
+				e.preventDefault()
+				@wrapper.notifications.add "copy", "done", "Site address with peers copied to your clipboard", 5000
+				document.removeEventListener('copy', handler, true)
+
+			document.addEventListener('copy', handler, true)
+			document.execCommand('copy')
+			return false
+
 		# Sign and publish content.json
 		$(document).on "click touchend", =>
 			@tag?.find("#button-sign-publish-menu").removeClass("visible")
diff --git a/plugins/Sidebar/media/all.js b/plugins/Sidebar/media/all.js
index 50b1a02f..6e9b85b1 100644
--- a/plugins/Sidebar/media/all.js
+++ b/plugins/Sidebar/media/all.js
@@ -697,6 +697,21 @@ window.initScrollable = function () {
           return false;
         };
       })(this));
+      this.tag.find("#link-copypeers").off("click touchend").on("click touchend", (function(_this) {
+        return function(e) {
+          var copy_text, handler;
+          copy_text = e.currentTarget.href;
+          handler = function(e) {
+            e.clipboardData.setData('text/plain', copy_text);
+            e.preventDefault();
+            _this.wrapper.notifications.add("copy", "done", "Site address with peers copied to your clipboard", 5000);
+            return document.removeEventListener('copy', handler, true);
+          };
+          document.addEventListener('copy', handler, true);
+          document.execCommand('copy');
+          return false;
+        };
+      })(this));
       $(document).on("click touchend", (function(_this) {
         return function() {
           var ref, ref1;