屏蔽谷歌搜索站点

在google搜索屏蔽指定站点

Cài đặt script này?
Script được tác giả gợi ý

Bạn có thế thích Greasyfork Thợ làm keo

Cài đặt script này
// ==UserScript==
// @name              屏蔽谷歌搜索站点
// @namespace         https://github.com/ChinaGodMan/UserScripts
// @version           0.0.1.51
// @description       在google搜索屏蔽指定站点
// @description:zh-CN 在google搜索屏蔽指定站点
// @name:zh-CN        屏蔽谷歌搜索站点
// @license           MIT
// @author            人民的勤务员 <china.qinwuyuan@gmail.com>
// @include           /^https?://(www|cse)\.google(\.\w+)+/search\?.*$/
// @run-at            document-start
// @grant             GM_registerMenuCommand
// @compatible        chrome >= 49
// @compatible        firefox >= 29
// @compatible        opera >= 46
// @compatible        safari >= 10.1
// @icon              data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAACXBIWXMAAAsTAAALEwEAmpwYAAAJuklEQVR4nO2de1QU1x3H7wzrjklsYpMT002jROMzPhEUgu6qKCCyPDTHyBofKKBSgaAgsCxmxAciVF4CsRofNbUxKO4uu7OoaHY3nsa2mkYliWk8ic1pNaZqWz1tVB7765lt16PRRXZnZmdmmc8533P2wB97f9/fnfv43TuAkISEhISEhISEhISEhICA/F6jIRfXQTpuhGT8AmiwG5CA3YEZqAMikQOUCGAqAufnWKwdErE7kIRdhxT8PGTgh2ENXgg6NJDvOEQDlKDnYDVWAsl4K8Rjd5wGM5UKAczBfoAU/FPIxYqBRH34jlNQAIlksBrPhYXYNxDx/17NpaKQA5biFyAXzwYS4ainAgXoOViJHwQ11s656e5ED1nZAe/2qKfCOcyk4xREoU7ejP+xYrAOyMAPAol6I38GsrBS52TJt+FKN0rA7kI+XoT8DSBlYaDBvufdYGU3tQC/DKR8OPIHIBOrgBk+mFyVLGsm1gl5OInECpDoaUjBW3k3UslwCZuGnwYSyZGYgAJiMLyB3eLdQCVL0mB/h0KkQGIAcmWTIA67y7tpSpZFb+aEngQgAyIEvcpRMlA6bkVCBt6SvQaz/NV8TOD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W1pVaWjUNC4l0qKGSJMbqdb+PULCqxcQ7Mrax+wPwRhSc7s6q2TEdC5MCRkdMWG2f6VRLiDs+Gxe+QzjPeUUX2jtzajQlIyOw8Oj44zRjlV8ORWp8I2XuX3cyvJScjMUAvEbObpt7k2zQ1S9KaVNf1R14R3BlGl9BVznXmSaf5Nk/NQPQeZ7Ml9PQla6B4/7ROFRVclmSYxdmOWc2RFhpiHLssYzYhf+CAZeSEXJPqKt+mqrupQpPyrxQ1bDTyN+osQeuXGKNZLWWrWVSqMbKtjgpah/wZvTWwb7llgv5NY0yHgIabjhoq+IOzR18QzDk15+zRj+1bRk18n+3DHU+0wjjjbm3z+N0N1ld7zj9yewhAWAU1YUW+SfklXfXk2vQkQ6yj2Bz+1U5qTA6X1+ZF+1TUNgcVk+bws6ksbebi9QmQbpr+n2Iq/JN6atxag2HYT/iOUzT8umXM0O2Wsfml5tDDOpPy81yT6nqaIeq2xhjTMU8f66DX6fTVGPpzsmFm+zJj5O1cs+raelP4uXJqYkO9JShf3zzM5wf+EhISEhISEhISEhISqAv+C1SzADoeEosIAAAAAElFTkSuQmCC
// @iconbak           https://github.com/ChinaGodMan/UserScripts/raw/main/docs/icon/Scripts%20Icons/icons8-google-96.png
// @supportURL        https://github.com/ChinaGodMan/UserScripts/issues
// @homepageURL       https://github.com/ChinaGodMan/UserScripts
// ==/UserScript==

(function () {
    'use strict'

    // 初始化默认屏蔽站点
    const DEFAULT_BLOCKED_SITES = 'csdn'

    // 获取存储的屏蔽站点列表
    function getBlockedSites() {
        return localStorage.getItem('blockedSites') || DEFAULT_BLOCKED_SITES
    }

    // 设置屏蔽站点列表
    function setBlockedSites(sites) {
        localStorage.setItem('blockedSites', sites)
    }

    // 注册油猴菜单命令
    GM_registerMenuCommand('❌编辑屏蔽站点', function () {
        showEditDialog(getBlockedSites())
    })

    // 显示编辑对话框
    function showEditDialog(currentSites) {
        const overlay = document.createElement('div')
        overlay.id = 'overlay'
        overlay.style = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 9998;'

        const dialog = document.createElement('div')
        dialog.id = 'editDialog'
        dialog.style = 'position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 20px; border: 1px solid #ccc; box-shadow: 3px 3px 5px rgba(0,0,0,0.3); z-index: 9999; width: 60%; max-width: 600px; resize: both; overflow: auto;'
        dialog.innerHTML = `
            <h3 style="cursor: move;">编辑屏蔽站点</h3>
            <p>请输入用英文逗号分隔的站点:</p>
            <textarea id="sitesInput" style="width: 100%; height: 100px; resize: vertical;">${currentSites}</textarea>
            <div style="text-align: right; margin-top: 10px;">
                <button id="saveBtn">保存</button>
                <button id="cancelBtn">取消</button>
            </div>
        `

        document.body.appendChild(overlay)
        document.body.appendChild(dialog)

        document.getElementById('saveBtn').addEventListener('click', function () {
            const newSites = document.getElementById('sitesInput').value
            setBlockedSites(newSites)
            alert('屏蔽站点已更新,刷新页面以生效。')
            closeEditDialog()
        })

        document.getElementById('cancelBtn').addEventListener('click', function () {
            closeEditDialog()
        })

        overlay.addEventListener('click', function () {
            closeEditDialog()
        })

        function closeEditDialog() {
            document.body.removeChild(dialog)
            document.body.removeChild(overlay)
        }
    }

    // 获取搜索参数
    var params = new URLSearchParams(location.search),
        q = params.get('q')

    // 获取当前屏蔽站点列表并格式化
    const blockedSites = getBlockedSites().split(',').map(site => `-${site.trim()}`).join(' ')

    // 如果查询参数中没有屏蔽站点,则添加
    if (q && !blockedSites.split(' ').some(site => q.includes(site))) {
        params.set('q', q + ' ' + blockedSites)
        location.search = '?' + params.toString()
    }

})()