Quick filter for M&B wiki operations

Add a small input box to look-up, find and filter specific Mount&Blade 1.011 and Warband module system operations.

目前為 2025-07-21 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Quick filter for M&B wiki operations
// @description Add a small input box to look-up, find and filter specific Mount&Blade 1.011 and Warband module system operations.
// @namespace   https://greasyfork.org/users/4813
// @match       https://mbcommands.fandom.com/wiki/Operations*
// @match       https://antifandom.com/mbcommands/wiki/Operations*
// @icon        https://static.wikia.nocookie.net/mount26blade20mooders20reference/images/4/4a/Site-favicon.ico/revision/latest
// @version     2025.07.21
// @author      Swyter
// @license     GNU GPLv3
// @grant       none
// ==/UserScript==

search=document.createElement("input")
search.setAttribute("id", "opfilter")
search.setAttribute("type", "text")
search.setAttribute("placeholder", "Filter operations...")
search.setAttribute("style", "/*! position: relative; */align-self: center;/*! display: inline-grid; */width: calc(100% - 40%);left: calc(20%);position: fixed;bottom: 20px;box-shadow: 0 0 56px #000; opacity: .8;")
document.body.appendChild(search)

style=document.createElement("style")
style.textContent = `
.operation[hidden],
.operation[hidden] + dl,
body[opfilter] .mw-parser-output p:not(.operation),
body[opfilter] .mw-parser-output pre,
body[opfilter] .mw-parser-output ol,
body[opfilter] .mw-parser-output ul,
body[opfilter] .mw-parser-output *:not(.operation) + dl,
body[opfilter] .mw-parser-output div
{
  display: none; /* swy: hide all the flowing text, explanations and tables while in filter mode */
}

#opfilter:not(:focus)
{
  opacity: .35 !important; /* swy: fade it out when the input box is not focused */
}

* {
  scroll-margin-top: 100px; /* swy: fix scrolling to an element but getting hidden by the top bar: https://stackoverflow.com/a/59253905/674685 */
}
`
document.body.appendChild(style)

search.oninput=function(e)
{
  /* swy: hide all the non-operation stuff when using the search box; make it clean */
  document.body.setAttribute("opfilter", "true")

  //console.log(e, e.target.value);
  operations  = document.querySelectorAll(".operation");
  search_text = e.target.value

  search_elems = search_text.toLowerCase().split(/\s+/)

  for (var op of operations)
  {
    matches_all = true

    for (var el of search_elems)
      if (!op.id.includes(el))
        matches_all = false

    if (matches_all)
      op.removeAttribute("hidden")
    else
      op.setAttribute("hidden", "true")
  }

  first_visible_op = document.querySelector(".operation:not([hidden])");
  if (first_visible_op)
    first_visible_op.scrollIntoView();

// wiki_content = document.querySelector(".mw-parser-output")
// cur_wiki_content_elem = wiki_content.lastElementChild
// any_visible_since_last_header = []
// any_visible_since_last_header[1] = false
// any_visible_since_last_header[2] = false
// any_visible_since_last_header[3] = false
// any_visible_since_last_header[4] = false
// any_visible_since_last_header[5] = false
// do
// {
//   cur_is_hidden = !!!cur_wiki_content_elem.offsetParent /* swy: https://stackoverflow.com/a/21696585/674685 */

//   if (cur_wiki_content_elem.nodeName == "H5" ||
//       cur_wiki_content_elem.nodeName == "H4" ||
//       cur_wiki_content_elem.nodeName == "H3" ||
//       cur_wiki_content_elem.nodeName == "H2" ||
//       cur_wiki_content_elem.nodeName == "H1")
//   {
//     h_number = +temp0.tagName[1] /* swy: 'h3' -> 3 */

//     cur_wiki_content_elem.setAttribute("hidden", "true") : op.removeAttribute("hidden")

//     for (var i=h_number; i <= any_visible_since_last_header.length; i++)
//       any_visible_since_last_header[i] = false
//   }
//   else
//   {
//     any_visible_since_last_header[1] = !cur_is_hidden
//   }
//   //any_visible_since_last_header

//   console.log(cur_wiki_content_elem, cur_is_hidden)
// } while (cur_wiki_content_elem = cur_wiki_content_elem.previousElementSibling)

}