2023-05-15 20:52:07 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link rel="stylesheet" href="../../css/spectre.min.css">
|
|
|
|
<link rel="stylesheet" href="../../css/spectre-exp.min.css">
|
|
|
|
<link rel="stylesheet" href="../../css/spectre-icons.min.css">
|
|
|
|
<style>
|
|
|
|
.badgeerror[data-badge]::after { background-color: red; }
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2023-05-18 20:19:27 +00:00
|
|
|
<h1>Upload tracks to your watch</h1>
|
|
|
|
<p>Allows uploading a GPX format track file to your watch. Converts tracks containing "trkpt"-nodes into the GPS Trekking format.</p>
|
2023-05-21 07:07:52 +00:00
|
|
|
<input class="form-input" type="file" id="fileSelector"><br/>
|
|
|
|
<label class="form-label" for="fileName">Filename on watch (must end with .trf an be shorter than 28 characters total)</label>
|
|
|
|
<input class="form-input" placeholder="route.trf" id="fileName" pattern="^.{0,24}\.trf$"><br/>
|
|
|
|
<button class="btn btn-primary" type="button" id="upload">Upload</button><br/>
|
2023-05-15 20:52:07 +00:00
|
|
|
</div>
|
|
|
|
<script src="../../core/lib/interface.js"></script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var options;
|
|
|
|
|
2023-05-21 07:07:52 +00:00
|
|
|
let converted;
|
|
|
|
|
2023-05-15 20:52:07 +00:00
|
|
|
document.getElementById('fileSelector').addEventListener('change', event => {
|
|
|
|
const file = document.getElementById('fileSelector').files[0];
|
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.readAsText(file,'UTF-8');
|
|
|
|
|
|
|
|
// here we tell the reader what to do when it's done reading...
|
|
|
|
reader.onload = readerEvent => {
|
|
|
|
var content = readerEvent.target.result; // this is the content!
|
|
|
|
console.log( content );
|
|
|
|
|
|
|
|
const xsltProcessor = new XSLTProcessor();
|
|
|
|
|
|
|
|
// Load the xsl file using synchronous (third param is set to false) XMLHttpRequest
|
|
|
|
const myXMLHTTPRequest = new XMLHttpRequest();
|
|
|
|
myXMLHTTPRequest.open("GET", "convert.xsl", false);
|
|
|
|
myXMLHTTPRequest.send(null);
|
|
|
|
|
|
|
|
const xslRef = myXMLHTTPRequest.responseXML;
|
|
|
|
|
|
|
|
// Finally import the .xsl
|
|
|
|
xsltProcessor.importStylesheet(xslRef);
|
|
|
|
|
|
|
|
const parser = new DOMParser();
|
|
|
|
console.log(file.text);
|
|
|
|
const doc = parser.parseFromString(content, "text/xml");
|
|
|
|
|
|
|
|
console.log(doc);
|
|
|
|
|
|
|
|
const fragment = xsltProcessor.transformToFragment(doc, document);
|
|
|
|
|
2023-05-21 07:07:52 +00:00
|
|
|
let serializer = new XMLSerializer();
|
|
|
|
converted = serializer.serializeToString(fragment);
|
|
|
|
console.log("Fragment", converted);
|
2023-05-15 20:52:07 +00:00
|
|
|
|
|
|
|
let filename = file.name.replaceAll(".gpx",".trf");
|
|
|
|
console.log("New file name", filename);
|
|
|
|
|
2023-05-21 07:07:52 +00:00
|
|
|
if (document.getElementById('fileName').value == ""){
|
|
|
|
document.getElementById('fileName').value = filename;
|
|
|
|
}
|
2023-05-15 20:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-05-21 07:07:52 +00:00
|
|
|
document.getElementById('upload').addEventListener('click', event => {
|
|
|
|
Util.showModal("Saving...");
|
|
|
|
Util.writeStorage(document.getElementById('fileName').value, converted, function() {
|
|
|
|
Util.hideModal();
|
|
|
|
});
|
|
|
|
});
|
2023-05-15 20:52:07 +00:00
|
|
|
function onInit() {
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|