filter empty title

jh-changes
Shin'ya Ueoka 7 years ago
parent f8e7e7840a
commit 7ace5e1e19
  1. 48
      src/background/histories.js
  2. 5
      src/console/console.scss

@ -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) => { const getCompletions = (keyword) => {
return browser.history.search({ return browser.history.search({
text: keyword, text: keyword,
startTime: '1970-01-01' startTime: '1970-01-01'
}).then((items) => { }).then((items) => {
return filterHttp(items.map(item => [item, new URL(item.url)])) items = items.map(item => [item, new URL(item.url)]);
.sort((x, y) => x[0].lastVisitTime < y[0].lastVisitTime) 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) .slice(0, 10)
.map(item => item[0]); .map(item => item[0]);
}); });

@ -50,11 +50,16 @@ body {
&-caption { &-caption {
display: inline-block; display: inline-block;
width: 40%; width: 40%;
text-overflow: ellipsis;
overflow: hidden;
} }
&-url { &-url {
display: inline-block; display: inline-block;
color: green; color: green;
width: 60%;
text-overflow: ellipsis;
overflow: hidden;
} }
} }
} }