我正在考虑首次开发Google Chrome扩展程序;没有以前的经验。我想到的扩展必须能够查看用户的浏览历史记录,并提供他们访问某个网站或该网站内任何子目录的最早实例的URL。
例如,用户的浏览历史记录可以是:
8:58 - http://mysite.com/page/page1.html
8:59 - http://mysite.com/test/index.php
9:00 - http://google.com
9:01 - http://google.com/?q=mysite
9:03 - http://mysite.com/this/info.html
9:04 - http://mysite.com/this/info2.html
9:05 - http://mysite.com/this/info3.html
9:06 - http://facebook.com
在这种情况下,假设该应用正在查找访问http://mysite.com或任何子目录的实例。 (这将在扩展代码本身中指定;它不是由用户设置的。)扩展程序将查找最近访问http://mysite.com的“组”,在这种情况下:
9:03 - http://mysite.com/this/info.html
9:04 - http://mysite.com/this/info2.html
9:05 - http://mysite.com/this/info3.html
从这个组中,它将选择最早的条目,并显示该URL,在这种情况下是:
9:03 - http://mysite.com/this/info.html
一直在查看Google有关使用扩展程序历史记录的文档(http://developer.chrome.com/extensions/history.html),但我不认为我正在寻找的是该文档页面。 ..
想知道是否有人能给我一个正确的方向?
谢谢!
答案 0 :(得分:1)
此处列出了您的扩展程序可用的任何历史记录功能: http://developer.chrome.com/extensions/history.html
如果不是,您将无法访问它们。 Chrome扩展程序没有未记录的历史记录API。
你可能想做这样的事情:
var siteToSearch = 'facebook.com';
chrome.history.search({text: siteToSearch, callback: function(results) {
//Iterate through the `results` array of `HistoryItem` objects
//Look for lowest value of `lastVisitTime` OR call `chrome.history.getVisits` with
//`results[i].url` and then check the returned `VisitItem` for the `visitTime` property
}})
您可能希望使用正则表达式将要搜索的网站的网址与浏览器历史记录中的结果进行匹配。
答案 1 :(得分:1)
Google 似乎将文档移至 this link
并且可以通过以下方式使用旧答案中包含的代码段:
const siteToSearch = 'facebook.com';
chrome.history.search({text: siteToSearch}, callback: function(results) {
//Iterate through the `results` array of `HistoryItem` objects
//Look for lowest value of `lastVisitTime` OR call `chrome.history.getVisits` with
//`results[i].url` and then check the returned `VisitItem` for the `visitTime` property
}})