From 6f589fedcc826b125884e3a5884c9791802afb7f Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Sat, 21 Jan 2012 00:23:59 +0100 Subject: add fuzzy mode --- background_page.html | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index d8d3f75b..bca446a6 100644 --- a/background_page.html +++ b/background_page.html @@ -26,7 +26,9 @@ returnScrollPosition: handleReturnScrollPosition, getCurrentTabUrl: getCurrentTabUrl, settings: handleSettings, - getBookmarks: getBookmarks + getBookmarks: getBookmarks, + getAllBookmarks: getAllBookmarks, + getHistory: getHistory, }; var sendRequestHandlers = { @@ -276,6 +278,57 @@ }) } + function getAllBookmarks(args, port) { + function traverseTree(bookmarks, callback) { + for (var i = 0; i < bookmarks.length; ++i) { + callback(bookmarks[i]); + if (typeof bookmarks[i].children === "undefined") + continue; + traverseTree(bookmarks[i].children, callback); + } + }; + + chrome.bookmarks.getTree(function(bookmarks) { + var results = []; + traverseTree(bookmarks, function(bookmark) { + if (typeof bookmark.url === "undefined") + return; + results.push(bookmark); + }); + port.postMessage({bookmarks:results}); + }); + }; + + function getHistory(args, port) { + chrome.history.search({ text: '', + maxResults: args.maxResults || 1000 }, + function(history) { + // sort by visit cound descending + history.sort(function(a, b) { + // visitCount may be undefined + var visitCountForA = a.visitCount || 0; + var visitCountForB = a.visitCount || 0; + return visitCountForB - visitCountForA; + }); + var results = []; + for (var i = 0; i < history.length; ++i) { + results.push(history[i]); + } + port.postMessage({history:results}); + }); + }; + + /* + * Used by everyone to get settings from local storage. + */ + function getSettingFromLocalStorage(setting) { + if (localStorage[setting] != "" && !localStorage[setting]) { + return defaultSettings[setting]; + } else { + return localStorage[setting]; + } + } + function getCurrentTimeInSeconds() { Math.floor((new Date()).getTime() / 1000); } chrome.tabs.onSelectionChanged.addListener(function(tabId, selectionInfo) { -- cgit v1.2.3 From 3520212b6ef4945b96fc061ecfe7c198195e1ee4 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Sat, 21 Jan 2012 15:44:13 +0100 Subject: move some logic from background to content page --- background_page.html | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index bca446a6..97017fad 100644 --- a/background_page.html +++ b/background_page.html @@ -291,8 +291,6 @@ chrome.bookmarks.getTree(function(bookmarks) { var results = []; traverseTree(bookmarks, function(bookmark) { - if (typeof bookmark.url === "undefined") - return; results.push(bookmark); }); port.postMessage({bookmarks:results}); @@ -302,19 +300,8 @@ function getHistory(args, port) { chrome.history.search({ text: '', maxResults: args.maxResults || 1000 }, - function(history) { - // sort by visit cound descending - history.sort(function(a, b) { - // visitCount may be undefined - var visitCountForA = a.visitCount || 0; - var visitCountForB = a.visitCount || 0; - return visitCountForB - visitCountForA; - }); - var results = []; - for (var i = 0; i < history.length; ++i) { - results.push(history[i]); - } - port.postMessage({history:results}); + function(history) { + port.postMessage({history:history}); }); }; -- cgit v1.2.3 From 53f8158919d8b916818c54c6a9e4bf12d28df0f0 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Sat, 21 Jan 2012 16:27:42 +0100 Subject: add tab completion support --- background_page.html | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 97017fad..0f86e3ce 100644 --- a/background_page.html +++ b/background_page.html @@ -29,6 +29,7 @@ getBookmarks: getBookmarks, getAllBookmarks: getAllBookmarks, getHistory: getHistory, + getTabsInCurrentWindow: getTabsInCurrentWindow, }; var sendRequestHandlers = { @@ -43,7 +44,8 @@ updateScrollPosition: handleUpdateScrollPosition, copyToClipboard: copyToClipboard, isEnabledForUrl: isEnabledForUrl, - saveHelpDialogSettings: saveHelpDialogSettings + saveHelpDialogSettings: saveHelpDialogSettings, + selectSpecificTab: selectSpecificTab, }; // Event handlers @@ -259,6 +261,14 @@ Clipboard.copy(request.data); } + /** + * Selects the tab with the ID specified in request.id + */ + function selectSpecificTab(request) { + console.log("selectSpecificTab"); + chrome.tabs.update(request.id, { selected: true }); + } + /* * Used by the content scripts to get settings from the local storage. */ @@ -305,6 +315,12 @@ }); }; + function getTabsInCurrentWindow(args, port) { + chrome.tabs.getAllInWindow(null, function(tabs) { + port.postMessage({tabs:tabs}); + }); + }; + /* * Used by everyone to get settings from local storage. */ -- cgit v1.2.3 From 76b26a8a25522300b9e6e463e75397693fa2bb53 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Sun, 22 Jan 2012 13:46:17 +0100 Subject: really get more history items --- background_page.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 0f86e3ce..c065333d 100644 --- a/background_page.html +++ b/background_page.html @@ -308,9 +308,11 @@ }; function getHistory(args, port) { - chrome.history.search({ text: '', - maxResults: args.maxResults || 1000 }, - function(history) { + chrome.history.search({ + text: '', + maxResults: args.maxResults || 1000, + startTime: 0, + }, function(history) { port.postMessage({history:history}); }); }; -- cgit v1.2.3 From 516101bf1350cd77cd71423a2cbdf639f33dfd85 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Sun, 22 Jan 2012 13:48:26 +0100 Subject: remove debug statement --- background_page.html | 1 - 1 file changed, 1 deletion(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index c065333d..641fea1f 100644 --- a/background_page.html +++ b/background_page.html @@ -265,7 +265,6 @@ * Selects the tab with the ID specified in request.id */ function selectSpecificTab(request) { - console.log("selectSpecificTab"); chrome.tabs.update(request.id, { selected: true }); } -- cgit v1.2.3 From 6bc1d44939c9b4557ef8648a6e645e73caaa0623 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Mon, 23 Jan 2012 22:29:13 +0100 Subject: improve perfmance by caching history results in the background page. Also decrease the number of included results slightly. --- background_page.html | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 641fea1f..99c7d430 100644 --- a/background_page.html +++ b/background_page.html @@ -75,6 +75,8 @@ if (portHandlers[port.name]) port.onMessage.addListener(portHandlers[port.name]); + // prefetch history + useHistory(function() {}); }); chrome.extension.onRequest.addListener(function (request, sender, sendResponse) { @@ -306,13 +308,38 @@ }); }; - function getHistory(args, port) { + var cachedHistory = null; + function useHistory(callback) { + if (cachedHistory !== null) { + callback(cachedHistory); + return; + } + chrome.history.search({ text: '', - maxResults: args.maxResults || 1000, + maxResults: 20000, startTime: 0, }, function(history) { - port.postMessage({history:history}); + // sorting in asceding order, so we can push new items to the end later + history.sort(function(a, b) { + // visitCount may be undefined + return (a.visitCount || 0) - (b.visitCount || 0); + }); + cachedHistory = history; + callback(cachedHistory); + }); + } + + chrome.history.onVisited.addListener(function(item) { + if (cachedHistory === null) return; + cachedHistory.push(item); + }); + + function getHistory(args, port) { + useHistory(function(history) { + port.postMessage({ + history: history.slice(history.length - args.maxResults) + }); }); }; -- cgit v1.2.3 From 2eae98f3b4b6cccaa49f91b282854c39145f12a4 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Tue, 24 Jan 2012 00:08:04 +0100 Subject: improve comments and fix some naming style inconsistencies --- background_page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 99c7d430..f220d76c 100644 --- a/background_page.html +++ b/background_page.html @@ -320,7 +320,7 @@ maxResults: 20000, startTime: 0, }, function(history) { - // sorting in asceding order, so we can push new items to the end later + // sorting in ascending order, so we can push new items to the end later history.sort(function(a, b) { // visitCount may be undefined return (a.visitCount || 0) - (b.visitCount || 0); -- cgit v1.2.3 From c397fffc94f563f1475f37c90eefa154ac78a6e0 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Wed, 25 Jan 2012 00:47:39 +0100 Subject: prevent duplicate history items --- background_page.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index f220d76c..e248043c 100644 --- a/background_page.html +++ b/background_page.html @@ -332,7 +332,9 @@ chrome.history.onVisited.addListener(function(item) { if (cachedHistory === null) return; - cachedHistory.push(item); + // only cache newly visited sites + if (item.visitCount === 1) + cachedHistory.push(item); }); function getHistory(args, port) { -- cgit v1.2.3 From 7c2755bcd67968f9646ac3b79432bf45da349246 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Wed, 25 Jan 2012 17:58:06 +0100 Subject: sort history by last visit time and raise number of history items to be searched --- background_page.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index e248043c..b6b72406 100644 --- a/background_page.html +++ b/background_page.html @@ -322,8 +322,7 @@ }, function(history) { // sorting in ascending order, so we can push new items to the end later history.sort(function(a, b) { - // visitCount may be undefined - return (a.visitCount || 0) - (b.visitCount || 0); + return (a.lastVisitTime|| 0) - (b.lastVisitTime || 0); }); cachedHistory = history; callback(cachedHistory); -- cgit v1.2.3 From e8b402595e5e7ebeb5abc6e1d058692370369cad Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Wed, 25 Jan 2012 21:52:15 +0100 Subject: fix bug when history maxResults is too high --- background_page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index b6b72406..a56028bc 100644 --- a/background_page.html +++ b/background_page.html @@ -339,7 +339,7 @@ function getHistory(args, port) { useHistory(function(history) { port.postMessage({ - history: history.slice(history.length - args.maxResults) + history: history.slice(Math.max(history.length - args.maxResults, 0)) }); }); }; -- cgit v1.2.3 From 3449af0461782c24c8577fe4a5938f35f417cbb1 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Fri, 27 Jan 2012 19:21:54 +0100 Subject: move completion logic to background page This has the following advantages: * searching is done in the background, UI responsiveness is improved * caches are no longer duplicated. This saves RAM and improves performance --- background_page.html | 94 +++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 63 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index a56028bc..f760ea70 100644 --- a/background_page.html +++ b/background_page.html @@ -4,6 +4,7 @@ +