-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathindex.js
34 lines (29 loc) · 980 Bytes
/
index.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
export function isStoredInternally(page) {
return !!(page._attachments && page._attachments['frozen-page.html'])
}
export function isStoredInDownloads(page) {
return !!(page.download && page.download.exists)
}
export function isSnapshotAvailable(page) {
return isStoredInternally(page) || isStoredInDownloads(page)
}
export function urlForSnapshot(page) {
const url = urlForInternallyStoredPage(page) || urlForDownloadedPage(page)
return url
}
export function urlForInternallyStoredPage(page) {
if (!isStoredInternally(page)) {
return undefined
}
const pageId = page._id
const url = `/local-page.html?page=${pageId}`
const hash = (page.url && page.url.split('#')[1])
const href = (hash !== undefined) ? url + '#' + hash : url
return browser.runtime.getURL(href)
}
function urlForDownloadedPage(page) {
if (!isStoredInDownloads(page)) {
return undefined
}
return `file://${page.download.filename}`
}