-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
382 lines (369 loc) · 12.5 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title id="title">Convert Bookmarks</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="viewport" content="user-scalable=no, width=device-width" />
<meta name="apple-mobile-web-app-title" content="Convert Bookmarks" />
<link rel="stylesheet" href="style.css">
<style type="text/css">
.switch-binary {
-webkit-appearance: none;
appearance: none;
display: inline-block;
/* background-color: #F46053; */
background-color: #CCC;
border-radius: 3px;
font-size: 0.55em;
}
.switch-binary:checked {
background-color: #00FF84;
}
.switch-binary::after {
position: relative;
display: inline-block;
margin: 0.15em 3.15em 0.15em 0.15em;
width: 3em;
height: 1.5em;
background-color: #FFF;
border-radius: 3px;
color: #000;
text-align: center;
line-height: 1.5em;
}
.switch-binary:checked::after {
margin: 0.15em 0.15em 0.15em 3.15em;
}
.no-yes::after {
content: "NO";
}
.no-yes:checked::after {
content: "YES";
}
.off-on::after {
content: "OFF";
}
.off-on:checked::after {
content: "ON";
}
td {
border: 1px solid black;
}
table {
border-collapse: collapse;
}
form {
display: flex;
flex-direction: column;
}
/* content: "↓"; */
</style>
</head>
<body ontouchstart="">
<form>
<fieldset>
<legend>The bookmarks file</legend>
<input type="file" name="fileElem" accept="application/json,.json,.JSON,text/html,.html.HTML,.htm,.HTM" required="" onchange="load_fileInfo(this.files);">
<output>
<!-- FILE METADATA -->
</output>
</fieldset>
<fieldset onchange="parseRequest(this.form);">
<legend>What will be changed</legend>
<input type="hidden" name="sites" value="You don't wanna know why this element has to exist.">
<div><label>Patch all? <input type="checkbox" name="patchAll" class="switch-binary no-yes"></label></div>
<div><label>HTTPS all? <input type="checkbox" name="httpsAll" class="switch-binary no-yes"></label></div>
<table>
<caption>Sites</caption>
<thead>
<tr>
<td>Sitename</td><td>Patch?</td><td>Set all to HTTPS?</td>
</tr>
</thead>
<tbody id="sitesList">
</tbody>
</table>
</fieldset>
<fieldset>
<legend>The result</legend>
<output>
Here be:
File Download
Human explanation
File Info
</output>
</fieldset>
</form>
<fieldset>
<legend>Manual</legend>
If you want to patch the bookmarks of your browser, these are the necessary steps:
<ul>
<li>
<h3>Firefox</h3>
<ol>
<li>Click on the menu bar and select "History", then "Show all history".</li>
<li>In the window which opens, select "Import and Backup", then "Backup".</li>
<li>You are now prompted to save a file named "bookmarks-DATE.json". Save it.</li>
<li>Import this file into this website, choose your patching options and save it.</li>
<li>In Firefox window from before, select "Import and Backup" then "Restore", "Choose File...".</li>
<li>Select the file you got from this website.</li>
<li>Your bookmarks are patched!</li>
</ol>
</li>
<li>
<h3>Chrome</h3>
<p>If you don't want to have your bookmarks duplicated, you have to do the following:</p>
<ol>
<li>
<p>Find your bookmarks file.</p>
<ul>
<li>
<h4>Linux</h4>
<ol>
<li>Go to ~/.config/google-chrome/Default/</li>
<li>Import the "Bookmarks" file into this website.</li>
</ol>
</li>
<li>
<h4>MacOS</h4>
<ol>
<li>Go to ~/.config/google-chrome/Default/</li>
<li>Import the "Bookmarks" file into this website.</li>
</ol>
</li>
<li>
<h4>Windows</h4>
<ol>
<li>Go to ~/.config/google-chrome/Default/</li>
<li>Import the "Bookmarks" file into this website.</li>
</ol>
</li>
</ul>
</li>
</ol>
</li>
</ul>
</fieldset>
</body>
<script type="text/javascript">
let sites = {
"Anilinkz": {
"url": "aniwatcher.com",
"rxp": [
/^https:?\/\/(www\.)?anilinkz\.(to|com|net|tv|io)/i,
/^https:?\/\/(www\.)?aniwatcher\.com/i,
]
},
"Batoto": {
"url": "bato.to"
}
}
let elem_sitesList = document.getElementById("sitesList");
var bookmarksBackupX;
for (let siteName in sites) {
let row = document.createElement("tr");
let cell_sitename = document.createElement("td");
cell_sitename.setAttribute("scope", "row");
cell_sitename.innerText = siteName;
row.appendChild(cell_sitename);
let cell_patch = document.createElement("td");
let input_patch = document.createElement("input");
input_patch.type = "checkbox";
input_patch.name = "sites";
input_patch.value = siteName;
input_patch.className = "switch-binary no-yes";
cell_patch.appendChild(input_patch);
row.appendChild(cell_patch);
let cell_https = document.createElement("td");
let input_https = document.createElement("input");
input_https.type = "checkbox";
input_https.name = "force_https";
input_https.value = 1;
input_https.className = "switch-binary no-yes";
cell_https.appendChild(input_https);
row.appendChild(cell_https);
elem_sitesList.appendChild(row);
}
function load_fileInfo(files) {
/*
file.name;
file.type;//should display web browser bookmarks file type too
file.lastModified;
*/
for (let i = 0, file; file = files[i]; i++) {
switch (file.type) {
case "application/json":
var reader = new FileReader();
reader.onload = function(event) {
var bookmarksBackup = JSON.parse(event.target.result);
var bookmarksBackup_updated = replaceJSONBookmarks(bookmarksBackup, sites, elem_form.sites, elem_form.useHTTPS.checked);
var bookmarksBackup_updated_encoded = encodeURIComponent(JSON.stringify(bookmarksBackup_updated));
var downloadElement = document.createElement("a");
downloadElement.setAttribute("href", "data:application/json;charset=utf-8,"+bookmarksBackup_updated_encoded);
var newFileName = file.name;
if (newFileName.endsWith(".json")) {
newFileName = newFileName.slice(0, -5);
}
newFileName += "_patched.json";
downloadElement.setAttribute("download", newFileName);
downloadElement.style.display = "none";
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
}
reader.readAsText(file);
break;
case "text/html":
var reader = new FileReader();
reader.onload = function(event) {
var parser = new DOMParser();
var bookmarksBackup = parser.parseFromString(event.target.result, "text/html");
var bookmarksBackup_updated = replaceHTMLBookmarks(bookmarksBackup, sites, elem_form.sites, elem_form.useHTTPS.checked);
var XMLS = new XMLSerializer();
var bookmarksBackup_updated_encoded = encodeURIComponent(XMLS.serializeToString(bookmarksBackup_updated));
var downloadElement = document.createElement("a");
downloadElement.setAttribute("href", "data:application/json;charset=utf-8,"+bookmarksBackup_updated_encoded);
var newFileName = file.name;
if (newFileName.endsWith(".html")) {
newFileName = newFileName.slice(0, -5);
} else if (newFileName.endsWith(".htm")) {
newFileName = newFileName.slice(0, -4);
}
newFileName += "_patched.html";
downloadElement.setAttribute("download", newFileName);
downloadElement.style.display = "none";
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
}
reader.readAsText(file);
break;
}
}
}
function parseRequest(elem_form) {
var files = elem_form.fileElem.files;
for (let i = 0, file; file = files[i]; i++) {
switch (file.type) {
case "application/json":
var reader = new FileReader();
reader.onload = function(event) {
var bookmarksBackup = JSON.parse(event.target.result);
var bookmarksBackup_updated = replaceJSONBookmarks(bookmarksBackup, sites, elem_form.sites, elem_form.useHTTPS.checked);
var bookmarksBackup_updated_encoded = encodeURIComponent(JSON.stringify(bookmarksBackup_updated));
var downloadElement = document.createElement("a");
downloadElement.setAttribute("href", "data:application/json;charset=utf-8,"+bookmarksBackup_updated_encoded);
var newFileName = file.name;
if (newFileName.endsWith(".json")) {
newFileName = newFileName.slice(0, -5);
}
newFileName += "_patched.json";
downloadElement.setAttribute("download", newFileName);
downloadElement.style.display = "none";
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
}
reader.readAsText(file);
break;
case "text/html":
var reader = new FileReader();
reader.onload = function(event) {
var parser = new DOMParser();
var bookmarksBackup = parser.parseFromString(event.target.result, "text/html");
var bookmarksBackup_updated = replaceHTMLBookmarks(bookmarksBackup, sites, elem_form.sites, elem_form.useHTTPS.checked);
var XMLS = new XMLSerializer();
var bookmarksBackup_updated_encoded = encodeURIComponent(XMLS.serializeToString(bookmarksBackup_updated));
var downloadElement = document.createElement("a");
downloadElement.setAttribute("href", "data:application/json;charset=utf-8,"+bookmarksBackup_updated_encoded);
var newFileName = file.name;
if (newFileName.endsWith(".html")) {
newFileName = newFileName.slice(0, -5);
} else if (newFileName.endsWith(".htm")) {
newFileName = newFileName.slice(0, -4);
}
newFileName += "_patched.html";
downloadElement.setAttribute("download", newFileName);
downloadElement.style.display = "none";
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
}
reader.readAsText(file);
break;
}
}
return false;
}
function replaceJSONBookmarks(container, sitesData, siteCheckboxes, useHTTPS=true) {
if (container.constructor.name == "Object") {
if ("type" in container && container["type"]=="text/x-moz-place") {
if ("uri" in container) {
var url = container["uri"];
siteCheckboxes.forEach(function(siteCheckbox){
let siteID = siteCheckbox.value;
if (siteCheckbox.checked && siteID in sitesData) {
sitesData[siteID]["rxp"].forEach(function(siteRegex){
var siteRegex_match = siteRegex.exec(url);
if (siteRegex_match) {
if (useHTTPS) {
var protocol = "https://";
} else {
var protocol = "http://";
}
container["uri"] = protocol+sitesData[siteID]["url"]+url.slice(siteRegex_match[0].length);
/*
if should change title
match title
patch title
*/
}
})
}
})
}
}
if ("children" in container) {
container["children"].forEach(function(elem, i){
container["children"][i] = replaceJSONBookmarks(elem, sitesData, siteCheckboxes, useHTTPS);
})
}
}
return container;
}
function replaceHTMLBookmarks(container, sitesData, siteCheckboxes, useHTTPS=true) {
if (container.constructor.name == "HTMLAnchorElement") {
if ("href" in container) {
var url = container.href;
siteCheckboxes.forEach(function(siteCheckbox){
let siteID = siteCheckbox.value;
if (siteCheckbox.checked && siteID in sitesData) {
sitesData[siteID]["rxp"].forEach(function(siteRegex){
var siteRegex_match = siteRegex.exec(url);
if (siteRegex_match) {
if (useHTTPS) {
var protocol = "https://";
} else {
var protocol = "http://";
}
container.href = protocol+sitesData[siteID]["url"]+url.slice(siteRegex_match[0].length);
/*
if should change title
match title
patch title
*/
}
})
}
})
}
}
for (let i = 0, elem; elem = container.children[i]; i++) {
container.children[i] = replaceHTMLBookmarks(elem, sitesData, siteCheckboxes, useHTTPS);
}
return container;
}
</script>
</html>