Reddit on SearXNG Search

Add site:reddit.com to SearXNG search queries on button click

当前为 2025-04-16 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit on SearXNG Search
// @namespace    https://github.com/Kdroidwin/Reddit-on-SearXNG-Search
// @version      0.4
// @description  Add site:reddit.com to SearXNG search queries on button click
// @author       Kdroidwin
// @license GPL-3.0 license
// @match        https://priv.au/*
// @match        https://search.inetol.net/*
// @match        https://searx.tiekoetter.com/*
// @match        https://searx.be/search*
// @match        https://opnxng.com/search*
// @match        https://searxng.hweeren.com/search*
// @match        https://searx.perennialte.ch/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // SearXNG の検索フォームと検索入力フィールドのセレクタを取得
    const searchForm = document.querySelector('form[action="/search"]');
    const searchInput = document.querySelector('input[name="q"]');

    // Reddit 検索用のボタンを作成
    const redditButton = document.createElement('button');
    redditButton.textContent = 'Search Reddit';
    redditButton.type = 'button';
    redditButton.style.marginLeft = '10px';

    // ボタンのクリックイベントを追加
    redditButton.addEventListener('click', function() {
        let query = searchInput.value;

        // クエリに site:reddit.com を追加
        if (!query.includes('site:reddit.com')) {
            searchInput.value = query + ' site:reddit.com';
        }

        // フォームを送信
        searchForm.submit();
    });

    // セーフサーチの要素を探す
    const safeSearchElement = document.querySelector('select[name="safesearch"]');

    // セーフサーチの右側にボタンを追加
    if (safeSearchElement) {
        safeSearchElement.parentNode.insertBefore(redditButton, safeSearchElement.nextSibling);
    } else {
        // セーフサーチが見つからなかった場合は、代わりに検索フォームに追加
        if (searchForm) {
            searchForm.appendChild(redditButton);
        }
    }
})();