<html> <head> <title>轉換</title> <style type="text/css"> b a{padding-left:7px; padding-right:7px; border:1px outset; cursor:pointer;} </style> <script type="text/javascript"> // 顯示功能 function changeFrame(id, max){ for(i = 1; i <= max; i++){ document.getElementById("label" + i).style.backgroundColor = "white"; document.getElementById("frame" + i).style.display = "none"; } document.getElementById("label" + id).style.backgroundColor = "lightblue"; document.getElementById("frame" + id).style.display = "block"; } // 計算經過時間 function timeSpend(){ this.t = (new Date()).getTime(); this.end = function(){ this.t = (new Date()).getTime() - this.t; return "總共經過 : " + Math.floor(this.t / 1000) + " 秒 " + this.t % 1000; } } // 建立 AJAX物件 function getXMLHTTP(){ var xmlHttp = false; // Ajax /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { xmlHttp = false; } } @end @*/ if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); } return xmlHttp; } var xmlHttp = false; function setTextArea(){ document.getElementById("before").innerHTML = xmlHttp.responseText; } // 讀檔 function readFile(objId){ xmlHttp = getXMLHTTP(); xmlHttp.onreadystatechange = setTextArea; var file = document.getElementById(objId).value; while(file != file.replace("\\", "/")){ file = file.replace("\\", "/"); } xmlHttp.open("GET", "file:///"+file); xmlHttp.send(null); } </script> </head> <body> <b> <a id="label1" onclick="changeFrame(1,4);" style="background-color:lightblue;">properties檔案轉換</a> <a id="label2" onclick="changeFrame(2,4);">發文轉換</a> <a id="label3" onclick="changeFrame(3,4);">字幕調整</a> <a id="label4" onclick="changeFrame(4,4);">NCR</a> </b> <textarea id="before" rows="7" style="width:100%;"></textarea> <br> <textarea id="after" rows="7" style="width:100%;background-color:#eeeeee;" readOnly="true"></textarea> <hr> <p id="ts"></p> <div id="frame1"> <input type="button" id="action" value="轉換"> <input type="button" id="redo" value="還原"> <input type="button" value="重置" onclick="reset();"> <!-- <input type="file" id="file1"> <input type="button" value="讀檔" onclick="readFile('file1');"> --> <p>說明 : 轉換 Java 的 properties 檔案</p> </div> <script type="text/javascript"> document.getElementById("action").onclick = function(){ var ts = new timeSpend(); // 計算時間 var chars = new Array(); var context = document.getElementById("before").value; for(i = 0; i < context.length; i++){ chars[i] = context.charCodeAt(i) > 127 ? "\\u" + context.charCodeAt(i).toString(16) : context.charAt(i); } document.getElementById("after").value = chars.join(""); document.getElementById("ts").innerHTML = ts.end(); // 顯示經過時間 } function reset(){ document.getElementById("after").value = ""; document.getElementById("before").value = ""; } document.getElementById("redo").onclick = function(){ var ts = new timeSpend(); // 計算時間 var source = document.getElementById("before").value.split(""); var chars = new Array(); var temp; while(source.length > 0){ temp = source.shift(); if(temp == "\\"){ if((temp = source.shift()) == "u"){ // u code = source.shift(); // 16進位數第4位數 code += source.shift(); // 16進位數第3位數 code += source.shift(); // 16進位數第2位數 code += source.shift(); // 16進位數第1位數 c = parseInt(code, 16); // 轉成10進位 chars.push(String.fromCharCode(c)); // 轉回原文 }else{ chars.push(temp); } }else{ chars.push(temp); } } document.getElementById("after").value = chars.join(""); document.getElementById("ts").innerHTML = ts.end(); // 顯示經過時間 } </script> <div id="frame2" style="display:none;"> <input type="button" id="action2" value="轉換"> <input type="button" value="重置" onclick="reset();"> <p>說明 : 轉換發 blog 的 HTML 特殊字元</p> </div> <script type="text/javascript"> document.getElementById("action2").onclick = function(){ var ts = new timeSpend(); // 計算時間 var mapping = new Array("&", " ", "\t", "<", ">"); var mapped = new Array("&", " ", " ", "<", ">"); var context = document.getElementById("before").value.split(""); var stemp = new Array(); var s; while(context.length > 0){ s = context.shift(); for(i = 0; i < mapping.length; i++){ if(mapping[i] == s){ s = mapped[i]; break; } } stemp.push(s); } document.getElementById("after").value = stemp.join(""); document.getElementById("ts").innerHTML = ts.end(); // 顯示經過時間 } </script> <div id="frame3" style="display:none;"> 時間 : <input type="text" id="microseconds"> <input type="button" id="action3" value="調整"> <input type="button" value="重置" onclick="reset();"> <p>說明 : 調整字幕檔 *.srt 的時間</p> </div> <script type="text/javascript"> document.getElementById("action3").onclick = function(){ var ts = new timeSpend(); // 計算時間 var microseconds = document.getElementById("microseconds").value; var hh, mm, ss, micro; try{ microseconds = parseInt(microseconds); }catch(e){ alert("Input is not a number."); return; } var content = document.getElementById("before").value.split("\n"); var times; for(i = 0; i < content.length; i++){ if(content[i].indexOf(" --> ") > -1){ times = content[i].split(" --> "); // =====開始時間===== times[0] = doCal(times[0], microseconds); // =====結束時間===== times[1] = doCal(times[1], microseconds); content[i] = times.join(" --> "); } } document.getElementById("after").value = content.join("\n"); document.getElementById("ts").innerHTML = ts.end(); // 顯示經過時間 } // 計算時間 function doCal(time, microseconds){ hhTemp = time.substring(0,2); mmTemp = time.substring(3,5); ssTemp = time.substring(6,8); microTemp = time.substring(9,12); // 去掉字首的 0 (原因 : 在parseInt時會出錯) hhTemp = hhTemp.substring(0,1) == "0" ? hhTemp.substring(1, hhTemp.length) : hhTemp; mmTemp = mmTemp.substring(0,1) == "0" ? mmTemp.substring(1, mmTemp.length) : mmTemp; ssTemp = ssTemp.substring(0,1) == "0" ? ssTemp.substring(1, ssTemp.length) : ssTemp; while(microTemp.substring(0,1) == "0" && microTemp.length > 1){ microTemp = microTemp.substring(1, microTemp.length); } hhTemp = parseInt(hhTemp); mmTemp = parseInt(mmTemp); ssTemp = parseInt(ssTemp); microTemp = parseInt(microTemp); //換成 timeStamp計算 timeStamp = microTemp + ssTemp * 1000 + mmTemp * 60 * 1000 + hhTemp * 60 * 60 * 1000; // 加上位移時間 timeStamp += microseconds; microTemp = timeStamp % 1000; ssTemp = Math.floor((timeStamp % 60000) / 1000); mmTemp = Math.floor((timeStamp % 3600000) / 60000); hhTemp = Math.floor((timeStamp % 216000000) / 3600000); // 轉為字串 hhTemp = ("" + hhTemp).length == 1 ? ("0" + hhTemp) : ("" + hhTemp); mmTemp = ("" + mmTemp).length == 1 ? ("0" + mmTemp) : ("" + mmTemp); ssTemp = ("" + ssTemp).length == 1 ? ("0" + ssTemp) : ("" + ssTemp); while(("" + microTemp).length < 3){ microTemp = "0" + microTemp; } // 寫回資料 return hhTemp + ":" + mmTemp + ":" + ssTemp + "," + microTemp; } </script> <div id="frame4" style="display:none;"> <input id="action4" type="button" value="轉換"> <input id="redo4" type="button" value="還原"> <input type="button" value="重置" onclick="reset();"> <p>說明 : Numeric Character Reference, 網頁用多國語表示法 (字碼小於128者不做轉換) </div> <script type="text/javascript"> document.getElementById("action4").onclick = function(){ var ts = new timeSpend(); // 計算時間 var context = document.getElementById("before").value.split(""); for(i = 0; i < context.length; i++){ if(context[i].charCodeAt(0) < 128) continue; context[i] = "&#x" + context[i].charCodeAt(0).toString(16) + ";"; } document.getElementById("after").value = context.join(""); document.getElementById("ts").innerHTML = ts.end(); // 顯示經過時間 } document.getElementById("redo4").onclick = function(){ var ts = new timeSpend(); // 計算時間 var context = document.getElementById("before").value.split(""); var chars = new Array(); for(i = 0; i < context.length; i++){ if(context[i] == "&" && context[i+1] == "#" && context[i+2] == "x"){ i += 3; var code = ""; while(context[i] != ";"){ code += context[i]; i++; } chars.push(String.fromCharCode(parseInt(code, 16))); }else{ chars.push(context[i]); } } //alert(chars.join("")); document.getElementById("after").value = chars.join(""); document.getElementById("ts").innerHTML = ts.end(); // 顯示經過時間 } </script> </body> </html>