其實歷史記錄的不只是有標題、網址而已,
事實上還能取得瀏覽次數、最後瀏覽的時間.
manifest.json
{
"manifest_version": 2,
"name": "ironman6",
"version": "1.0",
"browser_action": {
"default_popup": "index.html"
},
"permissions": [
"history"
]
}
index.html
<title>ironman6</title>
<style>body {width: 500px;}</style>
<div id="content"></div>
<script src="app.js"></script>
app.js
chrome.history.search({text: ''}, function(HistoryItem) {
var content = document.querySelector('#content');
var output = [];
for (var i = 0; i < HistoryItem.length; i++) {
var item = HistoryItem[i];
var url = item.url;
var title = item.title;
var visit = item.visitCount;
// item.lastVisitTime;
output.push('<ul><a href="' + url + '">' + title + '</a>( ' + visit + ' )</ul>');
}
content.innerHTML = output.join('');
});