From 15d82b6267a6854cfd72c4e31242520e2faede0d Mon Sep 17 00:00:00 2001 From: UnicodingUnicorn <7555ic@gmail.com> Date: Thu, 6 Aug 2020 15:46:47 +0800 Subject: [PATCH] Select engine in querystring (#18) * initial commit * Added pull from remote url and from querystring * Should resolve #15. Check querystring for 'engine' and act accordingly. * Remove debugging logging Co-authored-by: Daniel Lim Co-authored-by: Dreampuf --- index.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.html b/index.html index 5db5fd2..8fbeec4 100644 --- a/index.html +++ b/index.html @@ -438,9 +438,29 @@ rawEl.addEventListener("change", renderGraph); share.addEventListener("click", copyShareURL); + // Since apparently HTMLCollection does not implement the oh so convenient array functions + HTMLOptionsCollection.prototype.indexOf = function(name) { + for (let i = 0; i < this.length; i++) { + if (this[i].value == name) { + return i; + } + } + + return -1; + }; /* come from sharing */ const params = new URLSearchParams(location.search.substring(1)); + if (params.has('engine')) { + const engine = params.get('engine'); + const index = engineEl.options.indexOf(engine); + if (index > -1) { // if index exists + engineEl.selectedIndex = index; + } else { + show_error({ message: `invalid engine ${engine} selected` }); + } + } + if (params.has('raw')) { editor.getSession().setValue(params.get('raw')); renderGraph();