-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
60 lines (53 loc) · 1.5 KB
/
popup.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
function getCurrentTabUrl(callback) {
var queryInfo = {
active: true,
currentWindow: true
};
chrome.tabs.query(queryInfo, (tabs) => {
var url = tabs[0].url;
if (url.indexOf('wikipedia.org') > -1) {
callback(url);
}
});
}
document.addEventListener('DOMContentLoaded', () => {
var $container = $("#container");
chrome.storage.local.clear();
$container.html("");
getCurrentTabUrl((url) => {
function checkResult(r) {
if (r.url.indexOf("wikipedia.org") >= 20) { return false }
if (r.url.indexOf("wikipedia.org") <= -1) { return false }
if (r.url == url) { return false }
if (r.url == "https://en.wikipedia.org/wiki/Main_Page") { return false }
return true;
}
function updateResults(results) {
var html = "";
results.pages.forEach((p) => {
html = html + "<div><a href='" + p.url + "'>" + p.title + "</a></div>";
});
$container.html(html);
}
var query = {
text: "wikipedia"
};
chrome.history.search(query, (results) => {
var filtered = results.filter(checkResult);
var articles = filtered.map(r => {
return r.url.split("/")[4];
}).filter((u) => {
return u;
}).join(",");
$.getJSON("http://localhost:8080/multigraph/" + articles, (results) => {
updateResults(results);
});
});
});
$(document).on("click", "#container a", function() {
console.log(this.target);
chrome.tabs.update({
url: this.href
});
});
});