diff --git a/eaf.el b/eaf.el index 88d8adb..72b6d68 100644 --- a/eaf.el +++ b/eaf.el @@ -113,6 +113,7 @@ (define-key map (kbd "C-h m") #'eaf-describe-bindings) (define-key map [remap describe-bindings] #'eaf-describe-bindings) (define-key map (kbd "C-c b") #'eaf-open-bookmark) + (define-key map (kbd "C-c i") #'eaf-import-chrome-bookmarks) (define-key map (kbd "C-c e") #'eaf-open-external) (define-key map (kbd "M-'") #'eaf-toggle-fullscreen) (define-key map (kbd "M-/") #'eaf-get-path-or-url) @@ -255,6 +256,10 @@ It must defined at `eaf-browser-search-engines'." "Directory where eaf will store configuration files." :type 'directory) +(defcustom eaf-chrome-bookmark-file "~/.config/google-chrome/Default/Bookmarks" + "The default chrome bookmark file to import." + :type 'string) + (defcustom eaf-var-list '((eaf-camera-save-path . "~/Downloads") (eaf-browser-enable-plugin . "true") @@ -897,6 +902,13 @@ For now only EAF browser app is supported." (defaults . ,(list eaf--bookmark-title)) (filename . ,(eaf-get-path-or-url)))) +(defun eaf--browser-chrome-bookmark (name url) + "Restore EAF buffer according to chrome bookmark of given title and web URL." + `((handler . eaf--bookmark-restore) + (eaf-app . "browser") + (defaults . ,(list name)) + (filename . ,url))) + (defun eaf--pdf-viewer-bookmark () "Restore EAF buffer according to pdf bookmark from the current file path or web URL." `((handler . eaf--bookmark-restore) @@ -930,6 +942,31 @@ For now only EAF browser app is supported." ;; create new one for current buffer with provided name (bookmark-set cand))))) +(defun eaf-import-chrome-bookmarks () + "Command to import chrome bookmarks." + (interactive) + (when (eaf-read-input "Are you sure to import chrome bookmarks to EAF" "yes-or-no" "") + (if (not (file-exists-p eaf-chrome-bookmark-file)) + (message "Chrome bookmark file is not exist, check `eaf-chrome-bookmark-file` setting.") + (let ((orig-bookmark-record-fn bookmark-make-record-function) + (data (json-read-file eaf-chrome-bookmark-file))) + (cl-labels ((fn (item) + (pcase (alist-get 'type item) + ("url" + (let ((name (alist-get 'name item)) + (url (alist-get 'url item))) + (if (not (equal "chrome://bookmarks/" url)) + (progn + (setq-local bookmark-make-record-function + #'(lambda () (eaf--browser-chrome-bookmark name url))) + (bookmark-set name))))) + ("folder" + (mapc #'fn (alist-get 'children item)))))) + (fn (alist-get 'bookmark_bar (alist-get 'roots data))) + (setq-local bookmark-make-record-function orig-bookmark-record-fn) + (bookmark-save) + (message "Import success.")))))) + (defun eaf-open-external () "Command to open current path or url with external application." (interactive)