Last active
October 17, 2023 10:53
-
-
Save ScriptRaccoon/d3c7b9a9db83e6a5a06f4bb95ff113ad to your computer and use it in GitHub Desktop.
Script to open all GitHub discussions in a PR. Continuously clicks on the "Load More" buttons.
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 loadmore_condition = (button) => button.innerText.includes('Load more'); | |
const status_element = document.createElement('div'); | |
status_element.innerText = 'Opening conversations ...'; | |
status_element.style = | |
'position: fixed; z-index: 100; top: 1rem; left: 1rem; background-color: white; color: black; border: 1px solid black; padding: 0.5rem 1rem;'; | |
document.body.appendChild(status_element); | |
async function open_conversations() { | |
const buttons = Array.from(document.querySelectorAll('button')); | |
const loadmore_button = buttons.find(loadmore_condition); | |
if (loadmore_button) { | |
loadmore_button.scrollIntoView({ behavior: 'smooth', block: 'center' }); | |
loadmore_button.style = 'outline: 5px solid skyblue'; | |
loadmore_button.click(); | |
await new Promise((resolve) => setTimeout(resolve, 2500)); | |
open_conversations(); | |
} else { | |
status_element.innerText = 'Done!'; | |
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }); | |
setTimeout(() => status_element.remove(), 2500); | |
} | |
} | |
open_conversations(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bookmarklet code
Put this as the URL of a bookmark.
javascript: const loadmore_condition=e=>e.innerText.includes("Load more"),status_element=document.createElement("div");async function open_conversations(){let e=Array.from(document.querySelectorAll("button")),o=e.find(loadmore_condition);o?(o.scrollIntoView({behavior:"smooth",block:"center"}),o.style="outline: 5px solid skyblue",o.click(),await new Promise(e=>setTimeout(e,2500)),open_conversations()):(status_element.innerText="Done!",window.scrollTo({top:0,left:0,behavior:"smooth"}),setTimeout(()=>status_element.remove(),2500))}status_element.innerText="Opening conversations ...",status_element.style="position: fixed; z-index: 100; top: 1rem; left: 1rem; background-color: white; color: black; border: 1px solid black; padding: 0.5rem 1rem;",document.body.appendChild(status_element),open_conversations();