GitHub Quick Delete

Delete GitHub repos without confirmations

当前为 2021-01-05 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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);
    }
}