From b44a60f485a6cb3a41d92cc4d12c88ebc852588d Mon Sep 17 00:00:00 2001 From: Luxferre Date: Wed, 16 Oct 2024 13:11:49 +0300 Subject: [PATCH] Implemented torsocks link opening --- README.md | 6 ++++++ bfg.tcl | 34 +++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6ca0386..6c1b1fb 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ The following features are already (fully or partially) supported in BFG. * In-page text search * Ini-based customization of the current Ttk theme, content fonts and colors * Non-TLS mode for systems without TclTLS support +* Opening links in Torified windows (for the systems with torsocks installed) ## Non-supported features @@ -86,6 +87,7 @@ The following keybindings are currently supported: * Shift+d: download the file or page contents under the selected link and open it with your default application * Space / Return (Enter): click on the selected link * Shift + Space / Shift + Return (Enter): open the selected link in a new window +* Control + Shift + Space / Control + Shift + Return (Enter): open the selected link in a new window in Tor * h / Arrow Left / PgUp: scroll the content up 10 lines * j / Arrow Down: scroll the content down 1 line * k / Arrow Up: scroll the content up 1 line @@ -99,12 +101,16 @@ The following mouse bindings are currently supported: * Left click: open the link * Shift + Left click or Middle click: open the link in a new window +* Shift + Middle click or Control + Shift + Left click: open the link in a new window in Tor * Right click: download the link contents * Shift + Right click: download the link contents and open it with your default application * Scroll wheel: scroll the page content * Mouse button 8 ("Back") if present: go back in history * Mouse button 9 ("Forward") if present: go forward in history +Note: opening a link in Tor requires Tor to be running and torsocks command to be installed in the system. + +You don't need to do any special combinations to open links in Tor once the parent window is already opened via torsocks. You also cannot open new windows in clearnet from the Tor-enabled windows. ## Customization diff --git a/bfg.tcl b/bfg.tcl index d74b826..439ffd2 100755 --- a/bfg.tcl +++ b/bfg.tcl @@ -272,7 +272,7 @@ proc clicklink {linknum} { } # open link in a new window -proc windowlink {linknum} { +proc windowlink {linknum istor} { global bfg_prompt sentry_status linklist ilinklist global tclpath scriptpath set url [lindex $linklist $linknum] @@ -289,7 +289,8 @@ proc windowlink {linknum} { unset -nocomplain bfg_prompt } # forward the URL to a new window - exec -ignorestderr -- $tclpath $scriptpath $url & + if {$istor eq 1} {set epath "torsocks $tclpath"} else {set epath $tclpath} + exec -ignorestderr -- {*}$epath $scriptpath $url & } # link downloading logic @@ -362,9 +363,10 @@ proc linkinsert {textw prevurl rooturl url name iprefix tag} { } # handle possible interactive part set bindcmd "clicklink $linkcount" - set bindcmd2 "windowlink $linkcount" - set bindcmd3 "downloadlink $linkcount 0" - set bindcmd4 "downloadlink $linkcount 1" + set bindcmd2 "windowlink $linkcount 0" + set bindcmd3 "windowlink $linkcount 1" + set bindcmd4 "downloadlink $linkcount 0" + set bindcmd5 "downloadlink $linkcount 1" lappend ilinklist $iprefix # perform the insertion $textw insert end $linktext "$tagname $tag" @@ -372,8 +374,10 @@ proc linkinsert {textw prevurl rooturl url name iprefix tag} { $textw tag bind $tagname $bindcmd $textw tag bind $tagname $bindcmd2 $textw tag bind $tagname $bindcmd2 - $textw tag bind $tagname $bindcmd3 - $textw tag bind $tagname $bindcmd4 + $textw tag bind $tagname $bindcmd3 + $textw tag bind $tagname $bindcmd3 + $textw tag bind $tagname $bindcmd4 + $textw tag bind $tagname $bindcmd5 $textw tag bind $tagname "set prev_status \"\$bfg_status\";set bfg_status [trunc \"$url\"];%W configure -cursor hand2" $textw tag bind $tagname { set bfg_status $prev_status @@ -1113,13 +1117,25 @@ bind . { bind . { if {$linkcount > 0} { # we have some links - windowlink $curlink + windowlink $curlink 0 } } bind . { if {$linkcount > 0} { # we have some links - windowlink $curlink + windowlink $curlink 0 + } +} + +bind . { + if {$linkcount > 0} { # we have some links + windowlink $curlink 1 + } +} + +bind . { + if {$linkcount > 0} { # we have some links + windowlink $curlink 1 } }