哪个过渡类型获得所有的chrome浏览历史记录
Which transition type gets all the chrome browsing history?
我正在创建一个扩展来获取我的chrome浏览器的所有浏览历史。所有的工作都很好,但这里有一个小问题,我想检索所有的浏览历史记录,如"chrome://history/"。我无法找回所有的历史。谁能告诉我哪种过渡类型可以获得所有的浏览历史记录?提前谢谢。
下面是我的一小部分代码:
function onAnchorClick(event) {
chrome.tabs.create({
selected: true,
url: event.srcElement.href
});
return false;
}
// Given an array of URLs, build a DOM list of those URLs in the
// browser action popup.
function buildPopupDom(divName, data) {
var popupDiv = document.getElementById(divName);
var ul = document.createElement('ul');
popupDiv.appendChild(ul);
for (var i = 0, ie = data.length; i < ie; ++i) {
var a = document.createElement('a');
a.href = data[i];
a.appendChild(document.createTextNode(data[i]));
a.addEventListener('click', onAnchorClick);
var li = document.createElement('li');
li.appendChild(a);
ul.appendChild(li);
}
}
// Search history to find up to ten links that a user has typed in,
// and show those links in a popup.
function buildTypedUrlList(divName) {
// To look for history items visited in the last week,
// subtract a week of microseconds from the current time.
var microsecondsPerWeek = 1000 * 60 * 60 * 24 * 7;
var oneWeekAgo = (new Date).getTime() - microsecondsPerWeek;
// Track the number of callbacks from chrome.history.getVisits()
// that we expect to get. When it reaches zero, we have all results.
var numRequestsOutstanding = 0;
chrome.history.search({
'text': '', // Return every history item....
'startTime': oneWeekAgo // that was accessed less than one week ago.
},
function(historyItems) {
// For each history item, get details on all visits.
for (var i = 0; i < historyItems.length; ++i) {
var url = historyItems[i].url;
var processVisitsWithUrl = function(url) {
// We need the url of the visited item to process the visit.
// Use a closure to bind the url into the callback's args.
return function(visitItems) {
processVisits(url, visitItems);
};
};
chrome.history.getVisits({url: url}, processVisitsWithUrl(url));
numRequestsOutstanding++;
}
if (!numRequestsOutstanding) {
onAllVisitsProcessed();
}
});
// Maps URLs to a count of the number of times the user typed that URL into
// the omnibox.
var urlToCount = {};
// Callback for chrome.history.getVisits(). Counts the number of
// times a user visited a URL by typing the address.
var processVisits = function(url, visitItems) {
for (var i = 0, ie = visitItems.length; i < ie; ++i) {
// Ignore items unless the user typed the URL.
if (visitItems[i].transition != 'typed') {
//continue;
}
if (!urlToCount[url]) {
urlToCount[url] = 0;
}
urlToCount[url]++;
}
// If this is the final outstanding call to processVisits(),
// then we have the final results. Use them to build the list
// of URLs to show in the popup.
if (!--numRequestsOutstanding) {
onAllVisitsProcessed();
}
};
// This function is called when we have the final list of URls to display.
var onAllVisitsProcessed = function() {
// Get the top scorring urls.
urlArray = [];
for (var url in urlToCount) {
urlArray.push(url);
}
//根据用户输入的次数对url进行排序。urlArray。Sort(函数(a, b) {返回urlToCount[b] - urlToCount[a];});
buildPopupDom(divName, urlArray.slice(0, 2000));
};
}
document.addEventListener('DOMContentLoaded', function () {
buildTypedUrlList("typedUrl_div");
});
根据您在评论中的回复,假设您想获得从chrome://history
开始的所有历史记录,您可以使用chrome.history.search
:
chrome.history.search({text: "", maxResults: 10000}, function(results) {
var ans = results.filter(function(result) {
return result.startsWith("chrome://history");
});
});
相关文章:
- Chrome WebKitGetUserMedia
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- 在chrome.tabs.onCreated之后加载HTML页面
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- chrome扩展更改主机/域警告
- Chrome开发工具(如何知道我在调用哪个javascript对象)
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- Google/html5语音识别JavaScript SDK Chrome网络工具包SpeechRecognition
- 激活chrome上的chrome.notifications对象
- 如何从Google Chrome浏览器中打开浏览窗口
- 使用chrome扩展程序在后台自动进行条件浏览
- Chrome浏览器无法进行文件浏览
- 如何在Chrome扩展中使用历史API获得浏览历史记录
- Chrome扩展是否有可能获得用户的完整浏览历史记录?
- 你的浏览记录在谷歌Chrome扩展
- Chrome和Firefox文件上传浏览错误
- 哪个过渡类型获得所有的chrome浏览历史记录