1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Event listner for clicks on links in a browser action popup. 6 // Open the link in a new tab of the current window. 7 function onAnchorClick(event) { 8 chrome.tabs.create({ 9 selected: true, 10 url: event.srcElement.href 11 }); 12 return false; 13 } 14 15 // Given an array of URLs, build a DOM list of those URLs in the 16 // browser action popup. 17 function buildPopupDom(divName, data) { 18 var popupDiv = document.getElementById(divName); 19 20 var ul = document.createElement('ul'); 21 popupDiv.appendChild(ul); 22 23 for (var i = 0, ie = data.length; i < ie; ++i) { 24 var a = document.createElement('a'); 25 a.href = data[i].url; 26 a.appendChild(document.createTextNode(data[i].title)); 27 a.addEventListener('click', onAnchorClick); 28 29 var li = document.createElement('li'); 30 li.appendChild(a); 31 32 ul.appendChild(li); 33 } 34 } 35 36 // Search history to find up to ten links that a user has visited during the 37 // current time of the day +/- 1 hour. 38 function buildTypedUrlList(divName) { 39 var millisecondsPerHour = 1000 * 60 * 60; 40 var maxResults = 10; 41 42 chrome.experimental.history.getMostVisited({ 43 'filterWidth' : millisecondsPerHour, 44 'maxResults' : maxResults 45 }, 46 function(historyItems) { 47 buildPopupDom(divName, historyItems); 48 } 49 ); 50 } 51 52 document.addEventListener('DOMContentLoaded', function () { 53 buildTypedUrlList("filteredUrl_div"); 54 });