codeconv_o20.htm

戻る

<!DOCTYPE HTML>
<HTML LANG="ja">

<HEAD>
<META CHARSET="Shift_JIS">
<TITLE>文字コード変換</TITLE>
<STYLE TYPE="text/css">
<!--
#opt::-webkit-scrollbar {display:none}
-->
</STYLE>
</HEAD>

<BODY STYLE="background-color:#CCFFFF">
<CENTER>
<B>文字コード変換 (Opera 20)</B>
<BR><BR>

<FORM ID="form" ACTION="about:blank" TARGET="target">
<TABLE>
<TR><TD NOWRAP>
入力文字コード:
<INPUT TYPE=TEXT ID="i_enc" SIZE=30>
<SPAN STYLE="position:relative">
<INPUT TYPE=BUTTON VALUE="選択" onClick="sel_opt(this, elem_i_enc)" STYLE="position:relative">
</SPAN>
<INPUT TYPE=BUTTON ID="in" VALUE="読み込み" onClick="input()" STYLE="margin-left:1em">
</TD></TR>
<TR><TD NOWRAP>
出力文字コード:
<INPUT TYPE=TEXT ID="o_enc" SIZE=30>
<SPAN STYLE="position:relative">
<INPUT TYPE=BUTTON VALUE="選択" onClick="sel_opt(this, elem_o_enc)" STYLE="position:relative">
</SPAN>
<SPAN STYLE="margin-left:1em">改行:</SPAN>
<SELECT ID="le">
<OPTION>LF
<OPTION>CR
<OPTION>CR+LF
</SELECT>
<INPUT TYPE=BUTTON ID="out" VALUE="書き出し" onClick="output()" STYLE="margin-left:1em">
</TD></TR>
<TR><TD>
<TEXTAREA NAME="d" ID="data" ROWS=20 COLS=80 WRAP="OFF"></TEXTAREA>
</TD></TR>
</TABLE>

<SELECT ID="opt" SIZE=5 STYLE="position:absolute; left:0; top:0; z-index:1; display:none">
<OPTION>ISO-8859-1
<OPTION>ISO-2022-JP
<OPTION>Shift_JIS
<OPTION>EUC-JP
<OPTION>UTF-8
</SELECT>
</FORM>

</CENTER>

<IFRAME NAME="target" ID="frame" WIDTH=1 HEIGHT=1 SRC="about:blank" STYLE="display:none"></IFRAME>
<A ID="dl" STYLE="display:none"></A>

<SCRIPT TYPE="text/javascript">
<!--

function sel_opt(sel, enc) {
  elem_sel = sel;
  elem_enc = enc;
  elem_opt.selectedIndex = 0;
  elem_sel.parentNode.appendChild(elem_opt);
  elem_opt.style.display = "";
  elem_opt.focus();
}

function opt_click() {
  elem_enc.value = elem_opt.value;
  elem_opt.style.display = "none";
}

function opt_keydown(e) {
  switch(e.keyCode) {
  case 13:  // Enter
    elem_enc.value = elem_opt.value;
    // fall thru
  case 27:  // Esc
    elem_opt.style.display = "none";
    break;
  }
}

function opt_blur() {
  elem_opt.style.display = "none";
}

// 読み込み
function input() {
  elem_in.disabled = elem_out.disabled = true;
  setTimeout(enable_btn, 100);
  // ファイルを開く
  elem_file = document.createElement("INPUT");
  elem_file.type = "FILE";
  elem_file.onchange = input2;
  elem_file.click();
}

function enable_btn() {
  elem_in.disabled = elem_out.disabled = false;
}

function input2() {
  elem_in.disabled = elem_out.disabled = true;
  var src = "<HTML>"
          + "<HEAD>"
          + "<META CHARSET='" + elem_i_enc.value.trim() + "'>"
          + "</HEAD>"
          + "<BODY>"
          + "<IFRAME ID='frame2' WIDTH=1 HEIGHT=1 SRC='about:blank'></IFRAME>"
          + "</BODY>"
          + "</HTML>";
  elem_frame.onload = input3;
  elem_frame.src = URL.createObjectURL(new Blob([src], {type: "text/html"}));
}

function input3() {
  elem_frame.onload = null;
  elem_frame2 = elem_frame.contentDocument.getElementById("frame2");
  // フレームにレンダリングする
  elem_frame2.onload = input4;
  elem_frame2.src = URL.createObjectURL(
    // 取得した File に MIME タイプを付加した Blob を作る
    new Blob([elem_file.files.item(0)], {type: "text/plain"}));
}

function input4() {
  elem_frame2.onload = null;
  // フレームから変換結果を取り出す
  elem_data.value = elem_frame2.contentDocument.body.textContent;
  elem_in.disabled = elem_out.disabled = false;
}

// 書き出し
function output() {
  elem_in.disabled = elem_out.disabled = true;
  // フォームの文字エンコーディングをセットして送信
  elem_form.acceptCharset = elem_o_enc.value.trim();
  elem_frame.onload = output2;
  elem_form.submit();
}

function output2() {
  elem_frame.onload = null;
  // フレームから URL を取り出す
  var str = elem_frame.contentDocument.location.search.substring(3).replace(/\+/g, "%20");
                                                            // ?d= の後ろを取り出し,スペースを %20 に変換
  switch(elem_le.selectedIndex) {  // 改行
  case 0:  // LF
    str = str.replace(/%0[Dd]/g, "");
    break;
  case 1:  // CR
    str = str.replace(/%0[Aa]/g, "");
    break;
  }
  // 変換結果をダウンロードする
  elem_dl.href = "data:application/octet-stream," + str;
  elem_dl.click();
  elem_in.disabled = elem_out.disabled = false;
}

  elem_form = document.getElementById("form");
  elem_i_enc = document.getElementById("i_enc");
  elem_in = document.getElementById("in");
  elem_o_enc = document.getElementById("o_enc");
  elem_le = document.getElementById("le");
  elem_out = document.getElementById("out");
  elem_data = document.getElementById("data");
  elem_opt = document.getElementById("opt");
  elem_frame = document.getElementById("frame");
  elem_dl = document.getElementById("dl");

  elem_opt.onclick = opt_click;
  elem_opt.onkeydown = opt_keydown;
  elem_opt.onblur = opt_blur;

//-->
</SCRIPT>

</BODY>

</HTML>