Skip to content

Commit 8f8ccd7

Browse files
ddg-enhancements.user.js
1 parent 691e295 commit 8f8ccd7

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
})();

0 commit comments

Comments
 (0)