├── README.md ├── logo.png ├── plugin.json ├── preload.js └── web.png /README.md: -------------------------------------------------------------------------------- 1 | 1. Chrome 书签搜索 2 | 3 | 2. Chrome当前浏览的网页,切换到隐私模式浏览 (macos、windows) 4 | 5 | 3. 列出Chrome已打开的所有标签 (macos) -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/in3102/utools-chrome_helper/60f1b7ce932931d00757beefbd4742b8c3f21a66/logo.png -------------------------------------------------------------------------------- /plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.6", 3 | "pluginName": "Chrome 小助手", 4 | "description": "Chrome 书签搜索", 5 | "author": "uTools官方", 6 | "homepage": "https://u.tools", 7 | "preload": "preload.js", 8 | "logo": "logo.png", 9 | "features": [ 10 | { 11 | "platform": [ 12 | "darwin", 13 | "win32" 14 | ], 15 | "code": "incognito_mode", 16 | "explain": "Chrome 隐身模式打开当前URL", 17 | "cmds": [ 18 | { 19 | "type": "window", 20 | "match": { 21 | "app": ["Google Chrome.app", "chrome.exe"] 22 | }, 23 | "label": "隐身模式打开" 24 | } 25 | ] 26 | }, 27 | { 28 | "code": "chrome_bookmarks", 29 | "explain": "Chrome 书签搜索", 30 | "cmds": [ 31 | "Chrome BookMarks", 32 | "Chrome 书签" 33 | ] 34 | }, 35 | { 36 | "platform": "darwin", 37 | "code": "opened_tabs", 38 | "explain": "列出所有 Chrome 窗口已打开的标签页", 39 | "cmds": [ 40 | { 41 | "type": "window", 42 | "match": { 43 | "app": "Google Chrome.app" 44 | }, 45 | "label": "所有标签页" 46 | } 47 | ] 48 | } 49 | ] 50 | } -------------------------------------------------------------------------------- /preload.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const fs = require('fs') 3 | const { shell } = require('electron') 4 | const cp = require('child_process') 5 | let bookmarksDataCache = null 6 | let tabListCache = [] 7 | 8 | function getChromeBookmarks () { 9 | let chromeDataDir = '' 10 | const profiles = ['Default', 'Profile 3', 'Profile 2', 'Profile 1'] 11 | if (process.platform === 'win32') { 12 | chromeDataDir = path.join(process.env['LOCALAPPDATA'], 'Google/Chrome/User Data') 13 | } else if (process.platform === 'darwin') { 14 | chromeDataDir = path.join(window.utools.getPath('appData'), 'Google/Chrome') 15 | } else if (process.platform === 'linux') { 16 | chromeDataDir = path.join(window.utools.getPath('appData'), 'google-chrome') 17 | } 18 | const profile = profiles.find(profile => fs.existsSync(path.join(chromeDataDir, profile, 'Bookmarks'))) 19 | if (!profile) return [] 20 | const bookmarkPath = path.join(chromeDataDir, profile, 'Bookmarks') 21 | const bookmarksData = [] 22 | try { 23 | const data = JSON.parse(fs.readFileSync(bookmarkPath, 'utf-8')) 24 | const getUrlData = (item) => { 25 | if (!item || !Array.isArray(item.children)) return 26 | item.children.forEach(c => { 27 | if (c.type === 'url') { 28 | bookmarksData.push({ 29 | lowTitle: c.name.toLowerCase(), 30 | title: c.name, 31 | description: c.url, 32 | icon: 'web.png' 33 | }) 34 | } else if (c.type === 'folder') { 35 | getUrlData(c) 36 | } 37 | }) 38 | } 39 | getUrlData(data.roots.bookmark_bar) 40 | getUrlData(data.roots.other) 41 | getUrlData(data.roots.synced) 42 | } catch (e) {} 43 | return bookmarksData 44 | } 45 | 46 | window.exports = { 47 | 'incognito_mode': { 48 | mode: 'none', 49 | args: { 50 | enter: (action) => { 51 | const url = window.utools.getCurrentBrowserUrl() 52 | if (!url) { 53 | window.utools.outPlugin() 54 | return 55 | } 56 | window.utools.hideMainWindow() 57 | let chromePath = action.payload.appPath 58 | if (process.platform === 'darwin') { 59 | chromePath = path.join(chromePath, 'Contents/MacOS/Google Chrome') 60 | } 61 | cp.execFile(chromePath, ['--incognito', url], () => { window.utools.outPlugin() }) 62 | } 63 | } 64 | }, 65 | 'chrome_bookmarks': { 66 | mode: 'list', 67 | args: { 68 | enter: (action, callbackSetList) => { 69 | bookmarksDataCache = getChromeBookmarks() 70 | }, 71 | search: (action, searchWord, callbackSetList) => { 72 | if (!searchWord) return callbackSetList() 73 | searchWord = searchWord.toLowerCase() 74 | return callbackSetList(bookmarksDataCache.filter(x => x.lowTitle.includes(searchWord))) 75 | }, 76 | select: (action, itemData) => { 77 | window.utools.hideMainWindow() 78 | shell.openExternal(itemData.description).then(() => { 79 | window.utools.outPlugin() 80 | }) 81 | } 82 | } 83 | }, 84 | 'opened_tabs': { 85 | mode: 'list', 86 | args: { 87 | enter: (action, callbackSetList) => { 88 | tabListCache = [] 89 | cp.exec(`osascript -e 'set tabString to "" 90 | tell application "Google Chrome" 91 | set window_list to every window 92 | repeat with the_window in window_list 93 | set tab_list to every tab in the_window 94 | repeat with the_tab in tab_list 95 | set the_title to the title of the_tab 96 | set the_url to the URL of the_tab 97 | set tabString to tabString & the_title & "\n" & the_url & "\n\n" 98 | end repeat 99 | end repeat 100 | return tabString 101 | end tell'`, (error, stdout, stderr) => { 102 | if (error) return window.utools.showNotification(stderr) 103 | if (!stdout.trim()) return 104 | const list = stdout.trim().split('\n\n') 105 | list.forEach(r => { 106 | const rl = r.split('\n') 107 | tabListCache.push({ title: rl[0], description: rl[1] }) 108 | }) 109 | callbackSetList(tabListCache) 110 | }) 111 | }, 112 | search: (action, searchWord, callbackSetList) => { 113 | if (!searchWord) return callbackSetList(tabListCache) 114 | searchWord = searchWord.toLowerCase() 115 | const list = tabListCache.filter(x => x.title.toLowerCase().includes(searchWord) || x.description.toLowerCase().includes(searchWord)) 116 | callbackSetList(list) 117 | }, 118 | select: (action, itemData) => { 119 | window.utools.hideMainWindow() 120 | cp.exec(`osascript -e 'tell application "Google Chrome" 121 | repeat with w in (windows) 122 | set j to 0 123 | repeat with t in (tabs of w) 124 | set j to j + 1 125 | if URL of t is "${itemData.description}" then 126 | set (active tab index of w) to j 127 | set index of w to 1 128 | end if 129 | end repeat 130 | end repeat 131 | end tell'`, (error, stdout, stderr) => { 132 | if (error) return window.utools.showNotification(stderr) 133 | window.utools.outPlugin() 134 | }) 135 | } 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/in3102/utools-chrome_helper/60f1b7ce932931d00757beefbd4742b8c3f21a66/web.png --------------------------------------------------------------------------------