// 2015.08.19-2015.08.28
// localStorage
// 2015.04.24
// 整理しました
// 2014.12.28
// 配列に変えました
//Copyright (c) 2014-2015 nicotan
//Released under the MIT license
//http://opensource.org/licenses/mit-license.php
var INITIAL = ["000000","001011","001101","001110","010011","011001","011100","010101","010110","011010"];
var STARTBAR = ["a","b","W","d","X","f","g","h","i","j"];
var BAR = [
["0","1","2","3","4","5","6","7","8","9"],
["A","B","C","D","E","F","G","H","I","J"],
["L","M","N","O","P","Q","R","S","T","U"]
];
function Conv() {
p( 0 , "");
namesInput = document.getElementsByName("iJ");
for ( n = 0 ; n < 10 ; n++) {
if ( namesInput[n].value != "" ) {
var ans = conversion( namesInput[n].value )
p( 1, "<li>" + ans + "</li>" );
var tmp = namesInput[n].value.replace(/[\"\'\\\<\>\{\}]/g,"");
jansave(n, namesInput[n].value, ans);
} else {
p( 1, "<li></li>" );
}
}
}
function conversion(n) {
if ( !isNaN( n ) ) {
len = n.length;
switch ( len ) {
case 7:
return Seven(n);
case 8:
return Seven(n);
case 12:
return Twelve(n);
case 13:
return Twelve(n);
default:
return "桁数がちがいます";
}
} else {
return "数値を入力してください。";
}
}
function jancd( strJancode ) {
var g = 0, k = 0, h = 0;
for ( i = 0 ; i < 12 ; i += 2 ) {
g += parseInt( strJancode.charAt( i + 1 ) );
k += parseInt( strJancode.charAt( i ) );
}
h = ( g * 3 + k ) % 10;
return h == 0 ? 0 : 10 - h ;
}
function Seven( n ) {
var strJanfont = "Y";
for ( i = 0 ; i < 4 ; i++ ) { strJanfont += n.charAt( i ); }
strJanfont = strJanfont + "K";
for ( i = 4 ; i < 7 ; i++ ) { strJanfont += BAR[2][parseInt( n.charAt( i ) )]; }
strJanfont += BAR[2][jancd("00000" + n)];
return strJanfont += "Z";
}
function Twelve(n){
var numIni = parseInt(n.charAt(0));
var strJanfont = STARTBAR[numIni];
for ( i = 0 ; i < 6 ; i++ ) { strJanfont += BAR[parseInt(INITIAL[numIni].charAt(i))][parseInt(n.charAt(i+1))]; }
strJanfont += "K";
for ( i = 7 ; i < 12 ; i++ ) { strJanfont += BAR[2][parseInt( n.charAt(i) )]; }
strJanfont += BAR[2][jancd( n )];
return strJanfont += "Z";
}
function setFocus(i, kc) {
if ( kc == 13 ) {
inputs = document.getElementsByName("iJ");
if ( inputs[i] != undefined ) {
inputs[i].focus();
}
}
}
function Clear() {
p( 0 , "" );
namesInput = document.getElementsByName("iJ");
var memo = document.getElementsByName("memo");
for ( n = 0 ; n < 10 ; n++) {
namesInput[n].value = "";
memo[n].value = "";
}
}
function textArea() {
// dom textarea id=taRight の中身を消す
var idR = document.getElementById("taRight");
idR.value = "";
// dom textarea id=taLeft の value を取得
var idL = document.getElementById("taLeft");
t = idL.value;
// 1本のテキストとして t に入ってるので改行コードで分割し配列にする
var aCode = t.split(/\r\n|\r|\n/);
// 最後が空白なら削除する
if ( aCode[aCode.length - 1] == "") {
aCode.pop();
}
var idM = document.getElementById("taMemo");
memo = idM.value;
aMemo = memo.split(/\r\n|\r|\n/);
// メモが途中まででも最大値を作成する
aMemo[aCode.length] = "";
// i メモ追加用
var i = 0;
// 1個ずつ取り出して変換させる
aCode.forEach (
function textAreaRight(value) {
if ( !isNaN(value) ) {
if ( value != "") {
len = value.length;
switch ( len ) {
case 7:
str = Seven(value);
break;
case 8:
str = Seven(value);
break;
case 12:
str = Twelve(value);
break;
case 13:
str = Twelve(value);
break;
default:
str = "桁数が間違っています。";
}
} else {
str = "";
}
} else {
str = "数値を入力してください"
}
// ほぞん
var janmemo = "";
aMemo[i] == undefined ? janmemo = "" : janmemo = aMemo[i];
var tmp = str + ":" + janmemo;
localStorage.setItem(value, tmp);
i++;
// カキコ
idR.value += str + "\r\n";
}
);
var html = aCode.length + "件の変換と保存が完了しました<br>";
ok_message( "ta_ok", html);
}
function ok_message(id, html){
var elem = document.getElementById(id);
elem.innerHTML = html;
}
function ClearT() {
// dom textarea id=taRight の中身を消す
var idR = document.getElementById("taRight");
idR.value = "";
// dom textarea id=taLeft の中身を消す
var idL = document.getElementById("taLeft");
idL.value = "";
var idM = document.getElementById("taMemo");
idM.value = "";
ok_message("ta_ok", "");
}
function p( type , Str ) {
obj = document.getElementById("Output");
switch ( type ) {
case 0:
obj.innerHTML = Str;
break;
case 1:
saved = obj.innerHTML;
obj.innerHTML = saved + Str;
break;
}
}
function jansave( i, key, value ) {
var obj = document.getElementsByName("memo");
value = value + ":" + obj[i].value;
localStorage.setItem(key, value);
}
function janload() {
var obj = document.getElementById("print");
obj.innerHTML = "";
var print_m = document.getElementById("print_memo");
var print_f = document.getElementById("print_fontstr");
print_m.value = "";
print_f.value = "";
var html = "";
html += "<ul class=\"ulsaved\">";
if ( localStorage.length != 0) {
for ( var i = 0; i < localStorage.length; i++ ) {
var key = localStorage.key(i);
var value = localStorage.getItem( key );
var tmp = value.split(":");
var str = tmp[0];
var memo = tmp[1].replace(/[\"\'\<\>]/g,""); // "
var checkbox = "<li><input type=\"checkbox\" name=\"selectjan\" jan=\"" + key + "\" value=\"" + str + "\" memo=\"" + memo + "\" onclick=\"print_fontstr();\">";
html += checkbox + key + ":" + memo + " => " + str + "";
}
html += "<ul>";
obj.innerHTML = html;
}
}
function print_fontstr() {
var obj = document.getElementsByName("selectjan");
var print_m = document.getElementById("print_memo");
var print_f = document.getElementById("print_fontstr");
print_m.value = "";
print_f.value = "";
if ( obj[0] != undefined ) {
for ( i = 0; i < obj.length; i++ ) {
if ( obj[i].checked ) {
print_m.value += obj[i].getAttribute("memo") + "\n";
print_f.value += obj[i].value + "\n";
}
}
}
}
function delete_localstorage(){
var checkbox = document.getElementsByName("selectjan");
if ( confirm("選択したものを削除します") ) {
if ( checkbox[0] != undefined ) {
for ( i = 0; i < checkbox.length; i++ ) {
if ( checkbox[i].checked ) {
localStorage.removeItem( localStorage.key(i) );
}
}
}
}
}
function dis_delbtn(c) {
var btndel = document.getElementById("btndel");
if ( c.checked ) {
btndel.disabled = false;
} else {
btndel.disabled = true;
}
}
function all_delete() {
if ( confirm("保存されているJANコードをすべて削除します(localStorage.clear())") ) {
localStorage.clear();
}
}
window.onload = function() {
janload();
var c = document.getElementById("c_dis");
c.checked = false;
dis_delbtn(c);
}