ret += "sample q;\n";
}
}
-
}
if (ProgramTrack.STATE[0].length == 0)
{
ret = "qreg q[" + (ProgramTrack.STATE.length - 1) + "];\n";
ret += "sample q;\n";
}
+
+ if (!ret.includes("Duplicate") && !ret.includes("Incomplete"))
+ {
+ if (localStorage.getItem("hvar") != null)
+ {
+ if (!isNaN(parseFloat(localStorage.getItem("hvar"))))
+ {
+ ret = "hvar " + localStorage.getItem("hvar") + ";\n" + ret;
+ }
+ }
+ if (localStorage.getItem("noise") != null)
+ {
+ if (!isNaN(parseFloat(localStorage.getItem("noise"))))
+ {
+ if (parseFloat(localStorage.getItem("noise")) != 0)
+ {
+ ret = "noise " + localStorage.getItem("noise") + ";\n" + ret;
+ }
+ }
+ }
+ }
return ret;
},
drag: (e, erase, evt, dodrag) =>
window.onload = function()
{
+ if (localStorage.getItem("noise") == null)
+ localStorage.setItem("noise", 0);
+ if (localStorage.getItem("hvar") == null)
+ localStorage.setItem("hvar", "");
ProgramTrack.draw();
//$(".program-track")[0].parentNode.style.height = Math.round($(".program-instr")[0].getBoundingClientRect().height) + "px";
$(".program-track")[0].parentNode.style.width = "100%";
var apikey = localStorage.getItem("apikey");
apikey = (apikey ? apikey : "").replace("'", "").replace("\"", "").replace("\n", "");
$(".modal__container")[0].style.width = "500px";
- $("#modal-main-title")[0].innerHTML = "API Settings";
- $("#modal-main-content")[0].innerHTML = "<p>Please enter your API key: </p><input type='text' id='apikey' />";
+ $("#modal-main-title")[0].innerHTML = "Settings";
+ $("#modal-main-content")[0].innerHTML = `
+ <p>API key: </p><input type='text' id='apikey' />
+ <br />
+ <p>Noise: <p/><input type='number' id='noise' step='0.01' />
+ <br />
+ <p>Hidden variable: <p/><input type='number' id='hvar' step='0.01' />
+ `;
$("#apikey")[0].style.width = "100%";
+ $("#noise")[0].style.width = "100%";
+ $("#hvar")[0].style.width = "100%";
$("#apikey")[0].addEventListener("click", () =>
{
$("#apikey")[0].selectionStart = 0;
$("#apikey")[0].selectionEnd = $("#apikey")[0].value.length;
});
- $("#apikey")[0].addEventListener("keydown", e =>
+ $("#apikey")[0].addEventListener("keydown", e => { if (e.key == "Enter") { $("#modal-main-confirm")[0].click(); } })
+ $("#noise")[0].addEventListener("keydown", e => { if (e.key == "Enter") { $("#modal-main-confirm")[0].click(); } });
+ $("#hvar")[0].addEventListener("keydown", e => { if (e.key == "Enter") { $("#modal-main-confirm")[0].click(); } });
+ var noiseChange = () =>
{
- if (e.key == "Enter")
- {
- $("#modal-main-confirm")[0].click();
- }
- });
+ var v = parseFloat($("#noise")[0].value);
+ if (isNaN(v)) v = 0;
+ if (v < 0) v = 0;
+ if (v > 100) v = 100;
+ $("#noise")[0].value = v;
+ };
+ var hvarChange = () =>
+ {
+ var v = parseFloat($("#hvar")[0].value);
+ if (isNaN(v)) v = "";
+ $("#hvar")[0].value = v;
+ }
+ var changeEvents = ["change", "keydown", "keyup", "mouseenter", "mouseleave"];
+ for (var i = 0; i < changeEvents.length; i++)
+ {
+ $("#noise")[0].addEventListener(changeEvents[i], e => { noiseChange(); });
+ $("#hvar")[0].addEventListener(changeEvents[i], e => { hvarChange(); });
+ }
$("#apikey")[0].value = apikey;
+ $("#noise")[0].value = localStorage.getItem("noise");
+ $("#hvar")[0].value = localStorage.getItem("hvar");
$("#modal-main-confirm")[0].style.display = "";
$("#modal-main-cancel")[0].style.display = "";
- $("#modal-main-confirm")[0].setAttribute("onclick", "localStorage.setItem('apikey', $('#modal-main-content input')[0].value); closeModal();");
+ $("#modal-main-confirm")[0].setAttribute("onclick",
+ `
+ localStorage.setItem('apikey', $('#apikey')[0].value);
+ localStorage.setItem('noise', $('#noise')[0].value);
+ localStorage.setItem('hvar', $('#hvar')[0].value);
+ closeModal();
+ ProgramTrack.draw();
+ `);
MicroModal.show("modal-main");
- $("#apikey")[0].focus();
- $("#apikey")[0].selectionStart = 0;
- $("#apikey")[0].selectionEnd = $("#apikey")[0].value.length;
break;
case "save":
if (ProgramTrack.STATE[0].length == 0)