Skip to content

Commit

Permalink
half bake decode logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sonph committed Jun 2, 2024
1 parent 7c1cfca commit 09672fc
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
}, 2000 /* ms */);
}

function encodeAfterLastColon(str) {
function encodeAfterLastColon(str, /* bool */ encode) {
return str.split(";").map(e => {
const parts = e.trim().split(":");
const encodedPart = encodeURIComponent(parts[parts.length - 1])
return parts.slice(0, parts.length - 1).concat([encodedPart]).join(":");
var convertedPart;
if (encode) {
convertedPart = encodeURIComponent(parts[parts.length - 1]);
} else {
convertedPart = decodeURIComponent(parts[parts.length - 1]);
}
return parts.slice(0, parts.length - 1).concat([convertedPart]).join(":");
})
.join(";")
}
Expand Down Expand Up @@ -127,7 +132,7 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h

const measureText = document.getElementById("measureText").value;
if (measureText.length > 0) {
convertedUrl += "&MeasureText=" + encodeAfterLastColon(measureText);
convertedUrl += "&MeasureText=" + encodeAfterLastColon(measureText, true);
}

const convertedUrlElement = document.getElementById("convertedUrl");
Expand All @@ -147,6 +152,20 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
}
}

function parseQuery(str) {
var query = {};
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
return query;
}

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

function openLink() {
const convertedUrl = document.getElementById("convertedUrl").value;
if (convertedUrl.length > 0) {
Expand All @@ -164,6 +183,9 @@ <h3>Tool for converting a GrooveScribe drum notation for embedding in <a href="h
document.getElementById("convertBtn").addEventListener("click", convert);
document.getElementById("copyBtn").addEventListener("click", convertAndCopy);
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);
</script>
</body>

Expand Down

0 comments on commit 09672fc

Please sign in to comment.