[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changing a user agent string [CODE INCLUDED]
- From: Boruch Baum <boruch_baum@xxxxxxx>
- Date: Sun, 14 Jan 2018 00:44:01 -0500
- X-ml-name: emacs-w3m
- X-mail-count: 12872
I wanted to easily see how pages might appear differently using
different user-agent strings, so I wrote the following. If there is
interest to add it to the project, I would change the alist to a
defcustom.
If anyone on the list has any helpful experience to share regarding
useful user-agent strings, I would welcome hearing about it.
--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0
; User-agent strings
(setq w3m-user-agent-alist (list
(cons "Emacs-w3m (user default)" w3m-user-agent)
(cons "Emacs-w3m (package default)" (concat "Emacs-w3m/" emacs-w3m-version " " w3m-version))
'("Don't send user agent" . "")
'("Android Webkit" . "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30")
'("IE Mobile" . "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)")
'("Opera Mini 9.80" . "Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54")
'("Opera Mobile 12" . "Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02")
'("Chrome 51" . "Mozilla/5.0 (Linux; Android 5.1.1; VS810PP Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36")))
(defun w3m-user-agent-change (&optional ua-string)
"Change the user-agent string.
The function prompts the user to select from entries in
`w3m-user-agent-alist', or the user may manually enter a custom
user-agent string. This function also updates `w3m-add-user-agent'."
(interactive "P")
(when (not ua-string)
(setq ua-string
(or (cdr (assoc (setq ua-string
(completing-read "Select a user-agent: " w3m-user-agent-alist))
w3m-user-agent-alist))
ua-string)))
(cond
((or (not ua-string) (string-equal ua-string ""))
(setq w3m-add-user-agent nil))
(t
(setq w3m-add-user-agent t)
(setq w3m-user-agent ua-string))))