BangleApps/apps/gpstrek/interface.html

85 lines
2.9 KiB
HTML
Raw Normal View History

<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>
<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>
<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/>
</div>
<script src="../../core/lib/interface.js"></script>
<script>
var options;
let converted;
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);
let serializer = new XMLSerializer();
converted = serializer.serializeToString(fragment);
console.log("Fragment", converted);
let filename = file.name.replaceAll(".gpx",".trf");
console.log("New file name", filename);
if (document.getElementById('fileName').value == ""){
document.getElementById('fileName').value = filename;
}
}
});
document.getElementById('upload').addEventListener('click', event => {
Util.showModal("Saving...");
Util.writeStorage(document.getElementById('fileName').value, converted, function() {
Util.hideModal();
});
});
function onInit() {
}
</script>
</body>
</html>