Startpage.com - Hide Ads

Hides the ads section of Startpage.com search results.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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

})();