clean-search-extension

Auto-clean popular search engine URLs for a faster, cleaner experience. | made by conflicted

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         clean-search-extension
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Auto-clean popular search engine URLs for a faster, cleaner experience. | made by conflicted
// @author       conflicted @kittenware on discord
// @match        *://www.google.com/search*
// @match        *://www.google.*.*/search*
// @match        *://search.yahoo.com/search*
// @match        *://*.search.yahoo.com/search*
// @match        *://www.bing.com/search*
// @match        *://duckduckgo.com/*
// @match        *://yandex.com/search/*
// @match        *://yandex.ru/search/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const url = new URL(window.location.href);

    let cleaned = false; // Flag to detect if cleaning happened

    // GOOGLE
    if (url.hostname.includes('google.')) {
        if (url.searchParams.get('udm') !== '14') {
            url.searchParams.set('udm', '14');
            window.location.replace(url.toString());
        }
    }

    // YAHOO
    else if (url.hostname.includes('yahoo.com')) {
        const p = url.searchParams.get('p');
        if (p) {
            const cleanUrl = `${url.origin}${url.pathname}?p=${encodeURIComponent(p)}`;
            if (window.location.href !== cleanUrl) {
                window.location.replace(cleanUrl);
            }
        }
    }

    // BING
    else if (url.hostname.includes('bing.com')) {
        const q = url.searchParams.get('q');
        if (q) {
            const cleanUrl = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}`;
            if (window.location.href !== cleanUrl) {
                window.location.replace(cleanUrl);
            }
        }
    }

    // DUCKDUCKGO
    else if (url.hostname.includes('duckduckgo.com')) {
        const q = url.searchParams.get('q');
        if (q) {
            const cleanUrl = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}`;
            if (window.location.href !== cleanUrl) {
                window.location.replace(cleanUrl);
            }
        }
    }

    // YANDEX
    else if (url.hostname.includes('yandex.com') || url.hostname.includes('yandex.ru')) {
        const text = url.searchParams.get('text');
        if (text) {
            const cleanUrl = `${url.origin}${url.pathname}?text=${encodeURIComponent(text)}`;
            if (window.location.href !== cleanUrl) {
                window.location.replace(cleanUrl);
            }
        }
    }

    // AFTER THE PAGE LOADS
    window.addEventListener('load', () => {
        showPopup();
    });

    // Little Popup
    function showPopup() {
        const popup = document.createElement('div');
        popup.innerText = 'Results Cleaned by Conflicted @kittenware';
        popup.style.position = 'fixed';
        popup.style.top = '20px';
        popup.style.right = '20px';
        popup.style.backgroundColor = '#222';
        popup.style.color = '#fff';
        popup.style.padding = '10px 15px';
        popup.style.borderRadius = '10px';
        popup.style.boxShadow = '0px 0px 10px rgba(0,0,0,0.5)';
        popup.style.zIndex = '99999';
        popup.style.fontFamily = 'Arial, sans-serif';
        popup.style.fontSize = '14px';
        popup.style.opacity = '0.9';
        document.body.appendChild(popup);

        setTimeout(() => {
            popup.remove();
        }, 2000); // Remove popup after 2 seconds
    }
})();