File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// ==UserScript==
22// @name 新标签页打开链接
3- // @version 1.0.4
3+ // @version 1.0.5
44// @author X.I.U
55// @description 将网页中所有链接改为新标签页打开~
66// @match *://*/*
2424 function targetBlank ( ) {
2525 document . head . appendChild ( document . createElement ( 'base' ) ) . target = '_blank' ; // 让所有链接默认以新标签页打开
2626 Array . from ( document . links ) . forEach ( function ( _this ) {
27- if ( _this . href && _this . href . slice ( 0 , 4 ) != 'http' ) {
27+ if ( _this . onclick || _this . href . slice ( 0 , 4 ) != 'http' || _this . getAttribute ( 'href' ) . slice ( 0 , 1 ) === '# ') {
2828 _this . target = '_self'
2929 }
3030 } )
4949 for ( const target of mutation . addedNodes ) {
5050 if ( target . nodeType != 1 ) return
5151 if ( target . tagName === 'A' ) {
52- if ( target . href && target . href . slice ( 0 , 4 ) != 'http' ) {
52+ if ( target . onclick || target . href . slice ( 0 , 4 ) != 'http' || target . getAttribute ( 'href' ) . slice ( 0 , 1 ) === '# ') {
5353 target . target = '_self'
5454 }
5555 } else {
5656 document . querySelectorAll ( 'a' ) . forEach ( function ( _this ) {
57- if ( _this . href && _this . href . slice ( 0 , 4 ) != 'http' ) {
57+ if ( _this . onclick || _this . href . slice ( 0 , 4 ) != 'http' || _this . getAttribute ( 'href' ) . slice ( 0 , 1 ) === '# ') {
5858 _this . target = '_self'
5959 }
6060 } ) ;
You can’t perform that action at this time.
0 commit comments