-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
100 lines (100 loc) · 3.08 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
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.global.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/lib/theme-chalk/index.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.full.js"></script>
<title>AdAway-Search</title>
</head>
<body>
<div id="app">
<div v-if="loading">
Loading
</div>
<div v-else>
<div>
<el-select-v2
v-model="value"
filterable
:options="options"
style="width: 100%;"
multiple
@change="pushState"
clearable
/>
</div>
<el-card class="box-card" style="width: 100%;">
<pre><code>{{ hosts }}</code></pre>
</el-card>
<div style="user-select: none;"><a href="https://github.com/jiangtj-lab/AdAway-Search">Source In GitHub</a></div>
</div>
</div>
<script>
const App = {
data() {
return {
loading: true,
list: [],
map: [],
options: [],
value: []
};
},
computed: {
hosts() {
return this.value.map(a => this.map[a]).flat().join("\n");
}
},
created() {
let self =this;
fetch('https://adaway.org/hosts.txt')
.then(function(response) {
return response.text();
})
.then(function(text) {
let data = text.split("# [");
data.shift();
data = data.map(item => {
let arr = item.split("]");
let host = arr[0];
let list = arr[1].split("\n").filter(a => a.length !== 0);
return {host, list};
});
self.list = data;
self.map = self.listToMap(data, key => key.host, val => val.list);
self.options = data.map(a => ({label: a.host, value: a.host}));
return self.map;
})
.then(() => {
self.loading = false;
});
let search = window.location.search;
if (search.startsWith("?search=")) {
this.value = search.substr(8).split("+");
}
},
methods: {
listToMap(list, keyCall, valCall) {
const map = {};
list.forEach(element => {
map[keyCall(element)] = valCall(element);
});
return map;
},
pushState(map) {
let base = window.location.href.split("?")[0];
if (this.value.length === 0) {
window.history.pushState(null, document.title, base);
return;
}
window.history.pushState(null, document.title, `${base}?search=${this.value.join("+")}`);
}
}
};
const app = Vue.createApp(App);
app.use(ElementPlus);
app.mount("#app");
</script>
</body>
</html>