워치 번역기 코드

워치 번역기 (KO → EN)
KR ➔ EN
번역 결과가 표시됩니다
<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <title>워치 번역기 (KO → EN)</title>
  <style>
    :root {
      --bg-color: #000000;
      --card-bg: #16181c;
      --accent: #00e5ff;
      --accent-glow: rgba(0, 229, 255, 0.25);
      --text-main: #ffffff;
      --text-muted: #8e95a5;
      --danger: #ff3b30;
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      -webkit-tap-highlight-color: transparent;
      font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Pretendard", sans-serif;
    }

    body {
      background-color: #050507;
      min-height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 16px;
    }

    /* 스마트워치 프레임 */
    .watch-container {
      width: 100%;
      max-width: 320px;
      aspect-ratio: 1 / 1;
      background-color: var(--bg-color);
      border-radius: 50%;
      border: 3px solid #24272f;
      padding: 32px 24px 24px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0, 0, 0, 0.9);
      position: relative;
      overflow: hidden;
    }

    /* 헤더 라벨 */
    .header {
      text-align: center;
      font-size: 11px;
      font-weight: 700;
      letter-spacing: 1.5px;
      color: var(--accent);
      text-transform: uppercase;
    }

    /* 입력 영역 */
    .input-box {
      width: 100%;
      height: 64px;
      background-color: var(--card-bg);
      border: 1px solid #2a2e39;
      border-radius: 16px;
      padding: 10px 14px;
      color: var(--text-main);
      font-size: 14px;
      font-weight: 500;
      resize: none;
      outline: none;
      transition: border-color 0.2s, box-shadow 0.2s;
    }

    .input-box:focus {
      border-color: var(--accent);
      box-shadow: 0 0 12px var(--accent-glow);
    }

    .input-box::placeholder {
      color: var(--text-muted);
      font-size: 13px;
    }

    /* 결과 출력 영역 */
    .output-box {
      width: 100%;
      height: 64px;
      background: linear-gradient(145deg, #101318, #181d24);
      border-radius: 16px;
      padding: 10px 14px;
      color: #79f2ff;
      font-size: 14px;
      font-weight: 600;
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      overflow-y: auto;
      word-break: break-word;
      border: 1px solid rgba(0, 229, 255, 0.15);
    }

    .output-box.empty {
      color: #4a5160;
      font-weight: 400;
      font-size: 12px;
    }

    /* 버튼 그룹 */
    .btn-group {
      display: flex;
      gap: 8px;
      width: 100%;
    }

    .btn {
      flex: 1;
      height: 38px;
      border-radius: 20px;
      border: none;
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: transform 0.1s, opacity 0.2s;
    }

    .btn:active {
      transform: scale(0.96);
    }

    .btn-reset {
      background-color: #232730;
      color: var(--danger);
      flex: 0.8;
    }

    .btn-translate {
      background: linear-gradient(135deg, #00c6ff, #0072ff);
      color: #ffffff;
      flex: 1.2;
      box-shadow: 0 4px 12px rgba(0, 114, 255, 0.35);
    }

    .btn-translate:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
  </style>
</head>
<body>

  <div class="watch-container">
    <div class="header">KR ➔ EN</div>

    <!-- 한국어 입력창 -->
    <textarea 
      id="inputText" 
      class="input-box" 
      placeholder="한국어 입력..." 
      rows="2"
    ></textarea>

    <!-- 영어 번역 결과 -->
    <div id="outputText" class="output-box empty">
      번역 결과가 표시됩니다
    </div>

    <!-- 액션 버튼 -->
    <div class="btn-group">
      <button id="resetBtn" class="btn btn-reset" onclick="resetAll()">리셋</button>
      <button id="translateBtn" class="btn btn-translate" onclick="handleTranslate()">번역</button>
    </div>
  </div>

  <script>
    const inputEl = document.getElementById('inputText');
    const outputEl = document.getElementById('outputText');
    const translateBtn = document.getElementById('translateBtn');

    // 번역 실행 함수
    async function handleTranslate() {
      const text = inputEl.value.trim();
      if (!text) {
        outputEl.classList.add('empty');
        outputEl.textContent = '내용을 입력해주세요';
        return;
      }

      translateBtn.disabled = true;
      outputEl.classList.remove('empty');
      outputEl.textContent = '번역 중...';

      try {
        const response = await fetch(
          `https://api.mymemory.translated.net/get?q=${encodeURIComponent(text)}&langpair=ko|en`
        );
        const data = await response.json();

        if (data.responseData && data.responseData.translatedText) {
          outputEl.textContent = data.responseData.translatedText;
        } else {
          outputEl.textContent = '번역 실패';
        }
      } catch (err) {
        outputEl.textContent = '네트워크 오류';
      } finally {
        translateBtn.disabled = false;
      }
    }

    // 초기화 함수
    function resetAll() {
      inputEl.value = '';
      outputEl.classList.add('empty');
      outputEl.textContent = '번역 결과가 표시됩니다';
      inputEl.focus();
    }

    // 엔터키 입력 시 자동 번역
    inputEl.addEventListener('keydown', (e) => {
      if (e.key === 'Enter' && !e.shiftKey) {
        e.preventDefault();
        handleTranslate();
      }
    });
  </script>
</body>
</html>