Vcode.js
ソースコード:https://github.com/JofunLiang/Vcode.js
Vcode.jsは、純粋なJavaScriptで開発された軽量なキャプチャ生成プラグインです。
まずいくつかのデモを見てみましょう。
- 数字のみ
数字のみのキャプチャ
- 文字のみ
文字のみのキャプチャ
- 数字と文字の両方
数字と文字を含むキャプチャ
- カスタムデータ
カスタムデータのキャプチャ
使用方法(公式サイトからJSファイルをダウンロード):
<script src="Vcode.min.js"></script>
// または
// ES6 Modules または TypeScript
import captcha from 'Vcode'
// CommonJS
const captcha = require('Vcode')
デモ:
<div id="demo" class="demo">
<strong>キャプチャ:</strong>
<div class="captcha-display"></div>
<button type="button">変更</button>
</div>
function $(selector) {
return document.querySelector(selector);
}
// 数字のみモード
const numericCaptcha = new CaptchaGenerator({
target: "#demo .captcha-display",
length: 4,
fontSize: "60px",
mode: "numeric",
gap: 0
});
// 文字のみモード
const letterCaptcha = new CaptchaGenerator({
target: "#demo .captcha-display",
length: 4,
fontSize: "60px",
mode: "alphabetic",
gap: 0
});
// 数字と文字混合モード
const mixedCaptcha = new CaptchaGenerator({
target: "#demo .captcha-display",
length: 4,
fontSize: "60px",
gap: 0
});
// カスタムデータモード
const customCaptcha = new CaptchaGenerator({
target: "#demo .captcha-display",
data: "馬蹄声回荡在竹林间千山外江湖边月光纵横云掠过山鹰的背脊他冷眼看繁花乱掷地无声",
length: 4,
fontSize: "42px",
gap: 0
});
// キャプチャを再生成
$("#demo button").onclick = function() {
customCaptcha.regenerate();
};
パラメータ設定:
- target(文字列、必須) キャプチャを表示するCSSセレクタ
- data(文字列、オプション) カスタムキャプチャデータのソース
- length(整数、オプション、デフォルトは4) 生成するキャプチャの文字数
- mode(文字列、オプション、デフォルトは'mix'、数字と文字の混合モード) キャプチャタイプ
- fontSize(文字列、オプション) キャプチャのフォントサイズ
- gap(文字列、オプション、デフォルトは0) キャプチャ文字間の間隔
キャプチャオブジェクトのプロパティ:
- target(オブジェクト) キャプチャがマウントされる要素
- code(文字列) キャプチャの値
- data(文字列) キャプチャデータソース
- length(数値) キャプチャの長さ
- regenerate(関数) キャプチャを再生成する関数
MIT License
Copyright (c) 2018 jofunLiang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
類似プラグイン
- Vueキャプチャプラグインvue2-verify(https://github.com/mizuka-wu/vue2-verify)
- JavaScriptとcanvasベースのcaptcha.js (https://github.com/saucxs/captcha)