Last active
September 23, 2024 15:16
-
-
Save shiftgeist/deac6a23ebf8c52b770f87d959558a95 to your computer and use it in GitHub Desktop.
Userscript to hide github pull requests based on string in title or pr number.
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 Hide Github pr's | |
// @namespace shiftgeist custom Github script | |
// @match https://github.com/*/pulls* | |
// @icon https://github.com/fluidicon.png | |
// @grant GM.getValue | |
// @grant GM.setValue | |
// @version 1.1 | |
// @author - | |
// @description 23/09/2024, 10:02:18 | |
// @updateURL https://gist.githubusercontent.com/shiftgeist/deac6a23ebf8c52b770f87d959558a95/raw/gh-pr.js | |
// @downloadURL https://gist.githubusercontent.com/shiftgeist/deac6a23ebf8c52b770f87d959558a95/raw/gh-pr.js | |
// @supportURL https://gist.github.com/shiftgeist/deac6a23ebf8c52b770f87d959558a95 | |
// ==/UserScript== | |
const defaultConfig = { inTitles: [], inNumbers: [] }; | |
async function main() { | |
const config = await GM.getValue(location.pathname, defaultConfig); | |
console.log('[hide] config', config, '(hint: clear current page with `window.configReset();`)'); | |
const container = document.querySelector('[aria-label="Issues"] .js-navigation-container'); | |
Array.from(container.children).forEach(row => { | |
let hide = false; | |
const title = row.querySelector('.markdown-title'); | |
const prNum = row.querySelector('.opened-by').textContent.trim().split('\n')[0]; | |
if (config.inTitles.find(el => title.textContent.toLowerCase().includes(el)) || config.inNumbers.find(el => prNum.toLowerCase() === el)) { | |
hide = true; | |
} | |
if (hide) { | |
row.style.display = 'none'; | |
} | |
const button = document.createElement('button'); | |
button.innerText = `Ignore ${prNum}`; | |
button.style.marginLeft = '1rem'; | |
button.classList = 'Button--primary Button--medium Button'; | |
row.children[0].children[3].appendChild(button); | |
button.addEventListener('click', () => { | |
config.inNumbers.push(prNum); | |
GM.setValue(location.pathname, config); | |
row.style.display = 'none'; | |
}); | |
}); | |
const input = document.createElement('input'); | |
input.placeholder = `Title (part) to ignore - config with enter`; | |
input.classList = 'FormControl-input'; | |
container.parentElement.parentElement.parentElement.appendChild(input); | |
input.addEventListener('keydown', (e) => { | |
if (e.key === 'Enter') { | |
config.inTitles.push(input.value.toLowerCase()); | |
GM.setValue(location.pathname, config); | |
location.reload(); | |
} | |
}); | |
const reset = document.createElement('button'); | |
reset.innerText = `Reset ${config.inTitles.length + config.inNumbers.length} rules`; | |
reset.title = JSON.stringify(config, null, 2); | |
reset.classList = 'Button--primary Button--medium Button'; | |
document.body.appendChild(reset); | |
reset.addEventListener('click', () => { | |
GM.setValue(location.pathname, defaultConfig); | |
location.reload(); | |
}); | |
} | |
main().catch((e) => { | |
console.log(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment