complete histoly simply
This commit is contained in:
parent
49fc34e444
commit
66de4a59d0
2 changed files with 33 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
import * as tabs from '../background/tabs';
|
import * as tabs from '../background/tabs';
|
||||||
|
import * as histories from '../background/histories';
|
||||||
import * as consoleActions from './console';
|
import * as consoleActions from './console';
|
||||||
|
|
||||||
const normalizeUrl = (string) => {
|
const normalizeUrl = (string) => {
|
||||||
|
@ -39,9 +40,11 @@ const bufferCommand = (keywords) => {
|
||||||
|
|
||||||
const doCommand = (name, remaining) => {
|
const doCommand = (name, remaining) => {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
case 'o':
|
||||||
case 'open':
|
case 'open':
|
||||||
// TODO use search engined and pass keywords to them
|
// TODO use search engined and pass keywords to them
|
||||||
return openCommand(normalizeUrl(remaining));
|
return openCommand(normalizeUrl(remaining));
|
||||||
|
case 't':
|
||||||
case 'tabopen':
|
case 'tabopen':
|
||||||
return tabopenCommand(normalizeUrl(remaining));
|
return tabopenCommand(normalizeUrl(remaining));
|
||||||
case 'b':
|
case 'b':
|
||||||
|
@ -53,6 +56,26 @@ const doCommand = (name, remaining) => {
|
||||||
|
|
||||||
const getCompletions = (command, keywords) => {
|
const getCompletions = (command, keywords) => {
|
||||||
switch (command) {
|
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':
|
case 'buffer':
|
||||||
return tabs.getCompletions(keywords).then((gotTabs) => {
|
return tabs.getCompletions(keywords).then((gotTabs) => {
|
||||||
let items = gotTabs.map((tab) => {
|
let items = gotTabs.map((tab) => {
|
||||||
|
|
10
src/background/histories.js
Normal file
10
src/background/histories.js
Normal file
|
@ -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 };
|
Reference in a new issue