File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // ==UserScript==
2+ // @name DuckDuckGo Enhancements: Results in New Tab
3+ // @namespace https://softwareengineerprogrammer.github.io
4+ // @version 1.0.0
5+ // @description Opens external DuckDuckGo search results in a new tab.
6+ // @author softwareengineerprogrammer
7+ // @match *://duckduckgo.com/*
8+ // @match *://*.duckduckgo.com/*
9+ // @grant none
10+ // @run -at document-start
11+ // ==/UserScript==
12+
13+ ( function ( ) {
14+ 'use strict' ;
15+
16+ document . addEventListener ( 'click' , function ( event ) {
17+ const link = event . target . closest ( '#web_content_wrapper a[href]' ) ;
18+
19+ if ( link ) {
20+ const href = link . getAttribute ( 'href' ) ;
21+
22+ if ( href ) {
23+ const isInternal = href . startsWith ( '/' ) || href . startsWith ( '#' ) || href . startsWith ( 'javascript:' ) ;
24+
25+ if ( ! isInternal ) {
26+ link . setAttribute ( 'target' , '_blank' ) ;
27+ link . setAttribute ( 'rel' , 'noopener noreferrer' ) ;
28+ }
29+ }
30+ }
31+ } , true ) ;
32+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments