-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathscripts.js
More file actions
71 lines (55 loc) · 2.06 KB
/
Copy pathscripts.js
File metadata and controls
71 lines (55 loc) · 2.06 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
function download() {
var folderName = document.getElementById("folder-name").value;
var bookmarkUrls = document.getElementById("bookmark-urls").value.split("\n");
var bookmarkNames = document.getElementById("bookmark-names").value.split("\n");
var output = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>`
// Only add Folder to output if folder name specified
if (folderName != "") {
output = output.concat( `
<DT><H3>${folderName}</H3>
<DL><p>`)
}
for (var i = 0; i < bookmarkUrls.length; i++) {
// Skip blank lines
if (bookmarkUrls[i] == "") {
continue;
}
// Default bookmark name to url string if name not specified
if (bookmarkNames[i] == "" || typeof bookmarkNames[i] == 'undefined') {
bookmarkNames[i] = bookmarkUrls[i];
}
// Add individual bookmark to output
var bookmark = `
<DT><A HREF="${bookmarkUrls[i]}">${bookmarkNames[i]}</A>`
output = output.concat(bookmark)
}
// Only close folder tag if folder name specified
if (folderName != "") {
output = output.concat( `
</DL><p>`)
}
// Close final tag
output = output.concat( `
</DL><p>`);
// Build downloadable .html file with content from output variable
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(output));
element.setAttribute('download', "bookmarks.html");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
gtag('event', 'Download Clicked');
}
document.getElementById("bookmark-urls").placeholder = `https://github.com/
https://stackoverflow.com/
https://www.reddit.com/
`;
document.getElementById("bookmark-names").placeholder = `GitHub
Stack Overflow
Reddit
`;