forked from wkgg/chrome-history-analyze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history-chart.js
64 lines (61 loc) · 1.84 KB
/
history-chart.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
'use strict';
function renderData(data){
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "",
fontFamily: "Verdana",
fontColor: "Peru",
fontSize: 20
},
height: 180,
animationEnabled: true,
axisY: {
tickThickness: 0,
lineThickness: 0,
valueFormatString: " ",
gridThickness: 0,
},
axisX: {
tickThickness: 0,
lineThickness: 0,
labelFontSize: 18,
labelFontColor: "#515151"
},
backgroundColor: "#ffffff",
data: [
{
indexLabelFontSize: 10,
toolTipContent: "<span style='\"'font-size: 20px; color:peru '\"'><strong>{y} times</strong></span>",
indexLabelPlacement: "outside",
indexLabelFontColor: "#515151",
indexLabelFontWeight: 200,
indexLabelFontSize: 13,
indexLabelFontFamily: "Verdana",
color: "#2eb7d0",
type: "bar",
dataPoints: data
},
]
});
chart.render();
}
window.onload = function () {
let historyData = [];
chrome.history.search({text:"", startTime:1 ,maxResults:1000000}, function(results){
var domainMap = new Map();
for(let result of results) {
var domain = new URI(result.url).domain();
if(domainMap.has(domain)){
domainMap.set(domain, domainMap.get(domain) + 1);
}
else {
domainMap.set(domain, 1);
}
}
var sortedDomainMap = [...domainMap.entries()].sort((a,b) => a[1] < b[1] ? 1 : a[1] > b[1] ? -1 : 0)
for(let i = 4; i >= 0; --i){
historyData.push({y: sortedDomainMap[i][1], label: sortedDomainMap[i][0], indexLabel: sortedDomainMap[i][1].toString()});
}
renderData(historyData);
});
}