Created
June 7, 2023 02:13
-
-
Save scarf005/0b44459cd20796c4587cd1cc58317bb5 to your computer and use it in GitHub Desktop.
removes is:open from issues and discussions (only for Q&A).
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
const getUrl = (elem: Element) => elem.getAttribute("href")!.split("?")[0] | |
const setQuery = (selector: string, query: string) => () => { | |
const elem = document.querySelector(selector) | |
if (!elem) { | |
console.log(`elem with ${selector} not found`) | |
return | |
} | |
const newSearchParams = new URLSearchParams({ q: query }) | |
elem.setAttribute("href", `${getUrl(elem)}?${newSearchParams}`) | |
} | |
const showAllIssues = setQuery("#issues-tab", "is:issue sort:updated-desc") | |
const showAllDiscussions = setQuery("#discussions-tab", "") | |
const showAllQnA = () => { | |
const qna = document.querySelector("li.ActionList-item[item_id='q-a'] > a") | |
// @ts-ignore: idk why it errors but | |
const text = qna?.childNodes[3].innerText | |
if (!qna || !text) { | |
console.log("qna not found") | |
return | |
} | |
const newSearchParams = new URLSearchParams({ discussions_q: `category:${text}` }) | |
qna.setAttribute("href", `${getUrl(qna)}?${newSearchParams}`) | |
} | |
// TODO: remove is:open for q-a | |
const mount = (f: () => void) => { | |
f() | |
document.addEventListener("turbo:render", f) | |
} | |
// showAllPullRequests | |
const fx = [showAllIssues, showAllDiscussions, showAllQnA] | |
fx.forEach(mount) | |
console.log("remove is:open mounted.") | |
/* Deno */ | |
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts" | |
document = undefined as any | |
Deno.test("can explicitly set search params to show all discussions", () => { | |
const before = "https://github.com/denoland/deno/discussions" | |
const expected = "https://github.com/denoland/deno/discussions?discussions_q=" | |
assertEquals(`${before}?discussions_q=`, expected) | |
}) |
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 Remove is:open | |
// @namespace https://github.com/scarf005 | |
// @version 1.0.0 | |
// @description removes is:open from issues and discussions (only for Q&A). | |
// @icon https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png | |
// @author scarf005 <[email protected]> | |
// @license GPL-3.0-or-later https://www.gnu.org/licenses/gpl-3.0.txt | |
// @include https://github.com/* | |
// @grant none | |
// ==/UserScript== | |
{ | |
const getUrl = (elem) => elem.getAttribute("href").split("?")[0] | |
const setQuery = (selector, query) => () => { | |
const elem = document.querySelector(selector) | |
if (!elem) { | |
console.log(`elem with ${selector} not found`) | |
return | |
} | |
const newSearchParams = new URLSearchParams({ q: query }) | |
elem.setAttribute("href", `${getUrl(elem)}?${newSearchParams}`) | |
} | |
const showAllIssues = setQuery("#issues-tab", "is:issue sort:updated-desc") | |
const showAllDiscussions = setQuery("#discussions-tab", "") | |
const showAllQnA = () => { | |
const qna = document.querySelector("li.ActionList-item[item_id='q-a'] > a") | |
// @ts-ignore: idk why it errors but | |
const text = qna?.childNodes[3].innerText | |
if (!qna || !text) { | |
console.log("qna not found") | |
return | |
} | |
const newSearchParams = new URLSearchParams({ discussions_q: `category:${text}` }) | |
qna.setAttribute("href", `${getUrl(qna)}?${newSearchParams}`) | |
} | |
// TODO: remove is:open for q-a | |
const mount = (f) => { | |
f() | |
document.addEventListener("turbo:render", f) | |
} | |
// showAllPullRequests | |
const fx = [showAllIssues, showAllDiscussions, showAllQnA] | |
fx.forEach(mount) | |
console.log("remove is:open mounted.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment