Skip to content

Commit

Permalink
sorta decode converted url logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sonph committed Jun 2, 2024
1 parent 09672fc commit ee353d4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
<button type="button" id="convertBtn">Convert</button>
<button type="button" id="copyBtn">Convert & copy to clipboard</button>
<button type="button" id="openLink">Open link</button>
<br><br>
<button type="button" id="decodeUrlBtn">Decode converted URL</button>
</form>
</div>
<div></div>
Expand Down Expand Up @@ -152,7 +154,7 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
}
}

function parseQuery(str) {
function parseQuery(queryString) {
var query = {};
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
for (var i = 0; i < pairs.length; i++) {
Expand All @@ -162,8 +164,19 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
return query;
}

function decodeUrl() {
const query = parseQuery(window.location.search);
var dbg = {};

function decodeConvertedUrl() {
console.log("decoding");
const convertedUrl = document.getElementById("convertedUrl").value;
const query = parseQuery(convertedUrl.split("?")[1]);
dbg.query = query;
document.getElementById("showTempo").checked = (query.EmbedTempoTimeSig || "") === "true";
document.getElementById("subText").value = decodeURIComponent(query.subText || "");
document.getElementById("repeatBegins").value = query.RepeatBegins || "";
document.getElementById("repeatEnds").value = query.RepeatEnds || "";
document.getElementById("repeatEndings").value = query.RepeatEndings || "";
document.getElementById("measureText").value = encodeAfterLastColon(query.MeasureText || "", false);
}

function openLink() {
Expand All @@ -185,7 +198,7 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
document.getElementById("openLink").addEventListener("click", openLink);

// Decode URL to allow for easy modification of groove without having to re-type all the custom fields
// document.getElementById("convertedUrl").addEventListener("onchange", decodeUrl);
document.getElementById("decodeUrlBtn").addEventListener("click", decodeConvertedUrl);
</script>
</body>

Expand Down

0 comments on commit ee353d4

Please sign in to comment.