Skip to content

Instantly share code, notes, and snippets.

@rafmagana
Last active May 19, 2021 23:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rafmagana/c6859e21951c9642af1d0d548d6cc0f6 to your computer and use it in GitHub Desktop.
Save rafmagana/c6859e21951c9642af1d0d548d6cc0f6 to your computer and use it in GitHub Desktop.
Unwatch multiple repositories at once in GiHub
/* USAGE
Go to https://github.com/watching
Paste this function in the console
e.g. unwatchRepos("rails|node|go")
That unwatches repos containing rails, node or go in the repo link.
*/
var unwatchRepos = (pattern) => {
var list = document.getElementsByClassName('repo-list')[0]
var rows = list.getElementsByClassName('js-subscription-row')
for(var i = 0; i < rows.length; i++) {
var row = rows[i]
var link = row.getElementsByTagName('a')[0]
if(RegExp(pattern).test(link.href)) {
row.getElementsByClassName('btn-sm')[0].click()
}
}
}
@mattplatoff
Copy link

Found this Gist following the github onboarding guide while going through new hire onboarding. Github must have changed some of ids on their watching page since this was written so the script no longer works for me.
I took the liberty of modifying it for my usecase and am sharing the modified version here:

An important note, I have changed the pattern that unwatchRepos takes in from a language based pattern to a repo named pattern so unwatchReposExcept("android-instant") will unwatch everything except "android-instant".

var unwatchReposExcept = (pattern) => {
 var list = document.getElementsByClassName('repo-list')[0]
 var rows = list.getElementsByClassName('Box-row')

 for(var i = 0; i < rows.length; i++) {
   var row = rows[i]
   var notification_button = row.getElementsByTagName('notifications-list-subscription-form')[0]
   var link = row.getElementsByTagName('a')[0]
   if(!RegExp(pattern).test(link.href)) {
     notification_button.click()
     row.getElementsByClassName("SelectMenu-item flex-items-start").item(2).click()
   }
 }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment