diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-18 00:53:11 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-18 00:53:11 +0900 |
commit | a5af174db51a09ce6750520d2fb2d5b6bf90323a (patch) | |
tree | b61e4cad1fbaa5726f5271a87849cc0d95edfafe /src/background/histories.js | |
parent | 44d9123bc4dccbfa0fa38aa47c987fec63ef672c (diff) |
filter closed path
Diffstat (limited to 'src/background/histories.js')
-rw-r--r-- | src/background/histories.js | 16 |
1 files changed, 16 insertions, 0 deletions
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 |