From 66de4a59d0e3b617b9ba317e77aedb6fb705a1ff Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 21:32:05 +0900 Subject: complete histoly simply --- src/background/histories.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/background/histories.js (limited to 'src/background/histories.js') 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 }; -- cgit v1.2.3 From f8e7e7840a96d6b09b60aa41469df9ed7de02933 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 23:03:34 +0900 Subject: drop http history if https if in histories --- src/background/histories.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/background/histories.js') 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]); }); }; -- cgit v1.2.3 From 7ace5e1e1979f15bf835af5672999e72e5d8c46f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 23:40:55 +0900 Subject: filter empty title --- src/background/histories.js | 48 +++++++++++++++++++++++++++++++++++++++++++-- src/console/console.scss | 5 +++++ 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'src/background/histories.js') 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; } } } -- cgit v1.2.3 From bf8470e1311bce02de4687dd9d1488a6484ccf6a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Sep 2017 23:59:30 +0900 Subject: fix for lint --- src/background/histories.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/background/histories.js') 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]; }); }; -- cgit v1.2.3 From 43cf68b65be01d2f40f2cd3df403f06640e55839 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:00:57 +0900 Subject: fix history range --- src/background/histories.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/background/histories.js') 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) -- cgit v1.2.3 From 5d13818fb4128a2b3a511da4929acb26e4f1e872 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:16:12 +0900 Subject: use shortest link on suggestion filter --- src/background/histories.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/background/histories.js') 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, -- cgit v1.2.3 From 44d9123bc4dccbfa0fa38aa47c987fec63ef672c Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:27:39 +0900 Subject: sory by url --- src/background/histories.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/background/histories.js') 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]; }); }; -- cgit v1.2.3 From a5af174db51a09ce6750520d2fb2d5b6bf90323a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 18 Sep 2017 00:53:11 +0900 Subject: filter closed path --- src/background/histories.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/background/histories.js') 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 -- cgit v1.2.3