Better Google

Don't be evil

目前為 2020-01-17 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Better Google
// @namespace    google
// @version      0.1.9
// @description  Don't be evil
// @author       aligo
// @match        https://*.google.com/search?*
// @include     /^https?://(?:www|encrypted|ipv[46])\.google\.[^/]+/(?:$|[#?]|search|webhp)/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var betterGoogleRow = (el) => {
        var tbwUpd = el.querySelectorAll('.TbwUpd');
        if (tbwUpd.length > 0) {
            var linkEl = el.querySelector('.r > a');
            var addEl = linkEl.nextSibling;

            var betterAddEl = document.createElement('div');
            betterAddEl.style.display = 'inline-block';
            betterAddEl.style.position = 'relative';
            betterAddEl.style.verticalAlign = 'top';

            if (addEl) {
                for (var _el of addEl.children) {
                    if (_el.className.indexOf('TbwUpd') == -1) {
                        betterAddEl.appendChild(_el);
                    }
                }
            }

            var betterEl = document.createElement('div');
            betterEl.style.wordBreak = 'break-all';
            betterEl.style.lineHeight = '18px';
            betterEl.appendChild(betterAddEl);

            el.querySelector('.r').appendChild(betterEl);

            var urlEl = document.createElement('a');
            urlEl.href = linkEl.href;
            urlEl.target = '_blank';
            urlEl.innerText = linkEl.href;
            urlEl.style.lineHeight = '18px';
            urlEl.style.marginTop = '2px';
            urlEl.style.display = 'inline-block';
            urlEl.style.color = '#006621';
            urlEl.style.fontSize = '16px';
            urlEl.style.overflow = 'hidden';
            urlEl.style.textOverflow = 'ellipsis';
            urlEl.style.whiteSpace = 'nowrap';
            urlEl.style.verticalAlign = 'top';
            urlEl.style.textDecoration = 'none';

            var maxWidth = el.clientWidth - betterAddEl.offsetWidth - 10;

            betterEl.insertBefore(urlEl, betterAddEl);
            if (urlEl.offsetWidth > maxWidth) {
                urlEl.style.width = maxWidth.toString() + 'px';
            }


            tbwUpd.forEach(el => el.remove());
            linkEl.querySelector('h3').previousSibling.remove();
        }
    }

    var prevResultCount = 0;
    var runBetterGoogle = () => {
        if (prevResultCount != document.querySelectorAll('.g .rc').length) {
            document.querySelectorAll('.g .rc').forEach(betterGoogleRow);
            prevResultCount = document.querySelectorAll('.g .rc').length;
        }
    };

    runBetterGoogle();

    var searchEl = document.getElementById('search');
    var observer = new MutationObserver(runBetterGoogle);
    observer.observe(searchEl, {childList: true, subtree: true});
})();