-
Notifications
You must be signed in to change notification settings - Fork 0
/
pageInfo.js
44 lines (31 loc) · 1.08 KB
/
pageInfo.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
import db from "./db.js";
import utils from "./utils.js";
import injections from "./injectedFunctions.js";
export async function askPageForInfo(tab) {
var results = await chrome.scripting.executeScript({
target: {tabId: tab.id},
func: injections.retrievePageInfo
});
var pageInfo = results[0].result;
return pageInfo;
}
export async function getPageInfo(tab) {
var pageInfo = null;
var normalizedUrl = utils.normalizeURL(tab.url);
let [type, title, currentLanguage] = await askPageForInfo(tab);
utils.debugLog(type, title, currentLanguage);
// check if we have the page info in storage (find by url)
pageInfo = await db.getStoredPage({url: normalizedUrl});
if (!pageInfo) {
if (type != "other") {
// try to find it by title
pageInfo = await db.getStoredPage({title});
pageInfo.url = normalizedUrl;
await db.setStoredPage(pageInfo);
}
}
if (!pageInfo) {
pageInfo = {type, title: {[currentLanguage]: title}, currentLanguage};
}
return pageInfo;
}