CodeMatirx MR Title Input Validation

Validate CodeMatirx MR input field content with regex pattern ^(fix|feat|docs|doc|refactor|test|style|ci|chore|revert)(\(.*\))?!?: .+

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         CodeMatirx MR Title Input Validation
// @license MIT
// @namespace    https://git.woa.com/
// @version      1.0
// @description  Validate CodeMatirx MR input field content with regex pattern ^(fix|feat|docs|doc|refactor|test|style|ci|chore|revert)(\(.*\))?!?: .+
// @author       kerwinpeng
// @match        https://git.woa.com/CodeMatrix/CodeMatrix/merge_requests/new?*
// @match        http://git.woa.com/CodeMatrix/CodeMatrix/merge_requests/new?*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    setTimeout(function() {
        const pattern = /^(fix|feat|docs|doc|refactor|test|style|ci|chore|revert)(\(.*\))?!?: .+/;
        const inputField = document.querySelector('.tg-input__input');
        if(!pattern.test(inputField.value)) {
           inputField.value='feat(qta): '+inputField.value
        }

        inputField.addEventListener('input', (event) => {
            const inputValue = event.target.value.trim();
            //console.log(inputValue)
            const isValid = pattern.test(inputValue);
            if (!isValid) {
                inputField.setCustomValidity('MR标题不符合正则  pattern:'+pattern);
                inputField.reportValidity();
                inputField.value='feat(qta): '+inputField.value
            } else {
                inputField.setCustomValidity('符合标准');
            }
        });
   }, 3000);
})();