-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Util page for converting URLS from mikeslessons
- Loading branch information
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Embedded Groove</title> | ||
<style> | ||
input#url, | ||
input#convertedUrl { | ||
width: 80% | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div> | ||
<form> | ||
<label for="url">URL:</label> | ||
<input type="text" id="url" name="url"><br><br> | ||
<label for="showTempo">Show Tempo</label> | ||
<input type="checkbox" id="showTempo" name="showTempo"><br><br> | ||
<label for="convertedUrl">Converted URL:</label> | ||
<input readonly type="text" id="convertedUrl" name="convertedUrl"><br><br> | ||
<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> | ||
</form> | ||
</div> | ||
<div></div> | ||
<div> | ||
<span id="status"></span> | ||
</div> | ||
|
||
<script> | ||
function convertAndCopyOnEnter(event) { | ||
if (event.key === "Enter") { | ||
convertAndCopy(); | ||
} | ||
} | ||
|
||
function setStatus(status) { | ||
const statusE = document.getElementById("status"); | ||
statusE.innerHTML = "<b>" + status + "</b>"; | ||
setTimeout(function () { | ||
statusE.innerHTML = ""; | ||
}, 2000 /* ms */); | ||
} | ||
|
||
function convert() { | ||
const url = document.getElementById("url").value; | ||
if (url.length == 0) { | ||
setStatus("URL is empty!"); | ||
return; | ||
} | ||
|
||
const showTempo = document.getElementById("showTempo").checked; | ||
const regex = /(https:\/\/)?(www\.)?(mikeslessons\.com|montulli\.github\.io)\/(groove\/|GrooveScribe\/)/; | ||
var convertedUrl = | ||
url.replace(regex, "https://sonpham.me/notion-drum-sheet/"); | ||
if (showTempo) { | ||
convertedUrl = convertedUrl + "&EmbedTempoTimeSig=true"; | ||
} | ||
|
||
const convertedUrlElement = document.getElementById("convertedUrl"); | ||
convertedUrlElement.value = convertedUrl; | ||
convertedUrlElement.select(); | ||
|
||
setStatus("Converted!"); | ||
} | ||
|
||
function convertAndCopy() { | ||
convert(); | ||
const convertedUrlElement = document.getElementById("convertedUrl"); | ||
if (convertedUrlElement.value.length > 0) { | ||
navigator.clipboard.writeText(convertedUrlElement.value); | ||
setStatus("Copied!"); | ||
return; | ||
} | ||
} | ||
|
||
function openLink() { | ||
const convertedUrl = document.getElementById("convertedUrl").value; | ||
if (convertedUrl.length > 0) { | ||
window.open(convertedUrl, '_blank'); | ||
} | ||
} | ||
|
||
// Convert and copy on "Enter". Also select on click. | ||
document.getElementById("url").addEventListener("keypress", convertAndCopyOnEnter); | ||
document.getElementById("url").addEventListener("click", function() { | ||
const url = document.getElementById("url").select(); | ||
}); | ||
document.getElementById("showTempo").addEventListener("keypress", convertAndCopyOnEnter); | ||
|
||
document.getElementById("convertBtn").addEventListener("click", convert); | ||
document.getElementById("copyBtn").addEventListener("click", convertAndCopy); | ||
document.getElementById("openLink").addEventListener("click", openLink); | ||
</script> | ||
</body> | ||
|
||
</html> |