cs.rin.ru quick search all terms

add a field beside the search button to search all terms and an option to search within posts https://cs.rin.ru/forum/viewtopic.php?f=14&t=134386

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         cs.rin.ru quick search all terms
// @namespace    none
// @version      1
// @description  add a field beside the search button to search all terms and an option to search within posts https://cs.rin.ru/forum/viewtopic.php?f=14&t=134386
// @author       odusi
// @match        https://cs.rin.ru/forum/*
// @icon         none
// @grant        none
// ==/UserScript==
/*
Search within
all = Post subjects and message text. msgonly = Message text only. titleonly = Topic titles only. topics = First post of topics only
*/
let sf = 'titleonly'
/*
Sort results by
a = author. t = post time. f = forum. i = topic title. s = post subject
*/
const sk = 't'
const sd = 'd' // Sort results by: a = ascending. d = descending
const sr = 'topics' // Display results as: topics, posts
const ch = 300; // Return first # characters of posts

document.querySelector("#menubar > table:nth-child(3) > tbody > tr > td:nth-child(2)").insertAdjacentHTML('afterbegin', `
<div id="search-all-terms" style="position:relative;display:inline-block;"><input type="text" placeholder="Search for all terms">
    <div style="position: absolute; top: 110%">
    <input id="somecheckbox" type="checkbox" style="margin-right: 0.3rem;">
    <label for="somecheckbox">Search within posts</label></div>
    </div></div>
`)

const container = document.getElementById("search-all-terms")
const inputField = container.querySelector('input')
const checkbox = container.querySelector('#somecheckbox')

inputField.addEventListener('keydown', ev => {
    if (ev.code === 'Enter') {
        if (checkbox.checked) sf = 'all'
        window.location.href = `./search.php?keywords=${encodeURIComponent(inputField.value).replace(/%20/g, "+")}&terms=all&author=&sc=1&sf=${sf}&sk=${sk}&sd=${sd}&sr=${sr}&st=0&ch=${ch}&t=0`
    }
})