diff --git a/analyser.js b/analyser.js index a9b4770..53d5b15 100644 --- a/analyser.js +++ b/analyser.js @@ -11,6 +11,17 @@ var dataDelta = []; ///// MATHS FUNCTIONS ///// +// Next two functions are for timers... ripped from geeksforgeeks.org +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +async function waitAndReset() { + await sleep(2000); + var tooltip = document.getElementById("shareButton"); + tooltip.innerHTML = "Share"; +} + // Calculate Reduction of Area function getReduction(startSize, finalSize) { var startArea = Math.PI * ((startSize / 2) * (startSize / 2)); @@ -569,3 +580,53 @@ function formatCheck(value) { } return value; } + +function createLink() { + // Set our domain to create our link. We will default to the URL hosting the page + var domain = window.location.protocol + "//" + window.location.host + "/"; + + var shareLink = new URL(domain); + + // Create the starting point for the setup manually + var size = document.getElementById("die0").value; + size = formatCheck(size); + + // Check if the metric option is checked and save that + if (i == 1 && document.getElementById("metric").checked == true) { + var isMetric = "true"; + } else { + var isMetric = "false"; + } + + // Add the starting information to the link + shareLink.searchParams.append("die", "0"); + shareLink.searchParams.append("size0", size); + shareLink.searchParams.append("metric", isMetric); + + // Next iterate through all available reductions and add them as well, including their angle + for (var i = 1; i <= numDies; i++) { + var dieNum = "die" + i; + if (!null) + var angleNum = "angle" + i; + size = document.getElementById(dieNum).value; + size = formatCheck(size); + var angle = document.getElementById(angleNum).value; + console.log(dieNum + "=" + size); + console.log(angleNum + "=" + angle); + + shareLink.searchParams.append("die", i); + shareLink.searchParams.append("size" + i, size); + shareLink.searchParams.append("angle" + i, angle); + } + // Display the link to the user... I want to make this prettier some day but this crude solution is GoodEnough™️ + //window.prompt("Your share link: (Note: it has already been copied to your clipboard!)", shareLink.href); + navigator.clipboard.writeText(shareLink.href); + + var tooltip = document.getElementById("shareButton"); + tooltip.innerHTML = "Copied"; + waitAndReset(); +} + +function readLink() { + //TODO +} \ No newline at end of file diff --git a/index.html b/index.html index b771cd8..e6a914e 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,7 @@

+