Last active
November 18, 2025 17:47
-
-
Save eliliam/e3f24e3c6b986a2e94106cf211043fcd to your computer and use it in GitHub Desktop.
GitHub Issue Search - Clear `state:open` Search Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name GitHub Issues - Clear Open Issues Search Filter | |
| // @namespace https://github.com/eliliam | |
| // @version 1.5 | |
| // @description Removes the default 'state:open' from the GitHub Issues search bar and re-executes the search. | |
| // @author Eli Smith | |
| // @match https://github.com/*/*/issues* | |
| // @grant none | |
| // @run-at document-end | |
| // @downloadURL https://gist.githubusercontent.com/eliliam/e3f24e3c6b986a2e94106cf211043fcd/raw/clear_open_filter.user.js | |
| // @updateURL https://gist.githubusercontent.com/eliliam/e3f24e3c6b986a2e94106cf211043fcd/raw/clear_open_filter.user.js | |
| // ==/UserScript== | |
| (function () { | |
| "use strict"; | |
| const AUTO_REMOVE_TERMS = ["state:open"]; | |
| /** | |
| * Finds the issues search input and removes the default filter 'state:open' if it is contained in the search | |
| */ | |
| const clearDefaultSearch = () => { | |
| // Find the search input by its stable ID | |
| const searchInput = document.getElementById("repository-input"); | |
| if (!searchInput) return; | |
| const searchVal = searchInput.value.trim(); | |
| if (searchVal?.includes("state:open")) { | |
| const cleanedSearch = searchVal | |
| .split(" ") | |
| .filter((part) => !AUTO_REMOVE_TERMS.includes(part)).join(" "); | |
| // 1. Set the value using the native property setter. | |
| const nativeInputValueSetter = Object.getOwnPropertyDescriptor( | |
| window.HTMLInputElement.prototype, | |
| "value", | |
| ).set; | |
| nativeInputValueSetter.call(searchInput, cleanedSearch); | |
| // 2. Dispatch an 'input' event to notify the framework of the value change. | |
| const inputEvent = new Event("input", { | |
| bubbles: true, | |
| cancelable: true, | |
| }); | |
| searchInput.dispatchEvent(inputEvent); | |
| // 3. Dispatch a 'change' event. | |
| const changeEvent = new Event("change", { | |
| bubbles: true, | |
| cancelable: true, | |
| }); | |
| searchInput.dispatchEvent(changeEvent); | |
| // 4. Trigger the search execution by simulating an Enter keypress (the most common search trigger). | |
| const enterKeyEvent = new KeyboardEvent("keydown", { | |
| bubbles: true, | |
| cancelable: true, | |
| key: "Enter", | |
| code: "Enter", | |
| keyCode: 13, | |
| which: 13, | |
| }); | |
| searchInput.dispatchEvent(enterKeyEvent); | |
| } | |
| }; | |
| // Run the function on the initial page load | |
| clearDefaultSearch(); | |
| // GitHub uses Turbo (formerly Turbolinks/PJAX) for page navigation. | |
| document.addEventListener("turbo:load", clearDefaultSearch); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment