From 49fc34e4444773344e7388fa818dd6e76d825b86 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 20:12:49 +0900 Subject: [PATCH 01/11] add history permission --- manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4e32964..dfb4ae9 100644 --- a/manifest.json +++ b/manifest.json @@ -16,7 +16,8 @@ }, "permissions": [ "sessions", - "tabs" + "tabs", + "history" ], "web_accessible_resources": [ "build/console.html" From 66de4a59d0e3b617b9ba317e77aedb6fb705a1ff Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 21:32:05 +0900 Subject: [PATCH 02/11] complete histoly simply --- src/actions/command.js | 23 +++++++++++++++++++++++ src/background/histories.js | 10 ++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/background/histories.js diff --git a/src/actions/command.js b/src/actions/command.js index 3e6eadb..3e879a6 100644 --- a/src/actions/command.js +++ b/src/actions/command.js @@ -1,4 +1,5 @@ import * as tabs from '../background/tabs'; +import * as histories from '../background/histories'; import * as consoleActions from './console'; const normalizeUrl = (string) => { @@ -39,9 +40,11 @@ const bufferCommand = (keywords) => { const doCommand = (name, remaining) => { switch (name) { + case 'o': case 'open': // TODO use search engined and pass keywords to them return openCommand(normalizeUrl(remaining)); + case 't': case 'tabopen': return tabopenCommand(normalizeUrl(remaining)); case 'b': @@ -53,6 +56,26 @@ const doCommand = (name, remaining) => { const getCompletions = (command, keywords) => { switch (command) { + case 'o': + case 'open': + case 't': + case 'tabopen': + return histories.getCompletions(keywords).then((pages) => { + let items = pages.map((page) => { + return { + caption: page.title, + content: page.url, + url: page.url + }; + }); + return [ + { + name: 'History', + items + } + ]; + }); + case 'b': case 'buffer': return tabs.getCompletions(keywords).then((gotTabs) => { let items = gotTabs.map((tab) => { diff --git a/src/background/histories.js b/src/background/histories.js new file mode 100644 index 0000000..b276a2d --- /dev/null +++ b/src/background/histories.js @@ -0,0 +1,10 @@ +const getCompletions = (keyword) => { + return browser.history.search({ + text: keyword, + startTime: '1970-01-01' + }).then((items) => { + return items.sort((x, y) => x.lastVisitTime < y.lastVisitTime).slice(0, 10); + }); +}; + +export { getCompletions }; From 4bd55b67b6c71a1f80305f942ddfbc7a9df142f3 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 23:00:54 +0900 Subject: [PATCH 03/11] fix .eslintrc --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index 23f3809..8566445 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,6 +22,7 @@ "comma-dangle": "off", "consistent-return": "off", "default-case": "off", + "dot-location": ["error", "property"], "function-paren-newline": "off", "id-length": "off", "indent": ["error", 2], From f8e7e7840a96d6b09b60aa41469df9ed7de02933 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 23:03:34 +0900 Subject: [PATCH 04/11] drop http history if https if in histories --- src/background/histories.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/background/histories.js b/src/background/histories.js index b276a2d..4adada7 100644 --- a/src/background/histories.js +++ b/src/background/histories.js @@ -1,9 +1,22 @@ +const filterHttp = (items) => { + const httpsHosts = items + .filter(item => item[1].protocol === 'https:') + .map(item => item[1].host); + const httpsHostSet = new Set(httpsHosts); + return items.filter( + item => !(item[1].protocol === 'http:' && httpsHostSet.has(item[1].host)) + ); +}; + const getCompletions = (keyword) => { return browser.history.search({ text: keyword, startTime: '1970-01-01' }).then((items) => { - return items.sort((x, y) => x.lastVisitTime < y.lastVisitTime).slice(0, 10); + return filterHttp(items.map(item => [item, new URL(item.url)])) + .sort((x, y) => x[0].lastVisitTime < y[0].lastVisitTime) + .slice(0, 10) + .map(item => item[0]); }); }; From 7ace5e1e1979f15bf835af5672999e72e5d8c46f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 23:40:55 +0900 Subject: [PATCH 05/11] filter empty title --- src/background/histories.js | 48 +++++++++++++++++++++++++++++++++++-- src/console/console.scss | 5 ++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/background/histories.js b/src/background/histories.js index 4adada7..b369dd2 100644 --- a/src/background/histories.js +++ b/src/background/histories.js @@ -8,13 +8,57 @@ const filterHttp = (items) => { ); }; +const filterEmptyTitle = (items) => { + return items.filter(item => item[0].title && item[0].title !== ''); +} + +const reduceByPathname = (items, min) => { + let hash = {}; + for (let item of items) { + let pathname = item[1].origin + item[1].pathname; + if (!hash[pathname]) { + hash[pathname] = item; + } else if (hash[pathname][1].visitCount < item[1].visitCount) { + hash[pathname] = item; + } + } + let filtered = Object.values(hash); + if (filtered.length < min) { + return items; + } + return filtered; +}; + +const reduceByOrigin= (items, min) => { + let hash = {}; + for (let item of items) { + let origin = item[1].origin; + if (!hash[origin]) { + hash[origin] = item; + } else if (hash[origin][1].visitCount < item[1].visitCount) { + hash[origin] = item; + } + } + let filtered = Object.values(hash); + if (filtered.length < min) { + return items; + } + return filtered; +}; + + const getCompletions = (keyword) => { return browser.history.search({ text: keyword, startTime: '1970-01-01' }).then((items) => { - return filterHttp(items.map(item => [item, new URL(item.url)])) - .sort((x, y) => x[0].lastVisitTime < y[0].lastVisitTime) + items = items.map(item => [item, new URL(item.url)]); + items = filterEmptyTitle(items); + items = filterHttp(items); + items = reduceByPathname(items, 10); + items = reduceByOrigin(items, 10); + return items + .sort((x, y) => x[0].visitCount < y[0].visitCount) .slice(0, 10) .map(item => item[0]); }); diff --git a/src/console/console.scss b/src/console/console.scss index 7bb46dd..5823dce 100644 --- a/src/console/console.scss +++ b/src/console/console.scss @@ -50,11 +50,16 @@ body { &-caption { display: inline-block; width: 40%; + text-overflow: ellipsis; + overflow: hidden; } &-url { display: inline-block; color: green; + width: 60%; + text-overflow: ellipsis; + overflow: hidden; } } } From bf8470e1311bce02de4687dd9d1488a6484ccf6a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 23:59:30 +0900 Subject: [PATCH 06/11] fix for lint --- src/background/histories.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/background/histories.js b/src/background/histories.js index b369dd2..c94809b 100644 --- a/src/background/histories.js +++ b/src/background/histories.js @@ -10,7 +10,7 @@ const filterHttp = (items) => { const filterEmptyTitle = (items) => { return items.filter(item => item[0].title && item[0].title !== ''); -} +}; const reduceByPathname = (items, min) => { let hash = {}; @@ -29,7 +29,7 @@ const reduceByPathname = (items, min) => { return filtered; }; -const reduceByOrigin= (items, min) => { +const reduceByOrigin = (items, min) => { let hash = {}; for (let item of items) { let origin = item[1].origin; @@ -51,16 +51,17 @@ const getCompletions = (keyword) => { return browser.history.search({ text: keyword, startTime: '1970-01-01' - }).then((items) => { - items = items.map(item => [item, new URL(item.url)]); - items = filterEmptyTitle(items); - items = filterHttp(items); - items = reduceByPathname(items, 10); - items = reduceByOrigin(items, 10); - return items - .sort((x, y) => x[0].visitCount < y[0].visitCount) - .slice(0, 10) - .map(item => item[0]); + }).then((historyItems) => { + return [historyItems.map(item => [item, new URL(item.url)])] + .map(filterEmptyTitle) + .map(filterHttp) + .map(items => reduceByPathname(items, 10)) + .map(items => reduceByOrigin(items, 10)) + .map(items => items + .sort((x, y) => x[0].visitCount < y[0].visitCount) + .slice(0, 10) + .map(item => item[0]) + )[0]; }); }; From 43cf68b65be01d2f40f2cd3df403f06640e55839 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:00:57 +0900 Subject: [PATCH 07/11] fix history range --- src/background/histories.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/background/histories.js b/src/background/histories.js index c94809b..3136900 100644 --- a/src/background/histories.js +++ b/src/background/histories.js @@ -50,7 +50,7 @@ const reduceByOrigin = (items, min) => { const getCompletions = (keyword) => { return browser.history.search({ text: keyword, - startTime: '1970-01-01' + startTime: 0, }).then((historyItems) => { return [historyItems.map(item => [item, new URL(item.url)])] .map(filterEmptyTitle) From 5d13818fb4128a2b3a511da4929acb26e4f1e872 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:16:12 +0900 Subject: [PATCH 08/11] use shortest link on suggestion filter --- src/background/histories.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/background/histories.js b/src/background/histories.js index 3136900..42f7fd1 100644 --- a/src/background/histories.js +++ b/src/background/histories.js @@ -18,7 +18,7 @@ const reduceByPathname = (items, min) => { let pathname = item[1].origin + item[1].pathname; if (!hash[pathname]) { hash[pathname] = item; - } else if (hash[pathname][1].visitCount < item[1].visitCount) { + } else if (hash[pathname][1].href.length > item[1].href.length) { hash[pathname] = item; } } @@ -35,7 +35,7 @@ const reduceByOrigin = (items, min) => { let origin = item[1].origin; if (!hash[origin]) { hash[origin] = item; - } else if (hash[origin][1].visitCount < item[1].visitCount) { + } else if (hash[origin][1].href.length > item[1].href.length) { hash[origin] = item; } } @@ -46,7 +46,6 @@ const reduceByOrigin = (items, min) => { return filtered; }; - const getCompletions = (keyword) => { return browser.history.search({ text: keyword, From 44d9123bc4dccbfa0fa38aa47c987fec63ef672c Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:27:39 +0900 Subject: [PATCH 09/11] sory by url --- src/background/histories.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/background/histories.js b/src/background/histories.js index 42f7fd1..d70cf57 100644 --- a/src/background/histories.js +++ b/src/background/histories.js @@ -60,6 +60,7 @@ const getCompletions = (keyword) => { .sort((x, y) => x[0].visitCount < y[0].visitCount) .slice(0, 10) .map(item => item[0]) + .sort((x, y) => x.url > y.url) )[0]; }); }; From a5af174db51a09ce6750520d2fb2d5b6bf90323a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:53:11 +0900 Subject: [PATCH 10/11] filter closed path --- src/background/histories.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/background/histories.js b/src/background/histories.js index d70cf57..6b6e4c6 100644 --- a/src/background/histories.js +++ b/src/background/histories.js @@ -12,6 +12,21 @@ const filterEmptyTitle = (items) => { return items.filter(item => item[0].title && item[0].title !== ''); }; +const filterClosedPath = (items) => { + const allSimplePaths = items + .filter(item => item[1].hash === '' && item[1].search === '') + .map(item => item[1].origin + item[1].pathname); + const allSimplePathSet = new Set(allSimplePaths); + return items.filter( + item => !(item[1].hash === '' && item[1].search === '' && + (/\/$/).test(item[1].pathname) && + allSimplePathSet.has( + (item[1].origin + item[1].pathname).replace(/\/$/, '') + ) + ) + ); +}; + const reduceByPathname = (items, min) => { let hash = {}; for (let item of items) { @@ -54,6 +69,7 @@ const getCompletions = (keyword) => { return [historyItems.map(item => [item, new URL(item.url)])] .map(filterEmptyTitle) .map(filterHttp) + .map(filterClosedPath) .map(items => reduceByPathname(items, 10)) .map(items => reduceByOrigin(items, 10)) .map(items => items From 10bb350d849bf78d8811f11beb7f0bfb0e3ac03b Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:54:51 +0900 Subject: [PATCH 11/11] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c5e2ffe..2fa4cdf 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Firefox by WebExtensions API. - [ ] open command - [x] open a link - [ ] search by keywords with engined - - [ ] complete URLs from history + - [x] complete URLs from history - [ ] complete keywords for search - [x] tabs navigation - [x] select a tabs by keyboard