forked from interplanaria/bottle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmark.html
121 lines (121 loc) · 2.5 KB
/
bookmark.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
<html>
<head>
<style>
body {
margin: 0;
font-family: arial;
}
.container {
width: 800px;
margin: 0 auto;
}
.container input[type=text]:focus {
outline: none;
}
.container input[type=text] {
width: 100%;
box-sizing: border-box;
padding: 10px;
margin: 5px 0;
}
.form {
padding: 50px;
background: rgba(0,0,0,0.03);
}
h2 {
margin: 0;
}
button {
background: gold;
padding: 10px 50px;
color: black;
border-radius: 2px;
border: none;
}
.rows {
margin-top: 20px;
}
.row {
padding: 10px;
}
.row:nth-child(odd) {
background: white;
}
.row:nth-child(even) {
background: whitesmoke;
}
.row .name {
font-weight: bold;
font-size: 14px;
}
.row a.url {
color: rgba(0,0,0,0.8);
font-size: 12px;
}
.row .description {
font-size: 12px;
}
</style>
<script>
const fs = require('fs');
const path = require('path');
const {remote} = require('electron');
const dirname = remote.app.getAppPath();
const userPath = remote.app.getPath("userData");
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
var p = path.join(userPath, '.', 'bookmark.json');
var items = [];
var read = function() {
fs.readFile(p, function(err, data) {
if(data){
try {
items = JSON.parse(data);
if (items && Array.isArray(items) && items.length > 0) {
let d = items.map(function(item) {
return `<div class='row'>
<div class='name'>${item.name}</div>
<a target='_blank' class='url' href='${item.url}'>${item.url}</a>
</div>`
}).join("");
document.querySelector(".rows").innerHTML = d;
}
} catch (e) {
console.log("Error", e);
}
}
})
};
document.addEventListener("DOMContentLoaded", function(e) {
if (vars && vars.url) {
document.querySelector("#url").value = vars.url;
}
document.querySelector("button#save").addEventListener("click", function(e) {
let o = {
name: document.querySelector("#name").value,
url: document.querySelector("#url").value,
};
items.push(o);
fs.writeFile(p, JSON.stringify(items, null, 2), function(err, data) {
read();
});
})
read();
})
</script>
</head>
<body>
<div class='container'>
<div class='form'>
<h2>Bookmark</h2>
<input id='url' type='text' placeholder='enter url'>
<input id='name' type='text' placeholder='enter name'>
<button id='save' value='save'>Save</button>
</div>
<div class='rows'>
</div>
</div>
</body>
</html>