Skip to content

Instantly share code, notes, and snippets.

@yoozoosato
Created Jan 11, 2012
Embed
What would you like to do?
全角英数字記号を半角英数字記号に変換するグリモンスクリプト
// ==UserScript==
// @name z2h
// @namespace http://somethingnew2.com/js/monkeys/
// @description 全角英数字を半角に変換するよ
// @author SATO Yozo
// @version 0.1
// ==/UserScript==
(function() {
var z = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@-.,:';
var h = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@-.,:';
function z2h(arg) {
if (arg.nodeType === 1) {
for (var i = 0; i < arg.childNodes.length; ++i) {
z2h(arg.childNodes[i]);
}
} else if (arg.nodeType === 3) {
for (i = 0; i < z.length; i++) {
var regex = new RegExp(z[i], "gm");
arg.nodeValue = arg.nodeValue.replace(regex, h[i]);
}
}
}
z2h(document.body);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment