├── .gitignore ├── assets ├── chrome.png └── screenshot.png ├── package.json ├── zazu.json ├── readme.md └── search.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /assets/chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bayleeadamoss/zazu-chrome-bookmarks/HEAD/assets/chrome.png -------------------------------------------------------------------------------- /assets/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bayleeadamoss/zazu-chrome-bookmarks/HEAD/assets/screenshot.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zazu-chrome-bookmarks", 3 | "version": "1.0.0", 4 | "description": "Chrome bookmark searcher for Zazu.", 5 | "keywords": [ 6 | "zazu", 7 | "search", 8 | "chrome", 9 | "bookmarks" 10 | ], 11 | "author": "Blaine Schmeisser", 12 | "license": "MIT", 13 | "dependencies": { 14 | "fuzzyfind": "^2.0.0", 15 | "traverse": "^0.6.6" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /zazu.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Chrome Bookmarks", 3 | "version": "1.0.0", 4 | "description": "Chrome bookmark searcher for Zazu.", 5 | "icon": "assets/chrome.png", 6 | "blocks": { 7 | "input": [ 8 | { 9 | "id": "Chrome Bookmarks", 10 | "type": "PrefixScript", 11 | "space": true, 12 | "args": "Required", 13 | "prefix": ",b", 14 | "script": "search.js", 15 | "connections": [ 16 | "Open" 17 | ] 18 | } 19 | ], 20 | "output": [ 21 | { 22 | "id": "Open", 23 | "type": "OpenInBrowser", 24 | "url": "{value}" 25 | } 26 | ] 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Chrome Bookmarks 2 | 3 | Chrome bookmark searcher for Zazu. 4 | 5 | ## Usage 6 | 7 | This plugin requires a `,b` prefix, then any search term. For instance to search 8 | your bookmarks for `github` use the following: 9 | 10 | ~~~ 11 | ,b github 12 | ~~~ 13 | 14 | ![screenshot](./assets/screenshot.png) 15 | 16 | ## Installing 17 | 18 | Add the package to your plugins array in `./zazurc.js`. 19 | 20 | ~~~ javascript 21 | { 22 | "plugins": [ 23 | "tinytacoteam/zazu-chrome-bookmarks" 24 | ] 25 | } 26 | ~~~ 27 | 28 | By default we look for your default profile located at: 29 | 30 | ~~~ 31 | ~/Library/Application Support/Google/Chrome/Default/Bookmarks 32 | ~~~ 33 | 34 | To overwrite it, set the `file` variable: 35 | 36 | ~~~ javascript 37 | { 38 | "name": "tinytacoteam/zazu-chrome-bookmarks", 39 | "variables": { 40 | "file": "~/Library/Application Support/Google/Chrome/Profile 1/Bookmarks" 41 | } 42 | } 43 | ~~~ 44 | -------------------------------------------------------------------------------- /search.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const fs = require('fs') 3 | const os = require('os') 4 | const traverse = require('traverse') 5 | const fuzzyfind = require('fuzzyfind') 6 | 7 | let file = '' 8 | 9 | if (os.platform() === 'darwin') { 10 | file = '~/Library/Application Support/Google/Chrome/Default/Bookmarks' 11 | } else if (os.platform() === 'linux') { 12 | file = '~/.config/google-chrome/Default/Bookmarks' 13 | } 14 | 15 | module.exports = (pluginContext) => { 16 | return (query, env) => { 17 | if (query.length === 0) return Promise.resolve([]) 18 | const variables = env || {} 19 | const bookmarkFile = (variables['file'] || file).replace(/^~/, os.homedir()) 20 | return new Promise((resolve, reject) => { 21 | fs.readFile(bookmarkFile, (err, data) => { 22 | const rawData = JSON.parse(data) 23 | // Find 24 | const bookmarks = [] 25 | traverse(rawData).forEach((item) => { 26 | const isBookmark = item['type'] === 'url' 27 | if (isBookmark) { 28 | const bookmark = { 29 | id: query + item['url'], 30 | title: item['name'], 31 | subtitle: item['url'], 32 | value: item['url'], 33 | } 34 | bookmarks.push(bookmark) 35 | } 36 | }) 37 | 38 | // Filter 39 | const accessor = (bookmark) => bookmark.title + bookmark.subtitle 40 | const filteredBookmarks = fuzzyfind(query, bookmarks, { 41 | accessor, 42 | precision: 0.5, 43 | }).slice(0, 50) 44 | resolve(filteredBookmarks) 45 | }) 46 | }) 47 | } 48 | } 49 | --------------------------------------------------------------------------------