File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,37 @@ export class Browser extends StatefulClass {
166166 childList : true ,
167167 subtree : true ,
168168 } ) ;
169+ const anchorObserver = new MutationObserver ( ( mutations ) => {
170+ mutations . forEach ( ( mutation ) => {
171+ mutation . addedNodes . forEach ( ( node ) => {
172+ if ( node instanceof HTMLAnchorElement ) {
173+ const openInNewTab = ( ) => {
174+ const href = scramjet . decodeUrl ( node . href ) ;
175+ let newtab = this . newTab ( "title" ) ;
176+ if ( href ) {
177+ newtab . frame . go ( href ) ;
178+ } else {
179+ newtab . frame . go ( "about:blank" ) ;
180+ }
181+ } ;
182+ node . addEventListener ( "click" , ( e ) => {
183+ if ( node . target !== "_blank" ) return ;
184+ e . preventDefault ( ) ;
185+ openInNewTab ( ) ;
186+ } ) ;
187+ node . addEventListener ( "auxclick" , ( e ) => {
188+ if ( e . button !== 1 ) return ; // middle click
189+ e . preventDefault ( ) ;
190+ openInNewTab ( ) ;
191+ } ) ;
192+ }
193+ } ) ;
194+ } ) ;
195+ } ) ;
196+ anchorObserver . observe ( framedoc , {
197+ childList : true ,
198+ subtree : true ,
199+ } ) ;
169200 } ) ;
170201 use ( tab . url ) . listen ( ( ) => {
171202 this . activetab = this . activetab ;
You can’t perform that action at this time.
0 commit comments