<html> <head> <title>Translating 1.1</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <style type="text/css"> strong a{padding-left:7px; padding-right:7px; border:1px outset; cursor:pointer;} </style> <script type="text/javascript"> var TL = { executingTime : false, TSQLReverseWord : ["@@IDENTITY","ENCRYPTION","ORDER","ADD","END","OUTER","ALL","ERRLVL","OVER","ALTER","ESCAPE","PERCENT","AND","EXCEPT","PLAN","ANY","EXEC","PRECISION","AS","EXECUTE","PRIMARY","ASC","EXISTS","PRINT","AUTHORIZATION","EXIT","PROC","AVG","EXPRESSION","PROCEDURE","BACKUP","FETCH","PUBLIC","BEGIN","FILE","RAISERROR","BETWEEN","FILLFACTOR","READ","BREAK","FOR","READTEXT","BROWSE","FOREIGN","RECONFIGURE","BULK","FREETEXT","REFERENCES","BY","FREETEXTTABLE","REPLICATION","CASCADE","FROM","RESTORE","CASE","FULL","RESTRICT","CHECK","FUNCTION","RETURN","CHECKPOINT","GOTO","REVOKE","CLOSE","GRANT","RIGHT","CLUSTERED","GROUP","ROLLBACK","COALESCE","HAVING","ROWCOUNT","COLLATE","HOLDLOCK","ROWGUIDCOL","COLUMN","IDENTITY","RULE","COMMIT","IDENTITY_INSERT","SAVE","COMPUTE","IDENTITYCOL","SCHEMA","CONSTRAINT","IF","SELECT","CONTAINS","IN","SESSION_USER","CONTAINSTABLE","INDEX","SET","CONTINUE","INNER","SETUSER","CONVERT","INSERT","SHUTDOWN","COUNT","INTERSECT","SOME","CREATE","INTO","STATISTICS","CROSS","IS","SUM","CURRENT","JOIN","SYSTEM_USER","CURRENT_DATE","KEY","TABLE","CURRENT_TIME","KILL","TEXTSIZE","CURRENT_TIMESTAMP","LEFT","THEN","CURRENT_USER","LIKE","TO","CURSOR","LINENO","TOP","DATABASE","LOAD","TRAN","DATABASEPASSWORD","MAX","TRANSACTION","DATEADD","MIN","TRIGGER","DATEDIFF","NATIONAL","TRUNCATE","DATENAME","NOCHECK","TSEQUAL","DATEPART","NONCLUSTERED","UNION","DBCC","NOT","UNIQUE","DEALLOCATE","NULL","UPDATE","DECLARE","NULLIF","UPDATETEXT","DEFAULT","OF","USE","DELETE","OFF","USER","DENY","OFFSETS","VALUES","DESC","ON","VARYING","DISK","OPEN","VIEW","DISTINCT","OPENDATASOURCE","WAITFOR","DISTRIBUTED","OPENQUERY","WHEN","DOUBLE","OPENROWSET","WHERE","DROP","OPENXML","WHILE","DUMP","OPTION","WITH","ELSE","OR","WRITETEXT"], keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", changeTab : function(obj){ var strongs = document.getElementsByTagName("strong"); for(var i = 0; i < strongs.length; i++){ strongs[i].firstChild.style.backgroundColor = "transparent"; } obj.style.backgroundColor = "lightblue"; var panels = document.getElementById("panels"); for(var i = 0; i < panels.childNodes.length; i++){ if(panels.childNodes[i].nodeType == 1 && panels.childNodes[i].tagName == "DIV"){ panels.childNodes[i].style.display = panels.childNodes[i].getAttribute("panel") == obj.getAttribute("tab") ? "block" : "none"; } } }, time : function(end){ if(end){ if(this.executingTime){ var now = new Date(); var ms = now.getTime() - this.executingTime.getTime(); var time = Math.floor((ms/60000.0)%60) >= 1 ? Math.floor((ms/60000.0)%60) + " minute(s)" : ""; time += Math.floor((ms/1000.0)%60) >= 1 ? Math.floor((ms/1000.0)%60) + " second(s) " : (time.length > 0 ? " 0 second " : ""); time += ms%1000 + " miliseconds"; document.getElementById("timer").innerHTML = time; }else{ document.getElementById("timer").innerHTML = "Error time slip."; } }else{ this.executingTime = new Date(); } }, clear : function(){ document.getElementById("InputArea").value = ""; document.getElementById("OutputArea").value = ""; }, CopyToClipboard : function(){ if (window.clipboardData){ window.clipboardData.setData("Text", document.getElementById("OutputArea").value); }else if (window.netscape){ netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); if (!clip) return; var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); if (!trans) return; trans.addDataFlavor('text/unicode'); var str = new Object(); var len = new Object(); var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); var copytext=document.getElementById("OutputArea").value; str.data=copytext; trans.setTransferData("text/unicode",str,copytext.length*2); var clipid=Components.interfaces.nsIClipboard; if (!clip) return false; clip.setData(trans,null,clipid.kGlobalClipboard); }else{ return false; } return false; }, blogger : function(reverse){ this.time(false); if(reverse){ var input = document.getElementById("InputArea").value; var chars = [{s:"\t",r:" "},{s:" ",r:" "},{s:"<",r:"<"},{s:">",r:">"},{s:"&",r:"&"}]; var temp = input; for(var i in chars){ while((input = input.replace(chars[i].r, chars[i].s)) != temp) temp = input; } document.getElementById("OutputArea").value = input; }else{ var input = document.getElementById("InputArea").value.split(""); var chars = [{s:"&",r:"&"},{s:" ",r:" "},{s:"\t",r:" "},{s:"<",r:"<"},{s:">",r:">"}]; for(var i = 0; i < input.length; i++){ for(var j in chars) input[i] = input[i].replace(chars[j].s, chars[j].r); } document.getElementById("OutputArea").value = input.join(""); } this.time(true); }, sql : function(){ this.time(false); var input = document.getElementById("InputArea").value; var wd =false; var mg = false; this.TSQLReverseWord = this.TSQLReverseWord.sort(); for(var i in this.TSQLReverseWord){ wd = this.TSQLReverseWord[i]; var pattern = new RegExp("[\\D\\W]?(" + wd + ")[\\D\\W]?", "i"); mg = input.match(pattern); if(mg){ for(var j = 0; j < mg.length; j++){ input = input.replace(mg[j].toString(), mg[j].toString().toUpperCase()); } } } document.getElementById("OutputArea").value = input; this.time(true); }, url : function(reverse){ this.time(false); if(reverse){ document.getElementById("OutputArea").value = decodeURI(document.getElementById("InputArea").value); }else{ document.getElementById("OutputArea").value = encodeURI(document.getElementById("InputArea").value); } this.time(true); }, base64 : function(reverse){ this.time(false); var input = document.getElementById("InputArea").value; if(reverse){ debugger; var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; // remove all characters that are not A-Z, a-z, 0-9, +, /, or = input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); do { enc1 = this.keyStr.indexOf(input.charAt(i++)); enc2 = this.keyStr.indexOf(input.charAt(i++)); enc3 = this.keyStr.indexOf(input.charAt(i++)); enc4 = this.keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } while (i < input.length); document.getElementById("OutputArea").value = this._utf8_decode(output); }else{ input = this._utf8_encode(input); var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; do { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this.keyStr.charAt(enc1) + this.keyStr.charAt(enc2) + this.keyStr.charAt(enc3) + this.keyStr.charAt(enc4); } while (i < input.length); document.getElementById("OutputArea").value = output; } this.time(true); }, _utf8_encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, _utf8_decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; }, ncr : function(reverse){ this.time(false); if(reverse){ var input = document.getElementById("InputArea").value; var ncr = input.match(/&#x([\da-fA-F]+);/g); var unicode = false; for(var i = 0; i < ncr.length; i++){ unicode = ncr[i].toString().replace(/&#x([\da-fA-F]+);/, '$1'); input = input.replace(ncr[i].toString(), String.fromCharCode(parseInt(unicode, 16))); } document.getElementById("OutputArea").value = input; }else{ var input = document.getElementById("InputArea").value.split(""); for(var i = 0; i < input.length; i++){ if(input[i].charCodeAt(0) < 128) continue; input[i] = "&#x" + input[i].charCodeAt(0).toString(16) + ";"; } document.getElementById("OutputArea").value = input.join(""); } this.time(true); }, properties : function(reverse){ this.time(false); if(reverse){ var input = document.getElementById("InputArea").value; var prop = input.match(/[\\]u([\da-fA-F]+)/g); var unicode = false; for(var i = 0; i < prop.length; i++){ unicode = prop[i].toString().replace(/[\\]u([\da-fA-F]+)/, '$1'); input = input.replace(prop[i].toString(), String.fromCharCode(parseInt(unicode, 16))); } document.getElementById("OutputArea").value = input; }else{ var lines = document.getElementById("InputArea").value.split("\n"); //alert(lines.length); var out = ""; var chars = []; for(var n in lines){ //alert(line); chars = lines[n].split(""); if(chars[0] != "#" && chars[0] != "!") // continue; // for comment for(var i = 0; i < chars.length; i++){ if(chars[i].charCodeAt(0) < 128) continue; chars[i] = chars[i].charCodeAt(0) > 127 ? "\\u" + chars[i].charCodeAt(0).toString(16) : chars[i]; } out += chars.join(""); } document.getElementById("OutputArea").value = out; } this.time(true); }, srt : function(){ this.time(false); var hh, mm, ss, micro; var input = document.getElementById("InputArea").value.split("\n"); var addtime = document.getElementById("addtime").value; try{ microseconds = parseInt(microseconds); }catch(e){ alert(e); return; } var arrow = " --> "; var times; for(i = 0; i < content.length; i++){ if(content[i].indexOf(arrow) > -1){ times = content[i].split(arrow); // =====開始時間===== times[0] = this.moveTimeStamp(times[0], microseconds); // =====結束時間===== times[1] = this.moveTimeStamp(times[1], microseconds); content[i] = times.join(arrow); } } document.getElementById("OutputArea").value = input.join("\n"); this.time(true); }, moveTimeStamp : function(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; } }; var JSONFormater = { indentType: "\t", source: false, output: "", format: function() { if (document.getElementById("InputArea").value.length == 0) { alert("Empty source."); return; } try { eval("JSONFormater.source = " + document.getElementById("InputArea").value + ";"); } catch (e) { alert("Invalid JSON data."); return; } this.indentType = this.selectedIndent(); this.iteratorChilds(this.source, 0, false); this.clearTails(); document.getElementById("OutputArea").value = this.output; this.output = ""; }, hasMembers: function(obj) { for (var m in obj) return true; return false; }, isArray: function(obj) { return obj.constructor == Array; }, isString: function(obj) { return obj.constructor == String; }, iteratorChilds: function(obj, indent, isMember) { if (this.isArray(obj)) { this.output += "[\n"; for (var i = 0; i < obj.length; i++) { this.iteratorChilds(obj[i], indent + 1, false); } this.clearTails(); this.output += this.currentIndent(indent); this.output += "],\n"; } else if (this.hasMembers(obj)) { if (!isMember) this.output += this.currentIndent(indent); this.output += "{\n"; for (var e in obj) { this.output += this.currentIndent(indent + 1); this.output += (this.isString(e) ? "\"" + e + "\"" : e) + ": "; this.iteratorChilds(obj[e], indent + 1, true); } this.clearTails(); this.output += this.currentIndent(indent); this.output += "},\n"; } else { if (!isMember) this.output += this.currentIndent(indent); this.output += this.isString(obj) ? "\"" + obj + "\"" : obj; this.output += ",\n"; } }, currentIndent: function(ident) { var it = ""; for (var i = 0; i < ident; i++) { it += this.indentType; } return it; }, clearTails: function() { if (this.output.length > 2) this.output = this.output.substring(0, this.output.length - 2) + "\n"; }, selectedIndent: function() { switch (document.getElementById("indentType").value) { case "1": return "\t"; case "2": return " "; case "3": return " "; case "4": return " "; case "8": return " "; } } }; window.onresize = function(){ document.getElementById("InputArea").style.height = (document.body.offsetHeight-140)/2; document.getElementById("OutputArea").style.height = (document.body.offsetHeight-140)/2; }; </script> </head> <body onload="window.onresize();"> <form> <div> <strong><a onclick="TL.changeTab(this);" tab="1" style="background-color:lightblue;">Bloger</a></strong> <strong><a onclick="TL.changeTab(this);" tab="8">Json Formater</a></strong> <strong><a onclick="TL.changeTab(this);" tab="2">SQL</a></strong> <strong><a onclick="TL.changeTab(this);" tab="3">URL</a></strong> <strong><a onclick="TL.changeTab(this);" tab="4">BASE64</a></strong> <strong><a onclick="TL.changeTab(this);" tab="5">NCR</a></strong> <strong><a onclick="TL.changeTab(this);" tab="6">Java properties</a></strong> <strong><a onclick="TL.changeTab(this);" tab="7">SRT</a></strong> </div> <div> <textarea id="InputArea" rows="7" style="width:100%;"></textarea> </div> <div> <textarea id="OutputArea" rows="7" style="width:100%;background-color:#eeeeee;" readonly="true"></textarea> </div> <div id="panels"> <div panel="1"> <h4>for Blogger post.</h4> <input type="button" value="Translate" onclick="TL.blogger();" /> <input type="button" value="Restore" onclick="TL.blogger(true);" /> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <div panel="8" style="display:none;"> <h4>Json Formater</h4> <input type="button" value="format" onclick="JSONFormater.format();" /> <select id="indentType"> <option value="1" selected="selected">indent with a tab character</option> <option value="2">indent with 2 spaces</option> <option value="3">indent with 3 spaces</option> <option value="4">indent with 4 spaces</option> <option value="8">indent with 8 spaces</option> </select> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <div panel="2" style="display:none;"> <h4>for SQL statement.</h4> <input type="button" value="Translate" onclick="TL.sql();" /> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <div panel="3" style="display:none;"> <h4>for URL encode/decode.</h4> <input type="button" value="Translate" onclick="TL.url();" /> <input type="button" value="Restore" onclick="TL.url(true);" /> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <div panel="4" style="display:none;"> <h4>for BASE64 encode/decode.</h4> <input type="button" value="Translate" onclick="TL.base64();" /> <input type="button" value="Restore" onclick="TL.base64(true);" /> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <div panel="5" style="display:none;"> <h4>Numeric Character Reference (letter code less than 128 won't be translated.)</h4> <input type="button" value="Translate" onclick="TL.ncr();" /> <input type="button" value="Restore" onclick="TL.ncr(true);" /> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <div panel="6" style="display:none;"> <h4>for Java properties file</h4> <input type="button" value="Translate" onclick="TL.properties();" /> <input type="button" value="Restore" onclick="TL.properties(true);" /> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <div panel="7" style="display:none;"> <h4>time control</h4> <input type="text" id="addtime" /> <input type="button" value="Translate" /> <input type="button" value="Clear" onclick="TL.clear();" /> <input type="button" value="Copy" onclick="TL.CopyToClipboard();" /> </div> <p id="timer"> </p> </div> </form> </body> </html>