-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathexport.html
More file actions
122 lines (116 loc) · 4.08 KB
/
export.html
File metadata and controls
122 lines (116 loc) · 4.08 KB
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
---
layout: inner
title: AdAway - Import and Export
description: Convert between legacy hosts file format and AdAway's modern JSON format for easy migration of your ad-blocking rules.
---
<h1 class="center pt-2 pb-2">Import & Export Host Lists</h1>
<div class="export-section">
<label for="legacyExportTextArea" class="export-label">Legacy Format (hosts file)</label>
<textarea placeholder="Paste your legacy hosts file here (e.g., 127.0.0.1 example.com)" id="legacyExportTextArea" aria-describedby="legacyHelp" spellcheck="false"></textarea>
<p id="legacyHelp" class="export-help">Each line should be in format: <code>127.0.0.1 hostname</code> or <code>0.0.0.0 hostname</code> for blocked, <code>white hostname</code> for allowed</p>
<button type="button" class="button-submit mb-3" onclick="convertToModern()"><i class="fas fa-arrow-down mr-1" aria-hidden="true"></i> Convert to Modern JSON</button>
</div>
<div class="export-section">
<label for="modernExportTextArea" class="export-label">Modern Format (JSON)</label>
<textarea placeholder="Paste your AdAway JSON export here" id="modernExportTextArea" aria-describedby="modernHelp" spellcheck="false"></textarea>
<p id="modernHelp" class="export-help">AdAway's modern JSON format with blocked, allowed, and redirected arrays</p>
<button type="button" class="button-submit" onclick="convertToLegacy()"><i class="fas fa-arrow-up mr-1" aria-hidden="true"></i> Convert to Legacy</button>
</div>
<script>
const legacyExport = document.getElementById("legacyExportTextArea");
const modernExport = document.getElementById("modernExportTextArea");
const redirectedPattern = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\s+([^\s]+)$/;
function convertToLegacy() {
try {
const text = modernExport.value.trim();
if (!text) {
alert("Please enter a modern JSON export first.");
return;
}
const modern = JSON.parse(text);
let legacy = "";
// Convert blocked hosts
if (modern.blocked) {
for (const blocked of modern.blocked) {
if (blocked && blocked.host && blocked.enabled) {
legacy += "127.0.0.1 " + blocked.host + "\n";
}
}
}
// Convert allowed hosts
if (modern.allowed) {
for (const allowed of modern.allowed) {
if (allowed.host && allowed.enabled) {
legacy += "white " + allowed.host + "\n";
}
}
}
// Convert redirected hosts
if (modern.redirected) {
for (const redirected of modern.redirected) {
if (redirected.host && redirected.redirect && redirected.enabled) {
legacy += redirected.redirect + " " + redirected.host + "\n";
}
}
}
legacyExport.value = legacy;
} catch (e) {
alert("Invalid JSON format. Please check your input.");
}
}
function convertToModern() {
const modern = {
sources: [],
blocked: [],
allowed: [],
redirected: []
};
const text = legacyExport.value.trim();
if (!text) {
alert("Please enter a legacy hosts list first.");
return;
}
const lines = text.split('\n');
for (let line of lines) {
// Remove comments
const commentStart = line.indexOf('#');
if (commentStart !== -1) {
line = line.substring(0, commentStart);
}
// Clean up line
line = line.trim();
if (line.length === 0) {
continue;
}
// Test blocked hosts (127.0.0.1 or 0.0.0.0)
if (line.startsWith("127.0.0.1 ") || line.startsWith("0.0.0.0 ")) {
const host = line.split(/\s+/)[1];
if (host) {
modern.blocked.push({
host: host,
enabled: true
});
}
}
// Test allowed hosts
else if (line.startsWith("white ")) {
modern.allowed.push({
host: line.substring(6).trim(),
enabled: true
});
}
// Test redirected domains
else {
const match = line.match(redirectedPattern);
if (match && match.length > 5) {
modern.redirected.push({
host: match[5],
redirect: match[1] + '.' + match[2] + '.' + match[3] + '.' + match[4],
enabled: true
});
}
}
}
modernExport.value = JSON.stringify(modern, null, ' ');
}
</script>