Startpage.com - Hide Ads

Hides the ads section of Startpage.com search results.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Startpage.com - Hide Ads
// @namespace    https://phatbl.at/
// @version      1.0.1
// @description  Hides the ads section of Startpage.com search results.
// @author       Ben Chatelain
// @source       https://github.com/phatblat/Startpage-HideAds
// @match        https://*.startpage.com/*/search*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict'

    // Watches the DOM and removes the div containing the ads iframe.
    // It is added asynchronously via the following two lines:
    //
    //<link rel="preload" href="/sp/adsense/search/async-ads.js" as="script">
    //<script async="" src="/sp/adsense/search/async-ads.js" onerror="csadead=1"></script>

    new MutationObserver(function(mutations) {
        // Array of MutationRecord
        // https://developer.mozilla.org/en-US/docs/Web/API/MutationRecord
        mutations.forEach( (mutation) => {
             if (mutation.type == 'childList') {
                 // One or more children have been added to and/or removed from the tree.
                 mutation.addedNodes.forEach( (node) => {
                     // 1 = ELEMENT_NODE
                     if (node.nodeType == 1) {
                         if (node.nodeName == 'DIV') {
                             if (node.id == 'gcsa-top') {
                                 node.remove()
                                 this.disconnect() // disconnect the observ
                             }
                         }
                     }
                 })
             }
        })

    }).observe(document, {childList: true, subtree: true})
    // the above observes added/removed nodes on all descendants recursively

})();