Reddit on SearXNG Search

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

目前為 2025-03-27 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit on SearXNG Search
// @namespace    https://github.com/Kdroidwin/Reddit-on-SearXNG-Search
// @version      0.3
// @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*
// @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);
        }
    }
})();