[DocServer] Updated Top Sites Sample Extension.

BUG=299634
NOTRY=true

Review URL: https://codereview.chromium.org/25389003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226483 0039d316-1c4b-4281-b951-d872f2087c98
parent 73c9a7fb
<!DOCTYPE HTML>
<html>
<head>
<title>Most popular urls that you used during this hour in the last two months.</title>
<style>
body {min-width: 250px;}
</style>
<script src='historyFilterUrls.js'></script>
</head>
<body>
<h2>Most used urls:</h2>
<div id="filteredUrl_div"></div>
</body>
</html>
\ No newline at end of file
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Event listner for clicks on links in a browser action popup.
// Open the link in a new tab of the current window.
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].url;
a.appendChild(document.createTextNode(data[i].title));
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 visited during the
// current time of the day +/- 1 hour.
function buildTypedUrlList(divName) {
var millisecondsPerHour = 1000 * 60 * 60;
var maxResults = 10;
chrome.experimental.history.getMostVisited({
'filterWidth' : millisecondsPerHour,
'maxResults' : maxResults
},
function(historyItems) {
buildPopupDom(divName, historyItems);
}
);
}
document.addEventListener('DOMContentLoaded', function () {
buildTypedUrlList("filteredUrl_div");
});
\ No newline at end of file
{
"name": "Time filter for History",
"version": "1.1",
"description": "Reads your history, and shows top pages you visited in the time +/-1 hour in the last two months",
"permissions": ["experimental"],
"browser_action": {
"default_popup": "historyFilterUrls.html",
"default_icon": "clock.png"
},
"manifest_version": 2
}
\ No newline at end of file
{
"name": "Top Sites",
"version": "1.2",
"description": "Shows the top sites in a browser action",
"permissions": ["topSites"],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"manifest_version": 2
}
<!DOCTYPE HTML>
<html>
<body>
<h2>Most Visited:</h2>
<div id='mostVisited_div'></div>
<script src='popup.js'></script>
</body>
</html>
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Event listener for clicks on links in a browser action popup.
// Open the link in a new tab of the current window.
function onAnchorClick(event) {
chrome.tabs.create({ url: event.srcElement.href });
return false;
}
// Given an array of URLs, build a DOM list of these URLs in the
// browser action popup.
function buildPopupDom(mostVisitedURLs) {
var popupDiv = document.getElementById('mostVisited_div');
var ol = popupDiv.appendChild(document.createElement('ol'));
for (var i = 0; i < mostVisitedURLs.length; i++) {
var li = ol.appendChild(document.createElement('li'));
var a = li.appendChild(document.createElement('a'));
a.href = mostVisitedURLs[i].url;
a.appendChild(document.createTextNode(mostVisitedURLs[i].title));
a.addEventListener('click', onAnchorClick);
}
}
chrome.topSites.get(buildPopupDom);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment