Instantly share code, notes, and snippets.

Embed
What would you like to do?
;;; Commentary
;; Select and activate google chrome tabs by anything interface
;;; Requirements
;; https://github.com/mechairoi/crxel
;;; Usage
;; (require 'anything-chrome-tabs)
;; (crxel/start 9649)
;; (define-key global-map "C-t" 'anything-chrome-tabs)
(provide 'anything-chrome-tabs)
(require 'crxel)
(require 'anything-config)
(defun chrome-tab-url (tab)
(cdr-safe (assq 'url tab)))
(defun chrome-tab-title (tab)
(cdr-safe (assq 'title tab)))
(defun chrome-tab-id (tab)
(cdr-safe (assq 'id tab)))
(defun chrome-activate-tab (tab)
(crxel/eval (format "chrome.tabs.update(%s, { active: true });"
(chrome-tab-id tab))
:fail 'error))
(defun anything-chrome-tabs ()
(interactive)
(crxel/eval "var callback = window.crxel.callback;
chrome.tabs.query({}, function(tabs) {
callback(JSON.stringify(tabs));
});"
:async t
:success (lambda (data)
(anything-chrome-tabs-0
(append
(json-read-from-string data) nil)))
:fail 'error))
(defun anything-chrome-tabs-0 (tabs)
(anything-other-buffer
`((name . "Chrome Tabs")
(candidates . ,tabs)
(action . (("Activate" . chrome-activate-tab)))
(candidate-transformer . (lambda (tabs)
(mapcar (lambda (tab)
(cons
(concat
(chrome-tab-url tab)
"\n"
(chrome-tab-title tab))
tab)) tabs)))
(migemo)
(multiline))
"*anything chrome tabs*"))
@tmaeda

This comment has been minimized.

tmaeda commented Mar 9, 2014

これは興味深いですね。

一点間違いを見つけましたのでお知らせです。
quote が足りないようです。

;;  (define-key global-map "C-t" 'anything-chrome-tabs)
@mechairoi

This comment has been minimized.

Owner

mechairoi commented Jul 3, 2014

おお、指摘ありがとうございます!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment