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') 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