How to Permanently Exclude Site from DuckDuckGo Search Results

duckduckgo

Using DuckDuckGo, it's possible to temporarily remove a specific site from search results by adding -site:example.com to the search query.

Is there a way to permanently block/blacklist/exclude undesired websites from search results? I didn't find anything in the DDG settings but maybe there is some Greasemonkey script or Firefox extension out there that could do the trick?

Best Answer

With a standard URL rewrite/redirect pattern, you could use a Greasemonkey/Tampermonkey/generic userscript like:

// ==UserScript==
// @name        DuckDuckGo, Always add certain search parameters
// @match       *://*.duckduckgo.com/*
// @run-at      document-start
// @noframes
// @grant       none
// ==/UserScript==

//--- SET THIS NEXT VARIABLE TO TASTE.
//--- Seperate multiple site with the | key. i.e. -site:wikipedia.org|bbc.co.uk
var stickySrchTerm  = "-site:wikipedia.org";

var stckySrchEncdd  = encodeURIComponent (stickySrchTerm);
var oldUrlSearch    = location.search;

//--- Test that haven't already redirected.
if ( ! oldUrlSearch.includes (stckySrchEncdd) ) {
    //--- Our term must go in the `q=` portion of `location.search`.
    var srchParams  = oldUrlSearch.split ("&");
    for (var J = 0, L = srchParams.length;  J < L;  J++) {
        if (/^\??q=/.test (srchParams[J]) ) {
            srchParams[J] += "+" + stckySrchEncdd;
            break;
        }
    }
    var newUrlSearch    = srchParams.join ("&");
    var newURL          = location.protocol + "//"
                        + location.host
                        + location.pathname
                        + newUrlSearch
                        + location.hash
                        ;
    /*-- replace() puts the good page in the history instead of the
        bad page.
    */
    location.replace (newURL);
}