🏠 Home 

GitHub Quick Delete

Delete GitHub repos without confirmations

  1. // ==UserScript==
  2. // @name GitHub Quick Delete
  3. // @namespace Mattwmaster58 Scripts
  4. // @version 0.1
  5. // @description Delete GitHub repos without confirmations
  6. // @author Mattwmaster58
  7. // @include /^https://github\.com/.*/.*/settings/?$/
  8. // ==/UserScript==
  9. const nodes = document.querySelectorAll('.btn-danger[role="button"]');
  10. // we assume the last 'dangerous' button is the delete button...
  11. let deleteButton = nodes[nodes.length - 1];
  12. // ...but just to be sure we do a sanity check
  13. if (deleteButton.innerHTML.search('Delete this repository') === -1) {
  14. console.error('selected wrong delete button or the text has changed!', deleteButton)
  15. } else {
  16. console.log('changing delete button text');
  17. deleteButton.innerHTML = 'Delete this repository (no confirmation!)';
  18. deleteButton.onclick = submitDeleteForm;
  19. // deleteButton.onkeyup = () => event => {if (event.key === "Enter") {submitDeleteForm();}}
  20. }
  21. function submitDeleteForm() {
  22. try {
  23. // the form action URL will end with delete typically
  24. let deleteForm = document.querySelector('form[action$="delete"]')
  25. // more implicit validation we have the right URL
  26. let repoName = deleteForm.action.match(/\.com\/(.*\/.*)\/settings\/delete/)[1];
  27. console.log(`repo name found: ${repoName}`);
  28. deleteForm.querySelector('input:not([type=hidden])').value = repoName;
  29. console.log('submitting delete form');
  30. deleteForm.submit()
  31. } catch (error) {
  32. console.error('error occurred trying to submit delete form:', error);
  33. }
  34. }