Skip to content

Commit

Permalink
Add buttons to save and load the custom server list
Browse files Browse the repository at this point in the history
  • Loading branch information
softins committed May 18, 2024
1 parent 098700a commit 826b8b8
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@
<td colspan=2><input type="text" size=3 maxLength=5 placeholder="Port" v-model="single.port"></td>
<td><button :disabled="single.desc == '' || single.name == ''" @click="addServer('server', options.single, single)">Add</button></td>
</tr>
<tr><td colspan=5><hr></td></tr>
<tr>
<td colspan=5 class="centre">
<button @click="saveTextToFile">Save to file</button>
<label for="loadfile" class="loadfile">
<button type="button" @click="clickParent">Load from file</button>
<input type="file" accept="application/json" name="loadfile" id="loadfile" @change="loadTextFromFile" @click="resetFile">
</label>
</td>
</tr>
<tr><td colspan=5><hr></td></tr>
</tbody>
</table>
</modal>
Expand Down Expand Up @@ -506,6 +517,43 @@ export default {
}
list.splice(index,1);
localStorage.setItem(kind, JSON.stringify(list));
},
saveTextToFile() {
var data = {
directory: this.options.extra,
single: this.options.single
}
var file = new Blob([JSON.stringify(data)], {type: 'application/json;charset=utf-8'});
var anchor = document.createElement('a');
anchor.href = URL.createObjectURL(file);
anchor.download = 'explorer.json';
anchor.click();
URL.revokeObjectURL(anchor.href);
},
resetFile(e) {
e.target.value = '';
},
loadTextFromFile(e) {
var f = e.target.files;
var reader = new FileReader();
var options = this.options;
reader.onloadend = function() {
var data = JSON.parse(reader.result);
if (data.directory) {
options.extra = data.directory;
localStorage.setItem('directory', JSON.stringify(options.extra));
}
if (data.single) {
options.single = data.single;
localStorage.setItem('server', JSON.stringify(options.single));
}
}
reader.readAsText(f[0]);
},
clickParent(e) {
e.target.parentNode.click();
}
}
}
Expand All @@ -525,6 +573,11 @@ export default {
.click {
cursor: pointer;
}
.centre {
text-align: center;
}
.left {
text-align: left;
}
Expand Down Expand Up @@ -649,4 +702,11 @@ button.arrow {
.copyright a:hover {
text-decoration: underline;
}
label.loadfile input {
opacity: 0;
width: 0.1px;
height: 0.1px;
position: absolute;
}
</style>

0 comments on commit 826b8b8

Please sign in to comment.