forked from wkgg/chrome-history-analyze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
50 lines (42 loc) · 1.36 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
'use strict';
function getCurrentTabUrl(callback) {
var queryInfo = {
active: true,
currentWindow: true
};
chrome.tabs.query(queryInfo, function(tabs) {
var tab = tabs[0];
var url = tab.url;
getVisitedTimes(url, function(times){
renderVisitedTimes(times);
});
callback(url);
});
}
function getVisitedTimes(url, callback) {
var domain = new URI(url).domain();
chrome.history.search({text:domain, startTime:1 ,maxResults:1000000}, function(results){
var filteredResults = results.filter(result => new URI(result.url).domain() == domain)
if(filteredResults.length > 1){
renderLastVisited(filteredResults[1].lastVisitTime);
}
callback(filteredResults.length);
});
}
function renderLastVisited(epochTime) {
var timeAgo = moment(epochTime).fromNow();
document.getElementById('lastVisited').innerHTML = "<span class='title'>Last Visited: </span>" + timeAgo;
}
function renderUrl(currentUrl) {
document.getElementById('url').textContent = currentUrl;
}
function renderVisitedTimes(visitedTimes) {
document.getElementById('visitedTimes').innerHTML = "<span class='title'>Visited Times: </span>" + visitedTimes;
}
document.addEventListener('DOMContentLoaded', function() {
getCurrentTabUrl(function(url) {
if(url.length > 35)
url = url.substr(0, 34) + "..."
renderUrl('Current Url: ' + url);
});
});