Last active
December 12, 2015 06:38
-
-
Save mechairoi/4730136 to your computer and use it in GitHub Desktop.
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
;;; 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*")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
おお、指摘ありがとうございます!