Vercel Project Deletion Form Filler

Automatically fills in project deletion form fields on Vercel. This script extracts the project name from the page and fills it into the appropriate input field, along with the verification text. Use with caution as it automates deletion form filling.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Vercel Project Deletion Form Filler
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Automatically fills in project deletion form fields on Vercel. This script extracts the project name from the page and fills it into the appropriate input field, along with the verification text. Use with caution as it automates deletion form filling.
// @author       YourName
// @match        https://vercel.com/*/settings
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract project name from HTML
    function getProjectName() {
        const selectors = [
            'b[style*="overflow-wrap: anywhere"]',
            'p strong',
            'label b',
            'p b'
        ];

        for (let selector of selectors) {
            const element = document.querySelector(selector);
            if (element && element.textContent.trim()) {
                return element.textContent.trim();
            }
        }

        return null;
    }

    // Function to fill the form
    function fillForm() {
        const projectName = getProjectName();
        if (!projectName) {
            console.error('Could not find project name');
            return;
        }

        const inputs = Array.from(document.querySelectorAll('input[type="text"]'));

        const projectNameInput = inputs.find(input =>
            input.getAttribute('aria-label')?.toLowerCase().includes('resource name') ||
            input.getAttribute('name')?.toLowerCase().includes('resourcename') ||
            input.getAttribute('placeholder')?.toLowerCase().includes('project name')
        );
        if (projectNameInput) {
            projectNameInput.value = projectName;
            projectNameInput.dispatchEvent(new Event('input', { bubbles: true }));
            projectNameInput.dispatchEvent(new Event('change', { bubbles: true }));
        }

        const verificationInput = inputs.find(input =>
            input.getAttribute('aria-label')?.toLowerCase().includes('verification') ||
            input.getAttribute('name')?.toLowerCase().includes('verification') ||
            input.getAttribute('placeholder')?.toLowerCase().includes('delete my project')
        );
        if (verificationInput) {
            verificationInput.value = 'delete my project';
            verificationInput.dispatchEvent(new Event('input', { bubbles: true }));
            verificationInput.dispatchEvent(new Event('change', { bubbles: true }));
        }
    }

    // Run the function when the page is fully loaded
    window.addEventListener('load', fillForm);

    // Also run it immediately in case the page is already loaded
    fillForm();

    // Add a mutation observer to handle dynamic content loading
    const observer = new MutationObserver((mutations) => {
        for (let mutation of mutations) {
            if (mutation.addedNodes.length) {
                fillForm();
                break;
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();