// Run on your repositories page (github.com/$USERNAME/?tab=repositories), while logged in
getRepoId = (repoName) => fetch('https://github.com/benwinding/' + repoName)
.then(res => res.text())
.then(resText => {
const repoId = /content="repository\:([0-9]*)"/g.exec(resText)[1];
// THIS TOKEN NEEDS TO BE CHOSEN BETTER, WORKS ON SOME
const authToken = resText.split(/name="authenticity_token" value="([\w\/=]*)"/g).filter(t => t.endsWith('=='));
console.log({ repoName, repoId, authToken })
return [repoId, authToken[0]];
}).catch(err => console.error(err));
subscribeToRepo = (repoId, authToken) => fetch("https://github.com/notifications/subscribe", {
"headers": {
"accept": "application/json",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundary20q73EvXYBlWE59W",
"sec-ch-ua": "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\"",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
},
"referrerPolicy": "no-referrer-when-downgrade",
"body": `------WebKitFormBoundary20q73EvXYBlWE59W\r\nContent-Disposition: form-data; name=\"do\"\r\n\r\nsubscribed\r\n------WebKitFormBoundary20q73EvXYBlWE59W\r\nContent-Disposition: form-data; name=\"authenticity_token\"\r\n\r\n${authToken}\r\n------WebKitFormBoundary20q73EvXYBlWE59W\r\nContent-Disposition: form-data; name=\"repository_id\"\r\n\r\n${repoId}\r\n------WebKitFormBoundary20q73EvXYBlWE59W--\r\n`,
"method": "POST",
"mode": "cors",
"credentials": "include"
})
.then(res => res.json())
.then(json => console.log({ json })).catch(err => console.error(err));
repoNames = $$("a[itemprop='name codeRepository']").map(a => a.textContent.trim())
repoNames.map(repoName => getRepoId(repoName)
.then(([repoId, authToken]) => subscribeToRepo(repoId, authToken)))
Last active
July 12, 2021 08:13
-
-
Save benwinding/9cf94aaf21743bf7a79d29e61e698fdd to your computer and use it in GitHub Desktop.
JS - Subscribe to all Your Github Repo's
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment