Duck Hide Sites

Hide specific sites from DuckDuckGo search results

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Duck Hide Sites
// @namespace   IzzySoft
// @description Hide specific sites from DuckDuckGo search results
// @include     https://duckduckgo.com/*
// @include     http://duckduckgo.com/*
// @version     1
// @grant       none
// ==/UserScript==
// For our eventListener, FF complains "Use of Mutation Events is deprecated. Use MutationObserver instead." So alternatively:
// For Ajax reloads (paging), see solution at [Fire Greasemonkey script on AJAX request](http://stackoverflow.com/q/8281441/2533433)
// and [waitForKeyElements](https://greasyfork.org/en/scripts/6250-waitforkeyelements) (JQuery required)

var unwanted = ['experts-exchange.com'];
var unwantedWild = [];
var debug = false;

function getElementsByXpath(path, doc=document, ptype=XPathResult.ORDERED_NODE_SNAPSHOT_TYPE) {
  return document.evaluate(path,doc,null,ptype,null)
}
function dlog(msg) {
  if (debug) console.log(msg);
}

function hideResults() {
  var res = getElementsByXpath('//div[contains(@class,"results_links_deep")]',document);
  if (res.snapshotLength > 0) for ( i=0; i < res.snapshotLength; i++ ) {
    var link = getElementsByXpath('//a[@class="result__a"]',res.snapshotItem(i));
    if (link.snapshotLength>0) {
      if ( unwanted.indexOf(link.snapshotItem(i).hostname) > -1 ) {
        dlog('Removed result for: '+link.snapshotItem(i).hostname + ' ('+link.snapshotItem(i).getAttribute('href')+')');
        res.snapshotItem(i).style.display = 'none';
      }
      if (unwantedWild.length>0) for (var wild in unwantedWild) {
        var reg = new RegExp(unwantedWild[wild],'i');
        if ( link.snapshotItem(i).hostname.match(reg) ) {
          dlog('Removed wild result ('+unwantedWild[wild]+') for: '+link.snapshotItem(i).hostname + ' ('+link.snapshotItem(i).getAttribute('href')+')');
          res.snapshotItem(i).style.display = 'none';
        }
      }
    }
  }
}

//window.addEventListener('load', hideResults, false); // only run when page is loaded completely
document.addEventListener("DOMNodeInserted", hideResults, false); // Works on initial and additional (paged) results, as both are loaded via Ajax