Google Search Result Clean

Remove "People also ask", "Featured Snippets", "Video", "Image", "Searches related to ...", "Twitter", etc. Remove naive websites.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Google Search Result Clean
// @namespace    http://tampermonkey.net/
// @license MIT
// @version      0.12
// @description  Remove "People also ask", "Featured Snippets", "Video", "Image", "Searches related to ...", "Twitter", etc. Remove naive websites.
// @homepage     https://greasyfork.org/zh-CN/scripts/393699
// @author       Saisai Lu
// @match        https://*.google.com/search*
// ==/UserScript==

(function() {
    'use strict';

    // Remove naive and annoying websites.
    // Comment this out, use uBlacklist instead
    /*
    let hostsToBlock = ['www.w3schools.com', 'www.asciitable.com', 'www.dba-oracle.com', 'www.geeksforgeeks.org', 'www.tutorialspoint.com'];
    document.querySelectorAll('.g').forEach(result => {
        let a = result.querySelector('a');
        if (a && hostsToBlock.includes(a.host)) {
            result.remove();
        }
    });
    */

    // remove 'Featured Snippets'
    let firstLine = document.querySelector('.g')
    firstLine.querySelectorAll('a').forEach(link => {
        if (link.textContent == 'About Featured Snippets') {
            firstLine.remove();
        }
    });

    let resultLines = document.querySelectorAll('div#search>div>div>div');

    resultLines.forEach(resultLine => {
        resultLine.querySelectorAll('span').forEach(span => {
            //console.log(span.textContent);
            if (span.textContent == 'People also ask') {
                resultLine.remove();
            }
        });

        resultLine.querySelectorAll('a').forEach(span => {
            //console.log(span.textContent);
            if (span.textContent == 'About featured snippets') {
                resultLine.remove();
            }
        });

        resultLine.querySelectorAll('h3').forEach(span => {
            //console.log(span.textContent);
            if (span.textContent == 'Videos') {
                resultLine.remove();
            }
        });

        resultLine.querySelectorAll('span').forEach(span => {
            if (span.textContent == 'View on Twitter') {
                resultLine.remove();
            }
        });

        resultLine.querySelectorAll('img').forEach(span => {
            resultLine.remove();
        });

    });

    // remove "Searches related to ..."
    let relatedSearches = document.getElementById('bres');
    if (relatedSearches != null) relatedSearches.remove();
})();