w3m

提供: ArchWiki
2023年8月25日 (金) 17:54時点におけるKgx (トーク | 投稿記録)による版 (→‎Redirect URLs: 翻訳)
ナビゲーションに移動 検索に移動

関連記事

w3m はテキストベースの Web ブラウザであり、more や [ [less]] w3m を使用すると、ターミナルエミュレータ ウィンドウを通じて Web ページを閲覧できます。さらに、w3m は、HTML をプレーンテキストにタイプセットするテキスト整形ツールとしても使用できます。

インストール

w3m パッケージを インストール して下さい。

使い方

こちらを参照 w3m(1)

設定

w3m は、ブラウザ内の設定メニューを使用するか、設定ファイルを直接変更することによって構成できます。

より高度なオプションの一部は設定メニューを使用して使用できないため、設定ファイル自体を編集することをお勧めします。

デフォルトでは、すべての設定ファイルは ~/.w3m にあります。

ヒントとテクニック

Vim キーバインド

~/.w3m/keymapカスタム設定 に置き換えます。

URL ヒント

w3m は qutebrowser のようなリンクナビゲーションをサポートしています。設定ファイルに移動して、次の行を display_link_number 0 から display_link_number 1 に変更するだけです。

そして、keymap f COMMAND "RESHAPE ; LINK_BEGIN ; GOTO_LINK"keymap F COMMAND "RESHAPE ; LINK_BEGIN ; TAB_LINK"~/.w3m/keymap に追加します。

ノート: qutebrowser はヒントを選択するためのさまざまなキーをサポートしていますが、w3m では数字キーを使用してリンクを選択することしかできません。

kittens イメージプロトコルの使用

kitty ターミナルエミュレータのユーザーは、独自の グラフィックスプロトコル を使用することを選択できます。

これを行うには、~/.w3m/config 内の次の行を変更するだけです。

inline_img_protocol 0
imgdisplay w3mimgdisplay

これに:

inline_img_protocol 4
imgdisplay kitty

検索

wrap_search を 1 に設定すると、検索がページ内のすべての一致の最後に到達した後に先頭にジャンプできるようになります。

ignorecase_search を 1 に設定すると、大文字と小文字を区別しない検索が有効になります。

ノート: 他のブラウザやテキストエディタとは異なり、w3m にはスマートケース検索のオプションがありません。

カスタム検索エンジン

キーをマップして、入力をキャプチャしてカスタム検索エンジンに渡す CGI スクリプトを起動できます。そのためには、まず ~/.w3m/keymap 内にキーバインドを作成してスクリプトを起動します。

keymap s COMMAND "SET_OPTION dictcommand=file:///cgi-bin/omnibar_google.cgi ; DICT_WORD"

そして、[1]~/.w3m/cgi-bin ディレクトリ内に配置し、実行権限を与えます。

上記のスクリプトは Google の結果を返しますが、この種のスクリプトを使用して StackOverflow、GitHub、DuckDuckGo、Reddit、その他多数の Web サイトを検索することもできます。

同様のスクリプトは GitHub で参照できます。

リーダーモード

一部の Web ページは、コンテンツのほとんどを表示するために大量の JavaScript または CSS を使用しているため、w3m では適切に動作しません。 記事の先頭に到達するために複数のページをスクロールしなければならないことがよくあります。

これは、最初に Web ページを rdrview-gitAUR などのリーダーモードプログラムに通すことで軽減できます。

これを行うには、次の行を ~/.w3m/keymap に追加します。

keymap R COMMAND "READD_SHELL 'rdrview $W3M_URL -H 2> /dev/null 1> /tmp/readable.html' ; LOAD /tmp/readdable.html"

リダイレクト URL

~/.w3m/siteconf ファイルは、リファラーやユーザーエージェントなど、Web サイトに応じていくつかの環境設定を設定するために使用されます。

また、Web サイトの代わりに、より軽量 (レイアウトと帯域幅の両方の点で) でプライバシーの点で優れたサイトにリダイレクトするために使用することもできます。

これに加えて、特定の CGI スクリプトの実行にも使用できます。

~/.w3m/siteconf
url m!^https?://([a-z]+\.)?twitter\.com/!
substitute_url "https://nitter.net/"

url m!^https?://([a-z]+\.)?reddit\.com/!
substitute_url "https://safereddit.com/"

#url m!^https?://([a-z]+\.)?google\.com/!
#substitute_url "https://duckduckgo.com/lite/"

url m!^https?://([a-z]+\.)?imgur\.com/!
substitute_url "https://rimgo.pussthecat.org/"

url m!^https?://([a-z]+\.)?wikipedia\.com/!
substitute_url "https://wl.vern.cc/"

url "https://www.youtube.com/" exact
substitute_url "file:/cgi-bin/video.cgi?"
#substitute_url "https://yewtu.be/"

url "https://stackoverflow.com/" exact
substitute_url "https://ao.bloatcat.tk/"

url "https://www.reuters.com/" exact
substitute_url "https://neuters.de/"

url "https://fandom.com/" exact
substitute_url "https://breezewiki.pussthecat.org/"

url "https://medium.com/" exact
substitute_url "https://scribe.rip/"

url "https://web.archive.org/" exact
substitute_url "https://wayback-classic.net/"

Restore closed windows

Default w3m cannot reopen closed tabs, this can be added by binding the close tab button to echo the current URL of the tab to be closed to a text file, and binding another key to restore the latest URL added to the file, using a CGI script.

Inside ~/.w3m/keymap add:

keymap d COMMAND "EXTERN 'echo %s >> ~/.w3m/RestoreTab.txt' ; CLOSE_TAB"
keymap u COMMAND TAB_GOTO file:/cgi-bin/restore_tab.cgi

Then place the following file inside ~/.w3m/cgi-bin and make it executable.

restore_tab.cgi

Opening magnet links

magnet.cgi can be used to make w3m auto open magnet links using Transmission.

Fingerprinting

Using tor

You can use torify(1) to route w3m traffic through tor.

$ torify w3m -v

User agent and headers

By default w3m uses its own user agent, meaning w3m users stand out amongst other users.

Fingerprint can be reduced by using a more generic user agent, language and http_accept header.

~/.w3m/config
user_agent Mozilla/5.0 (Windows NO 10.0; rev:91.0) Gecko/20100101 Firefox91.0
no_referer 1
cross_origin_referer 0
accept_language en-US,en;q=0.5
accept_encoding gzip, deflate
accept_media text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Disable cookies

To disable cookies set use_cookie to 0 in ~/.w3m/config.

Disable cache

To disable cookies set no_cache to 1 in ~/.w3m/config.

Troubleshooting

Images flickering/causing lag

Unfortunately, sometimes w3m lags when trying to scroll past an image, to the point where the browser can become unresponsive for multiple seconds.

A solution to this is outright disabling images, but this breaks some websites (for example, hacker news relies on GIFs for comment indentation).

A more elegant solution would be to make a keybind to toggle images on or off, to do so add the following line to ~/.w3m/keymap:

keymap i COMMAND "SET_OPTION display_image=toggle ; RESHAPE"

See also