Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Created October 25, 2008 00:15
Show Gist options
  • Save cherenkov/19633 to your computer and use it in GitHub Desktop.
Save cherenkov/19633 to your computer and use it in GitHub Desktop.
// @name morse_code_decoder
// @edit by http://d.hatena.ne.jp/Cherenkov
// @description かな文字専用。モールスを選択してから実行する。
//this script based on
//http://www6.ocn.ne.jp/~miz2/morse.htm
kanalist = new Array(
"あ/--・--","い/・-","う/・・-","え/-・---","お/・-・・・",
"か/・-・・","き/-・-・・","く/・・・-","け/-・--","こ/----",
"が/・-・・ ・・","ぎ/-・-・・ ・・","ぐ/・・・- ・・","げ/-・-- ・・","ご/---- ・・",
"さ/-・-・-","し/--・-・","す/---・-","せ/・---・","そ/---・",
"ざ/-・-・- ・・","じ/--・-・ ・・","ず/---・- ・・","ぜ/・---・ ・・","ぞ/---・ ・・",
"た/-・","ち/・・-・","つ/・--・","て/・-・--",
"と/・・-・・","だ/-・ ・・","ぢ/・・-・ ・・","づ/・--・ ・・","で/・-・-- ・・","ど/・・-・・ ・・",
"な/・-・","に/-・-・","ぬ/・・・・","ね/--・-","の/・・--",
"は/-・・・","ひ/--・・-","ふ/--・・","へ/・","ほ/-・・",
"ば/-・・・ ・・","び/--・・- ・・","ぶ/--・・ ・・","べ/・ ・・","ぼ/-・・ ・・",
"ぱ/-・・・ ・・--・","ぴ/--・・- ・・--・","ぷ/--・・ ・・--・","ぺ/・ ・・--・","ぽ/-・・ ・・--・",
"ま/-・・-","み/・・-・-","む/-","め/-・・・-","も/-・・-・",
"や/・--","ゆ/-・・--","よ/--",
"ら/・・・","り/--・","る/-・--・","れ/---","ろ/・-・-",
"わ/-・-","ゐ/・-・・-","","ゑ/・--・・","を/・---","ん/・-・-・","゛/・・","゜/・・--・","-/・--・-"
);
suzilist = new Array(
"1/・----","2/・・---","","3/・・・--","4/・・・・-",
"5/・・・・・","6/-・・・・","7/--・・・","8/---・・","9/----・","0/-----",
"\r/・-・-・・"," /","  /","/ ","/ ","/"
);
function chg(){
chgtype = 1;
aft = "";
//変換後の文字列
switch(chgtype)
{
case 1:
//和文に変換の場合
list = kanalist.concat(suzilist);
syougou = 1;
kekka = 0;
bfr = window.getSelection().focusNode.data.split(" ");
num = bfr.length;
break;
}
listnum = list.length;
for(i=0;i<=num-1;i++)
{
chr = (syougou == 0) ? bfr.charAt(i) : bfr[i];
for (h=0;h<listnum;h++)
{
mozi = list[h].split("/");
if (mozi[syougou]==chr)
{
break;
}
}
aft = aft + mozi[kekka] + " ";
}
alert(aft);
}
chg();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment