Phabricator Auto Fill Summary/Test Plan

自动填充 Summary 和 Test Plan

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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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         Phabricator Auto Fill Summary/Test Plan
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动填充 Summary 和 Test Plan
// @match        https://code.yangqianguan.com/differential/revision/attach/*
// @grant        GM_xmlhttpRequest
// @license MIT
// ==/UserScript==
(function() {
    'use strict';

    const commitMessageURL = "http://127.0.0.1:8899/commit_message";

    GM_xmlhttpRequest({
        method: "GET",
        url: commitMessageURL,
        onload: function(response) {
            const commitMsg = response.responseText;
const lines = commitMsg.split('\n');
        const titleLine = lines[0].trim();
        const titleField = document.querySelector('input[name="title"]');
        if (titleField) titleField.value = titleLine;

        const summaryMatch = commitMsg.match(/Summary:\s*([\s\S]*?)\nTest Plan:/);
            const testPlanMatch = commitMsg.match(/Test Plan:\s*([\s\S]*?)(?:\n[A-Z][a-z]+:|$)/);

            if(summaryMatch) {
                const summaryField = document.querySelector('textarea[name="summary"]');
                if(summaryField) summaryField.value = summaryMatch[1].trim();
            }

            if(testPlanMatch) {
                const testPlanField = document.querySelector('textarea[name="testPlan"]');
                if(testPlanField) testPlanField.value = testPlanMatch[1].trim();
            }
        }
    });
})();