This repository has been archived by the owner on Nov 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsettings.html
98 lines (87 loc) · 3.15 KB
/
settings.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
{% extends 'templates/base.html' %}
{% set title = "ftools" %}
{% block content %}
{% raw %}
<section class="container mt-3">
<div id="app">
<div class="alert alert-success my-3" role="alert" v-show="showMessage">
Settings saved!
</div>
<div class="row">
<div class="col-md-6 mx-auto">
<div class="card">
<div class="card-header">
<h2>Settings</h2>
</div>
<div class="card-body">
<form>
<div class="form-group">
<label for="targetWikiField">Default Target Wiki</label>
<input class="form-control" type="text" id="targetWikiField" placeholder="ex: en.wikipedia.org" v-bind:class="{ 'is-invalid': targetWikiInvalid }" v-model.trim="targetWiki">
<div class="invalid-feedback">
Not a supported Wiki
</div>
</div>
<input type="button" value="Save Settings" class="btn btn-primary" v-on:click.prevent="save">
<input type="button" value="Restore Defaults" class="btn btn-secondary ml-2" v-on:click.prevent="restoreDefaults">
</form>
</div>
</div>
</div>
</div>
</div>
</section>
{% endraw %}
{% endblock%}
{% block scripts %}
{% include 'templates/lib-axios.html' %}
{% raw %}
<script type="module">
import JSWiki from "/jswiki.js";
import { defaultTargetWiki } from "/utils.js";
Vue.createApp({
data() {
return {
targetWiki: "",
allWikis: null,
targetWikiInvalid: false,
settingsUnsupported: false,
showMessage: false
}
},
created() {
try {
const ts = "__test__";
window.localStorage.setItem(ts, ts);
window.localStorage.removeItem(ts);
new JSWiki().siteMatrix().then(result => this.allWikis = result);
this.targetWiki = defaultTargetWiki();
}
catch (e) {
console.log(e);
this.settingsUnsupported = true;
}
},
methods: {
save() {
if (!this.targetWiki)
return;
this.targetWikiInvalid = false;
this.showMessage = false;
this.targetWiki = this.targetWiki.toLowerCase();
if (this.allWikis.has(this.targetWiki)) {
window.localStorage.setItem("targetWiki", this.targetWiki);
this.showMessage = true;
}
else
this.targetWikiInvalid = true;
},
restoreDefaults() {
window.localStorage.clear();
this.targetWiki = defaultTargetWiki();
}
}
}).mount("#app");
</script>
{% endraw %}
{% endblock %}