-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmarks.js
135 lines (109 loc) · 4.04 KB
/
bookmarks.js
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
const fs = require('fs')
const path = require('path')
const { decryptFile, chromeDtToDate } = require('./utilities.js')
// TODO: import from bookmarks.html or from database, copy code from jupyter_ops
const HOMEPATH = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
function findBookmarksFile() {
let workingPaths = []
let settingsPath
if (os.platform == 'win32') {
settingsPath = path.join(HOMEPATH, 'AppData\/LocalStorage')
} else {
if (os.platform == 'darwin') {
settingsPath = path.join(HOMEPATH, 'Library\/Application\ Support')
} else {
settingsPath = path.join(HOMEPATH, '.config')
}
}
//workingPaths.push(path.join(settingsPath, 'BraveSoftware\/Brave-Browser\/Default\/Bookmarks'))
workingPaths.push(path.join(settingsPath, 'Google\/Chrome\/Default/Bookmarks'))
for (let i = 0; i < workingPaths.length; i++) {
if (fs.existsSync(workingPaths[i])) {
return workingPaths[i]
}
}
}
function decryptBookmarks() {
const bookmarksFile = findBookmarksFile()
const bookmarksData = fs.readFileSync(bookmarksFile).toString('utf-8')
let decryptedBookmarks
if (bookmarksData[0] == '{') {
decryptedBookmarks = bookmarksData
} else {
decryptedBookmarks = decryptFile(bookmarksData)
}
return decryptedBookmarks
}
function parseBookmarks() {
let decryptedBookmarks = JSON.parse(decryptBookmarks()).roots
let root = decryptedBookmarks.bookmark_bar.children
//console.log(decryptedBookmarks)
//if(root.length == 0) {
root = root.concat(decryptedBookmarks.other.children)
//}
// from this verified structure, list newest additions
let bookmarks = root.reduce((function recursiveGroup(root, list, book) {
let folder = root
if(folder.includes('Other Bookmarks')) {
folder = ''
}
if(book.type == 'folder') {
folder += (folder && folder.length > 0 ? '/' : '') + book.name
book.children.forEach(recursiveGroup.bind(null, folder, list))
} else {
book.folder = folder
book.time_usec = parseInt(book.date_added + '')
book.date = chromeDtToDate(book.time_usec)
list.push(book)
}
return list
}).bind(null, ''), [])
return bookmarks
}
// TODO: make an html page out of categories
function listBookmarks() {
let bookmarks = parseBookmarks()
let recentlyAdded = bookmarks.sort((a, b) => b.date - a.date).filter((a, i) => i < 100)
//.filter(book => book.date.getTime() > Date.now() - 96 * 60 * 60 * 1000)
let bookmarkFolders = recentlyAdded.map(book => book.folder).filter((f, i, arr) => arr.indexOf(f) == i)
// TODO: a little bit of read-time estimation it looks like a factor of images + words / reading speed
// SOURCE: https://www.startpage.com/do/search?q=how+long+does+it+take+to+read+an+article+github
// 200 words per minute average
// ^^^ road-block because of PDF integration
// TODO: cache page to PDF like my bookmark downloader, wkhtml2pdf should be good enough
// search existing bookmark collections of PDFs to reduce work
// TODO: display HTML boxes with percent of workday spent reading other people's research,
// versus implementation from github logging
let html = `
<ol class="categories">
${bookmarkFolders.map(folder => {
let category
if (path.dirname(folder) == '.') {
category = `<li><a href="#${path.basename(folder)}">
<label for="cat-${path.basename(folder)}">
${path.basename(folder)}</a></label></li>`
} else {
category = `<li><a href="#${path.basename(folder)}">
<label for="cat-${path.basename(folder)}">
${path.basename(path.dirname(folder))}/${path.basename(folder)}</a></label></li>`
}
return category
}).join('\n')}
</ol>
${bookmarkFolders.map((folder, i) => {
return `
<input type="radio" id="cat-${path.basename(folder)}" name="category" value="${i}" />
<ol class="bookmarks">
${recentlyAdded.filter(book => book.folder == folder).map(book => {
return `<li><a href="${book.url}">${book.name}</a></li>`
}).join('\n')}
</ol>
`}).join('\n')}`
// next level share-point with employee monitoring integration?
// ABCs of programming
return html
}
// TODO: commit to a seperate branch using GitHub Actions CI
module.exports = {
listBookmarks
}