您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Add a small input box in the operations and triggers pages to easily look up, find and filter specific Mount&Blade 1.011 and Warband module system opcodes and triggers.
当前为
// ==UserScript== // @name Quick opcode filter for M&B mod wiki // @description Add a small input box in the operations and triggers pages to easily look up, find and filter specific Mount&Blade 1.011 and Warband module system opcodes and triggers. // @namespace https://greatest.deepsurf.us/users/4813 // // @match https://mbcommands.fandom.com/wiki/Operations* // @match https://antifandom.com/mbcommands/wiki/Operations* // // @match https://mbcommands.bandom.com/wiki/Triggers* // @match https://antifandom.com/mbcommands/wiki/Triggers* // // @icon https://static.wikia.nocookie.net/mount26blade20mooders20reference/images/4/4a/Site-favicon.ico/revision/latest // @version 2025.07.21 // @author Swyter // @license GNU GPLv3 // @run-at document-idle // @grant none // ==/UserScript== /* swy: append our new filter input box HTML element into the page */ search=document.createElement("input") search.setAttribute("id", "opfilter") search.setAttribute("type", "text") search.setAttribute("placeholder", "Filter operations or triggers... :)") document.body.appendChild(search) /* swy: append a new inline CSS stylesheet for our stuff into the page */ 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, body[opfilter] .mw-parser-output table { display: none; /* swy: hide all the flowing text, explanations and tables while in filter mode */ } input#opfilter { position: fixed; width: calc(100% - (20% + 20%)); /* swy: center it leaving 20% of page width at either side */ left: calc(20%); bottom: 20px; box-shadow: 0 0 4px black, 0 0 40px black, 0 0 100px black; opacity: .8; } input#opfilter:not(:focus) { opacity: .35; /* 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) /* swy: get rid of the tip mentioning this userscript if it's already installed */ if (install_userscript_box = document.querySelector('div.main-page-box:has(a[href*=greasyfork])')) install_userscript_box.remove() /* swy: on every new typed input do this */ search.oninput=function(e) { /* swy: hide all the non-operation stuff (text, explanations, ...) when using the search box; make it clean */ document.body.setAttribute("opfilter", "true") /* swy: get a list of every operation, get the search text the user typed, split into words */ operations = document.querySelectorAll(".operation"); search_text = e.target.value search_elems = search_text.toLowerCase().split(/\s+/) /* swy: go across every operation in the page and show it, if it contains *every* word in the filter, or just hide it otherwise */ 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") } /* swy: scroll into the first (visible) operation that matches our search, if any */ if (first_visible_op = document.querySelector('.operation:not([hidden])')) first_visible_op.scrollIntoView(); /* swy: hide empty headers (with no operation block hanging from it) */ wiki_content = document.querySelector(".mw-parser-output") cur_elem = wiki_content.lastElementChild header_regex = /H[0-9]/ parent_ctx = [] ctx = [] do { cur_elem_visible = !!cur_elem.offsetParent; /* swy: https://stackoverflow.com/a/21696585/674685 */ console.log("loop", cur_elem, cur_elem_visible) if (!cur_elem_visible) continue; console.log("cont", cur_elem, cur_elem_visible) if (cur_elem.nodeName.match(header_regex)) { console.log("header", cur_elem, ctx) parent_ctx.push({ header: cur_elem, nodes: ctx}) if (ctx.length <= 0) cur_elem.setAttribute("hidden", "true") else op.removeAttribute("hidden") ctx = [] } else if(cur_elem_visible) { ctx.push(cur_elem) console.log("other", cur_elem, ctx) } } while (cur_elem = cur_elem.previousElementSibling) // 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) }