-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
234 lines (204 loc) · 8.39 KB
/
index.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plover Theory Matcher</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<style>
body {
background: #efefef;
}
.btn-outline-primary {
background: white;
}
.uploader {
max-width: 100%;
width: 700px;
margin: auto;
}
.step {
display: none;
}
.step.active {
display: block;
}
</style>
</head>
<body class="d-flex justify-content-center align-items-center" style="min-height: 100vh;">
<div class="container">
<div class="uploader">
<h1 class="text-center mb-4">Plover JSON Dictionary Matcher</h1>
<p>
This tool helps you identify common entries between two Plover JSON dictionary files. Whether you're merging
dictionaries or looking to find overlapping strokes and definitions between different sources, this matcher
makes it
easy. You can either input a URL to a JSON file or upload the files directly. After identifying the common
entries,
the tool will allow you to download the matched entries as a new JSON file.
</p>
<ol>
<li>First, choose whether to input a URL or upload a JSON file from your device.</li>
<li>If using a URL, paste the link to your JSON file. If uploading, select the first JSON file.</li>
<li>Upload the second JSON file that you want to match against the first.</li>
<li>The tool will compare the two files and find the common entries.</li>
</ol>
<div class="alert alert-primary" role="alert">
<strong>Note:</strong> Only the entries from the second dictionary uploaded in step 3 will be included in the
result.
This means you'll receive a new JSON file containing only the matching entries from the second dictionary, which
overlapped with entries in the first dictionary.
</div>
<!-- Step 1: Choose Method -->
<div id="step1" class="step active">
<h3 class="text-center">Step 1: Choose Your Method</h3>
<div class="d-grid gap-2 mt-3">
<button id="chooseUrlButton" class="btn btn-outline-primary">Use a URL (Raw JSON only)</button>
<button id="chooseFileButton" class="btn btn-outline-primary">Upload a JSON File</button>
</div>
</div>
<!-- Step 2: Enter URL or Upload File -->
<div id="step2-url" class="step">
<h3 class="text-center">Step 2: Enter URL</h3>
<input id="urlInput" class="form-control mb-3" type="text" placeholder="Enter the URL for the JSON file"
required>
<div class="d-grid gap-2 mt-3">
<button id="nextFromUrlButton" class="btn btn-primary">Next</button>
<button id="backToStep1FromUrlButton" class="btn btn-secondary">Back</button>
</div>
</div>
<div id="step2-file" class="step">
<h3 class="text-center">Step 2: Upload JSON File</h3>
<input id="mainFileInput" class="form-control mb-3" type="file" accept=".json" required>
<div class="d-grid gap-2 mt-3">
<button id="nextFromFileButton" class="btn btn-primary">Next</button>
<button id="backToStep1FromFileButton" class="btn btn-secondary">Back</button>
</div>
</div>
<!-- Step 3: Upload File to Match -->
<div id="step3" class="step">
<h3 class="text-center">Step 3: Upload File to Match</h3>
<input id="fileInput" class="form-control mb-3" type="file" accept=".json" required>
<div class="d-grid gap-2 mt-3">
<button id="matchButton" class="btn btn-primary">Match</button>
<button id="backToStep2Button" class="btn btn-secondary">Back</button>
</div>
</div>
<!-- Result Display -->
<div id="result" class="mt-4"></div>
</div>
</div>
<script>
// Step 1: Choose Method
document.getElementById('chooseUrlButton').addEventListener('click', function () {
showStep('step2-url');
});
document.getElementById('chooseFileButton').addEventListener('click', function () {
showStep('step2-file');
});
// Step 2: URL or File
document.getElementById('nextFromUrlButton').addEventListener('click', function () {
const urlInput = document.getElementById('urlInput').value;
if (!urlInput) {
alert('Please enter a URL.');
return;
}
showStep('step3');
});
document.getElementById('nextFromFileButton').addEventListener('click', function () {
const mainFileInput = document.getElementById('mainFileInput').files[0];
if (!mainFileInput) {
alert('Please upload a JSON file.');
return;
}
showStep('step3');
});
document.getElementById('backToStep1FromUrlButton').addEventListener('click', function () {
showStep('step1');
});
document.getElementById('backToStep1FromFileButton').addEventListener('click', function () {
showStep('step1');
});
// Step 3: Back Button
document.getElementById('backToStep2Button').addEventListener('click', function () {
const urlInput = document.getElementById('urlInput').value;
if (urlInput) {
showStep('step2-url');
} else {
showStep('step2-file');
}
});
// Step 3: Match Files
document.getElementById('matchButton').addEventListener('click', function () {
var urlInput = document.getElementById('urlInput').value;
var mainFileInput = document.getElementById('mainFileInput').files[0];
var fileInput = document.getElementById('fileInput').files[0];
if (!fileInput) {
alert('Please select a JSON file to match.');
return;
}
if (urlInput) {
// Fetch JSON from URL
fetch(urlInput)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(mainData => matchFiles(mainData, fileInput))
.catch(error => {
console.error('Error fetching the JSON file:', error);
alert('Error fetching the JSON file. Please ensure the URL is correct and points to a valid JSON file.');
});
} else if (mainFileInput) {
// Read uploaded JSON file
var mainFileReader = new FileReader();
mainFileReader.onload = function () {
var mainData = JSON.parse(mainFileReader.result);
matchFiles(mainData, fileInput);
};
mainFileReader.readAsText(mainFileInput);
}
});
// Function to match files
function matchFiles(mainData, fileInput) {
var fileReader = new FileReader();
fileReader.onload = function () {
var fileData = JSON.parse(fileReader.result);
var uniqueProperties = new Set(Object.values(mainData));
var matchedData = {};
for (var key in fileData) {
var value = fileData[key];
if (uniqueProperties.has(value)) {
matchedData[key] = value;
}
}
var resultDiv = document.getElementById('result');
resultDiv.innerHTML = '';
if (Object.keys(matchedData).length === 0) {
resultDiv.innerHTML = '<div class="alert alert-warning" role="alert">No matches found!</div>';
} else {
var downloadUrl = URL.createObjectURL(new Blob([JSON.stringify(matchedData, null, 2)], { type: 'application/json' }));
resultDiv.innerHTML = '<div class="alert alert-success" role="alert">Matched data found! <a href="' + downloadUrl + '" download="dictionary-matches.json">Download Result</a></div>';
}
};
fileReader.readAsText(fileInput);
}
// Utility function to show a specific step and hide others
function showStep(stepId) {
const steps = document.querySelectorAll('.step');
steps.forEach(step => {
step.classList.remove('active');
if (step.id === stepId) {
step.classList.add('active');
}
});
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>