Re: [CBLX] w3m et javascript

[ Thread Index | Date Index | More lists.tuxfamily.org/carrefourblinux Archives ]


Le Sun, 29 Mar 2009 13:59:52 +0200 (CEST)
Pierre Lorenzon <devel@xxxxxxxxxxxxxxxxxxxx> écrivait:

> 
>   Qu'est-ce à dire ! Je veux voir !!!! Tu utilises le google
>   transcoder et tu l'as intégré ? Moi je l'utilise mais à la
>   main ; si tu as mis une solution intégrée au point c'est du
>   boulot utile : du très bon boulot ! Où est le code ?
> 

re salut,
ci-dessous le code à mettre dans le .emacs-w3m : ce sont 4 fonctions volées à emacspeak. Me suis pas trop fatigué...
Ai essayé sur des sites méchamment chargés en javascript (liberation.fr, le monde etc...)
amicalement
Erwin

-------------

(define-key w3m-mode-map "\C-t" 'webutils-transcode-current-url-via-google)

(defsubst url-encode (str)
  "URL encode string."
  (mapconcat
   #'(lambda (c)
       (cond ((= c 32) "+")
             ((or (and (>= c ?a) (<= c ?z))
                  (and (>= c ?A) (<= c ?Z))
                  (and (>= c ?0) (<= c ?9)))
              (char-to-string c))
             (t (upcase (format "%%%02x" c)))))
   str
   ""))

(defsubst webutils-browser-check () ;; ne sait pas si cela sert, j'ai donc laissé
  "Check to see if functions are called from a browser buffer"
  (declare (special major-mode))
  (unless (or (eq major-mode 'w3-mode)
              (eq major-mode 'w3m-mode))
    (error "This command cannot be used outside browser buffers.")))

(defvar webutils-google-transcoder-url
  "http://www.google.com/gwt/n?_gwt_noimg=1&output=xhtml&u=%s";
  "URL pattern for accessing Google transcoder.")

(defsubst webutils-transcoded-to-plain-url (url)
  "Extract plain URL from Google transcoder URL."
  (let ((prefix (substring webutils-google-transcoder-url 0
                           (1+ (position ?? webutils-google-transcoder-url)))))
    (when (equal prefix (substring url 0 (length prefix)))
      (let* ((args (substring url (length prefix)))
             (arg-alist (url-parse-args (subst-char-in-string ?& ?\; args))))
        (url-unhex-string (cdr (assoc "u" arg-alist)))))))
        
;;;###autoload 
(defsubst webutils-transcode-this-url-via-google (url)
  "Transcode specified url via Google."
  (declare (special webutils-google-transcoder-url))
  (browse-url
   (format webutils-google-transcoder-url
           (url-encode url))))

;;;###autoload
(defun webutils-transcode-current-url-via-google (&optional untranscode)
  "Transcode current URL via Google.
  Reverse effect with prefix arg."
  (interactive "P")
  (webutils-browser-check)
  ;;  (let ((url-mime-encoding-string "gzip"))
  ;; removing the above line makes the untranscode work
  (cond
   ((null untranscode)
    (webutils-transcode-this-url-via-google w3m-current-url))
   (t
    (let ((plain-url (webutils-transcoded-to-plain-url w3m-current-url)))
      (when plain-url
        (browse-url plain-url))))))


---
--
   CarrefourBLinuX MailingListe
   Pour obtenir de l'aide, envoyez le sujet  help  �   carrefourblinux-request@xxxxxxxxxxxxxxxxxxx
   Archives:
   http://listengine.tuxfamily.org/lists.tuxfamily.org/carrefourblinux


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/