Google Search - Quick Sites

Adds Filmweb, Letterboxd, MyAnimeList, Backloggd, and Reddit buttons to Google Search tools to quickly append them to your query.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Google Search - Quick Sites
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds Filmweb, Letterboxd, MyAnimeList, Backloggd, and Reddit buttons to Google Search tools to quickly append them to your query.
// @author       qualia
// @match        https://www.google.com/search*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // The sites and the text we want to append
    const sites = [
        { name: 'filmweb', domain: 'filmweb.pl' },
        { name: 'letterboxd', domain: 'letterboxd.com' },
        { name: 'myanimelist', domain: 'myanimelist.net' },
        { name: 'backloggd', domain: 'backloggd.com' },
        { name: 'reddit', domain: 'reddit.com' }
    ];

    function appendTermAndSearch(term) {
        const urlParams = new URLSearchParams(window.location.search);
        let query = urlParams.get('q') || '';

        if (!query.toLowerCase().includes(term.toLowerCase())) {
            query += ` ${term}`;
            urlParams.set('q', query);
            urlParams.delete('start');
            window.location.href = `/search?${urlParams.toString()}`;
        }
    }

    function createIcons() {
        if (document.getElementById('custom-site-appender-icons')) return;

        const targetContainer = document.querySelector('.rQTE8b');
        if (!targetContainer) return;

        const iconWrapper = document.createElement('div');
        iconWrapper.id = 'custom-site-appender-icons';
        iconWrapper.style.display = 'flex';
        iconWrapper.style.alignItems = 'center';
        iconWrapper.style.marginLeft = '8px';
        iconWrapper.style.gap = '4px';

        sites.forEach(site => {
            const btn = document.createElement('div');
            btn.title = `Append "${site.name}" and search`;
            btn.style.cursor = 'pointer';
            btn.style.display = 'flex';
            btn.style.alignItems = 'center';
            btn.style.justifyContent = 'center';
            btn.style.width = '32px';
            btn.style.height = '32px';
            btn.style.borderRadius = '50%';
            btn.style.transition = 'background-color 0.2s';

            btn.onmouseover = () => { btn.style.backgroundColor = 'rgba(128, 128, 128, 0.2)'; };
            btn.onmouseout = () => { btn.style.backgroundColor = 'transparent'; };

            const img = document.createElement('img');
            img.src = `https://www.google.com/s2/favicons?sz=32&domain=${site.domain}`;
            img.style.width = '16px';
            img.style.height = '16px';
            img.style.borderRadius = '2px';

            btn.appendChild(img);

            btn.addEventListener('click', (e) => {
                e.preventDefault();
                appendTermAndSearch(site.name);
            });

            iconWrapper.appendChild(btn);
        });

        targetContainer.appendChild(iconWrapper);
    }

    const observer = new MutationObserver(() => {
        if (document.querySelector('.rQTE8b') && !document.getElementById('custom-site-appender-icons')) {
            createIcons();
        }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    createIcons();
})();