-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCcodeTitleDate.html
140 lines (120 loc) · 3.68 KB
/
GCcodeTitleDate.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html><head>
<title>Convert GPX to list of GC code,name, and optional date found</title>
<meta charset="utf-8">
<body>
<h3>Convert GPX to list of GC codes, names, optional date found. Use MyFinds PQ for input.</h3>
<input type="file" id="files" name="file">
<br>
<br>
User: <input id="user"value="rragan"> Show Date?: <input id="showdate" type="checkbox" checked> <br>
<textarea id="list" rows="20" cols="80"></textarea>
<br>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.9.1/jszip.min.js"></script>
<script>
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
var output = [];
var error = [];
var who;
var showdate;
// Closure to capture the file information.
function handleZipFile(f) {
getZipFilesContent(f).then(dd => {
processXML(dd);
}).catch(e => {
console.log(e);
});
}
async function getZipFilesContent(data) {
const zipContent = [];
const promises = [];
const zip = (await JSZip.loadAsync(data));
zip.forEach(async (relativePath, file) => {
const promise = file.async('string');
promises.push(promise);
zipContent.push({
file: relativePath,
content: await promise
});
});
await Promise.all(promises);
return zipContent[0].content;
}
function processXML(dd) {
var re = /<name>(GC[A-Z0-9]*)<\/name>/g;
var re2 = /<groundspeak:name>(.*)<\/groundspeak.name>/g;
var re3 = /<groundspeak:date>(.+?)<\/groundspeak.date>/;
var re4 = /<groundspeak:type>(.+?)<\/groundspeak.type>/;
var re5 = /<groundspeak:finder .*>(.*)<\/groundspeak.finder>/;
// By lines
var lines = dd.split('\n');
var line = '';
var date = 0;
var foundit = 0;
for (var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace(/\'/g, '\'');
var m1 = re.exec(lines[i]);
var m2 = re2.exec(lines[i]);
var m3 = re3.exec(lines[i]);
var m4 = re4.exec(lines[i]);
var m5 = re5.exec(lines[i]);
if (m1 !== null) { //get GC code
line = m1[1];
m1 = null;
}
if (m2 !== null) { // get title
line += " " + m2[1];
m2 = null;
}
if (m3 !== null) { // get Date
var timeparts = m3[1].split('T');
date = " " + timeparts[0];
}
if (m4 !== null && m4[1] === 'Found it') { // look for Found it line
foundit = 1;
m4 = null;
}
if (m5 !== null && foundit === 1 && m5[1] === who) { // only handle my Found it line
if (showdate) {
line += date;
}
output.push(line + "\n");
line = '';
foundit = 0;
}
if (m5 !== null && foundit === 1 && m5[1] !== who) {
foundit = 0;
}
m5 = null;
}
updateView(output);
}
function updateView() {
var outarea = document.getElementById('list');
outarea.value = output.join(' '),
outarea.setSelectionRange(0, 99999);
}
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
who = document.getElementById('user').value;
showdate = document.getElementById('showdate').checked;
if (files[0].name.endsWith(".zip")) {
handleZipFile(files[0]);
} else {
var reader = new FileReader();
reader.onload = function(evt) {
processXML(this.result);
};
reader.readAsText(files[0]);
}
}
$(document).ready(function(){
document.getElementById('files').addEventListener('change', handleFileSelect, false);
});
</script>
</body></html>