Skip to content

Instantly share code, notes, and snippets.

@scarf005
Created June 7, 2023 02:13
Show Gist options
  • Save scarf005/0b44459cd20796c4587cd1cc58317bb5 to your computer and use it in GitHub Desktop.
Save scarf005/0b44459cd20796c4587cd1cc58317bb5 to your computer and use it in GitHub Desktop.
removes is:open from issues and discussions (only for Q&A).
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/std@0.190.0/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)
})
// ==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 <greenscarf005@gmail.com>
// @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