diff --git a/main.js b/main.js index acecd24..2b30d08 100644 --- a/main.js +++ b/main.js @@ -108,7 +108,7 @@ function errorHandling(e, err) { else message += ": 다시 한 번 시도해주세요."; } else if (errorCode.startsWith('N2MT')) { message = "번역 오류"; - if (errorCode == "N2MT08") message += ": 문장이 너무 길어요!"; + if (errorCode == "N2MT08") message += ": 문장이 너무 길어요!"; // up to 5000 characters. else message += ": 다시 한 번 시도해주세요."; } } diff --git a/views/window.js b/views/window.js index 422643c..52b16d4 100644 --- a/views/window.js +++ b/views/window.js @@ -14,18 +14,7 @@ button.onclick = function() { // should subdivide error handling. window.document.getElementById("translated-text").value = result; } - - if (result.length > 60) { - window.document.getElementById("translated-text").style.fontSize = "16px"; - } else if (result.length > 45) { - window.document.getElementById("translated-text").style.fontSize = "22px"; - } else if (result.length > 30) { - window.document.getElementById("translated-text").style.fontSize = "27px"; - } else if (result.length > 15) { - window.document.getElementById("translated-text").style.fontSize = "32px"; - } else { - window.document.getElementById("translated-text").style.fontSize = "40px"; - } + setTextFontSize(result, "translated-text"); }); }; @@ -40,20 +29,8 @@ const searchPress = function(e) { }; const search = window.document.getElementById("text"); search.onkeyup = function(event) { - const text = window.document.getElementById("text").value; - - if (text.length > 60) { - window.document.getElementById("text").style.fontSize = "16px"; - } else if (text.length > 45) { - window.document.getElementById("text").style.fontSize = "22px"; - } else if (text.length > 30) { - window.document.getElementById("text").style.fontSize = "27px"; - } else if (text.length > 15) { - window.document.getElementById("text").style.fontSize = "32px"; - } else { - window.document.getElementById("text").style.fontSize = "40px"; - } - + const text = window.document.getElementById("text").value;s + setTextFontSize(text, "text"); return searchPress(event); }; @@ -99,3 +76,18 @@ function setSourceText(text) { window.document.getElementById("translated-text").value = text; return text; } + +function setTextFontSize(text, elementId) { + if (text.length > 60) { + window.document.getElementById(elementId).style.fontSize = "16px"; + } else if (text.length > 45) { + window.document.getElementById(elementId).style.fontSize = "22px"; + } else if (text.length > 30) { + window.document.getElementById(elementId).style.fontSize = "27px"; + } else if (text.length > 15) { + window.document.getElementById(elementId).style.fontSize = "32px"; + } else { + window.document.getElementById(elementId).style.fontSize = "40px"; + } + return text.length; +}