From c9c3062262773a5a968984e79288da911b2df109 Mon Sep 17 00:00:00 2001 From: roeming Date: Wed, 30 Oct 2024 17:38:56 -0400 Subject: [PATCH] Adding copy button for sharing --- index.html | 4 +++- index.js | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index 4d6e2bd..9900240 100644 --- a/index.html +++ b/index.html @@ -15,9 +15,11 @@

+ +



-
+
Copy Link


diff --git a/index.js b/index.js index 692a3fe..89fa254 100644 --- a/index.js +++ b/index.js @@ -1022,19 +1022,10 @@ function drawGraph(v) var graphCanvas; -function GetURLParameter(sParam) +function GetURLParameter() { - var sPageURL = window.location.search.substring(1); - var sURLVariables = sPageURL.split('&'); - for (var i = 0; i < sURLVariables.length; i++) - { - var sParameterName = sURLVariables[i].split('='); - if (sParameterName[0] == sParam) - { - return sParameterName[1]; - } - } - return undefined; + let url = new URL(window.location); + return url.searchParams.get("seq"); } function equationChanged() @@ -1052,8 +1043,16 @@ document.addEventListener('DOMContentLoaded', function (event) { graphCanvas = document.getElementById("graphOutput"); inputElement.addEventListener("input", equationChanged); + document.getElementById("copyBtn").addEventListener("click", ()=>{ + let url = new URL([location.protocol, '//', location.host, location.pathname].join("")); + url.searchParams.append("seq", inputElement.value); + // console.log(url); + navigator.clipboard.writeText(url); + document.getElementById("copyBtn_confirm").innerHTML = "copied!" + }); + let urlParams = GetURLParameter("seq"); - if (urlParams !== undefined) + if (urlParams !== null) { inputElement.defaultValue = urlParams; equationChanged();