-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Buezas
committed
Sep 22, 2021
1 parent
94980d3
commit f69089e
Showing
21 changed files
with
187 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "chrome-palette", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"private": false, | ||
"author": "[email protected]", | ||
"dependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
body { | ||
width: 605px; | ||
height: 380px; | ||
height: 395px; | ||
background: rgba(0, 0, 0, 0.75); | ||
padding: 10px; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
body .atom-suggestionsContainerOpen { | ||
max-height: 330px; | ||
} | ||
.atom-category { | ||
color: #fff; | ||
margin-right: 6px; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { useRef, useState } from "react"; | ||
import { Command } from "./commandsSuggestions"; | ||
import { formatDistanceToNow } from "date-fns"; | ||
import { parseInputCommand } from "./parseInputCommand"; | ||
import browser from "webextension-polyfill"; | ||
import { UseSuggestionParam } from "./websitesSuggestions"; | ||
import niceUrl from "./niceUrl"; | ||
import { isDefined } from "./historySuggestions"; | ||
|
||
const traverse = ( | ||
nodes: browser.Bookmarks.BookmarkTreeNode[], | ||
breadcrumb = "" | ||
): Command[] => { | ||
return nodes.flatMap(({ id, children, url, title, dateAdded }) => { | ||
const path = breadcrumb ? breadcrumb + " / " + title : title; | ||
const list: Command[] = []; | ||
if (!url && path !== "") { | ||
list.push({ | ||
name: path, | ||
icon: "chrome://favicon/", | ||
category: "Add Bookmark", | ||
timeAgo: | ||
dateAdded !== 0 | ||
? undefined | ||
: formatDistanceToNow(new Date(dateAdded || 0)), | ||
command: async function () { | ||
const [tab] = await browser.tabs.query({ | ||
currentWindow: true, | ||
active: true, | ||
}); | ||
await browser.bookmarks.create({ | ||
index: 0, | ||
url: tab.url, | ||
title: tab.title, | ||
parentId: id, | ||
}); | ||
window.close(); | ||
}, | ||
}); | ||
} | ||
if (children) { | ||
list.push(...traverse(children, path)); | ||
} | ||
return list; | ||
}); | ||
}; | ||
|
||
export function useBookmarkThisSuggestions( | ||
KEYWORD: string, | ||
{ setInputValue, inputValue }: UseSuggestionParam | ||
) { | ||
const [commands, setCommands] = useState<Command[]>([]); | ||
const { didMatch, keyword } = parseInputCommand(inputValue); | ||
const myMatch = keyword === KEYWORD; | ||
const didFetch = useRef(false); | ||
if (myMatch && !didFetch.current) { | ||
didFetch.current = true; | ||
const fetch = async () => { | ||
if (!browser) return; | ||
const root = await browser.bookmarks.getTree(); | ||
setCommands(traverse(root)); | ||
}; | ||
fetch(); | ||
} | ||
|
||
if (myMatch) return commands; | ||
if (didMatch) return []; | ||
return [ | ||
{ | ||
name: "Bookmark this tab", | ||
category: "Add Bookmark", | ||
command: async function () { | ||
setInputValue(KEYWORD + ">"); | ||
}, | ||
keyword: KEYWORD + ">", | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.