GitHub Quick Delete

Delete GitHub repos without confirmations

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         GitHub Quick Delete
// @namespace    Mattwmaster58 Scripts
// @version      0.1
// @description  Delete GitHub repos without confirmations
// @author       Mattwmaster58
// @include      /^https://github\.com/.*/.*/settings/?$/
// ==/UserScript==

const nodes = document.querySelectorAll('.btn-danger[role="button"]');
// we assume the last 'dangerous' button is the delete button...
let deleteButton = nodes[nodes.length - 1];

// ...but just to be sure we do a sanity check
if (deleteButton.innerHTML.search('Delete this repository') === -1) {
    console.error('selected wrong delete button or the text has changed!', deleteButton)
} else {
    console.log('changing delete button text');
    deleteButton.innerHTML = 'Delete this repository (no confirmation!)';
    deleteButton.onclick = submitDeleteForm;
    // deleteButton.onkeyup = () => event => {if (event.key === "Enter") {submitDeleteForm();}}
}

function submitDeleteForm() {
    try {
        // the form action URL will end with delete typically
        let deleteForm = document.querySelector('form[action$="delete"]')
        // more implicit validation we have the right URL
        let repoName = deleteForm.action.match(/\.com\/(.*\/.*)\/settings\/delete/)[1];
        console.log(`repo name found: ${repoName}`);
        deleteForm.querySelector('input:not([type=hidden])').value = repoName;
        console.log('submitting delete form');
        deleteForm.submit()
    } catch (error) {
        console.error('error occurred trying to submit delete form:', error);
    }
}