-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (64 loc) · 2.25 KB
/
script.js
File metadata and controls
64 lines (64 loc) · 2.25 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
const showTime = () => {
const hours = new Date().getHours().toString().padStart(2,0);
const minutes = new Date().getMinutes().toString().padStart(2,0);
$('#clock').html(`${hours}:${minutes}`); // 21:04
}
const showBookmarkModal = () => {
$('.ui.mini.modal')
.modal({
closable : true,
onApprove : function() {
const $form = $('.content form'),
bookmark = $form.form('get values');
bookmark.parentId = '2';
const id = bookmark.id;
delete bookmark.id;
if (id) {
chrome.bookmarks.update(id, { title: bookmark.title, url: bookmark.url }, (response) => {
listBookmarks();
});
} else {
chrome.bookmarks.create(bookmark, (response) => {
listBookmarks();
});
}
}
})
.modal('show');
};
const listBookmarks = () => {
chrome.bookmarks.getChildren('2', (bms) => {
let uiBms = '';
bms.forEach(bm => {
uiBms += `<div class="item">
<i class="large middle aligned icon"><img src="chrome://favicon/${bm.url}"></i>
<div class="content">
<a class="header inline" href="${bm.url}" target="_blank">${bm.title} <span class="ui primary mini label">${bm.url}</span></a>
</div>
<i class="aligned small edit outline icon secondary middle" bId="${bm.id}" id="editBm" style="color:#ddd"></i>
<i class="aligned small trash icon secondary middle" bId="${bm.id}" id="editBm" style="color:#ddd"></i>
</div>`;
});
$('#bmList').html(uiBms);
})
}
$(document).ready(function(){
showTime();
listBookmarks();
setInterval(showTime, 1000);
$("#addBookmark").click(() => {
$('.content form')
.form('set values', {title: '', url: '', id: ''});
showBookmarkModal();
});
$(document).on('click','#editBm',function(event){
const element = event.target;
const id = element.getAttribute('bid');
chrome.bookmarks.get(id, (bm) => {
console.log(bm[0])
$('.content form')
.form('set values', bm[0]);
showBookmarkModal();
})
});
});