Skip to content

Commit

Permalink
Adding copy button for sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
roeming committed Oct 30, 2024
1 parent a057aee commit c9c3062
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ <h1>
<link rel="stylesheet" href="index.css"/>
<script src="index.js"></script>
<input id="inp" size="50" type="text"></input>
<input id="copyBtn" type="button" value="Copy Link"></input>
<p id="copyBtn_confirm"></p>
<br>
<br>
<div id="inputFields" class="down_container"></div>
<div id="inputFields" class="down_container">Copy Link</div>
<br>
<br>

Expand Down
25 changes: 12 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
Expand Down

0 comments on commit c9c3062

Please sign in to comment.