Custom Validation

入力欄に禁止語句を入力した際に警告文を表示する

La data de 07-06-2022. Vezi ultima versiune.

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         Custom Validation
// @namespace    https://twitter.com/kumrnm
// @version      1.0.1
// @description  入力欄に禁止語句を入力した際に警告文を表示する
// @author       蝙蝠の目
// @license      MIT
// @match        *://*/*
// ==/UserScript==

(function() {
    'use strict';

    // 検出する語句をここで指定します(記述方法は「正規表現」でググってください)
    const pattern = /あいうえおあいうえお/;

    const excludes = new Set();

    window.addEventListener("keyup", () => {
        const elm = document.activeElement;
        if (!elm) return;
        if (excludes.has(elm)) return;
        if (elm.tagName === "INPUT" || elm.tagName === "TEXTAREA") {
            const match = elm.value.match(pattern);
            if (match) {
                if (window.confirm("[Custom Validation]\n禁止語句の入力を検出しました。削除しますか?\n(「いいえ」を選択すると、ページを閉じるまでこの入力欄に対する検査を停止します。)")) {
                    elm.value = elm.value.substring(0, match.index) + elm.value.substring(match.index + match[0].length);
                } else {
                    excludes.add(elm);
                }
            }
        }
    });

    console.log("[Custom Validation] Activated.");
})();