Custom Validation

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

Versione datata 07/06/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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