summaryrefslogtreecommitdiff
path: root/src/options/options.html
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-09-01 20:10:20 +0900
committertanaka takashi <isazaka@gmail.com>2026-09-01 20:10:20 +0900
commit55e581bab9b600e7c070ec596d3109fc897d2d86 (patch)
tree15ca196a1858696c216946dc9608fae613ad6e5f /src/options/options.html
feat: Firefox selection translation extension with local Ollama (initial version)
Implement the complete initial version of a Firefox WebExtension (Manifest V3) that translates selected text on web pages using a local Ollama LLM and shows the result in a small popover near the selection. Specification alignment (Phase 0) - Unified Specifications.md / Design.md / Security.md on the same approach: Ollama REST API + Fetch API + NDJSON streaming (no ollama-js SDK dependency) - Fixed host_permissions to http://localhost/* and http://127.0.0.1/* because Firefox match patterns do not support port numbers (bug 1362809/1468162); the actual connection target is restricted to localhost/127.0.0.1 + any port by application-side validation (defense in depth, OLL-09) - Clipboard: use navigator.clipboard.writeText() only inside the copy button click (user activation); no deprecated execCommand fallback Implementation (zero dependencies, vanilla JS, no npm/Node required) - manifest.json: MV3, background.scripts + type:module (event page, no service_worker), action popup, options_ui, content_scripts for http/https, permissions: storage + localhost host permissions only - src/shared: constants (ports, limits, presets, error codes), message validation, settings schema (defaults / merge / sanitize / buildOptions / toApiThinking), system prompt builder (fixed prompt first + user prompt) - src/background: message-router (runtime.Port streaming + runtime.onMessage for model list), translation-session (single active request, abort previous on new request, stale chunk suppression), ollama-client (fetch against /api/tags and /api/chat with buffering NDJSON line parser tolerant to chunk boundaries inside JSON objects, AbortController, host re-validation before every request, HTTP status to error-code mapping), settings-service (storage.local load/save with validation and fallback to defaults) - src/content/content.js: single classic script (Firefox does not support ES modules in content scripts) with selection detection (selectionchange + mouseup + keyup, debounced), Shadow DOM action button, Shadow DOM popover with HIDDEN/LOADING/STREAMING/COMPLETED/ERROR state machine, port client with requestId-based stale chunk filtering, enabled-state sync via storage.onChanged; all dynamic text rendered via textContent only - src/popup + src/options: full settings UI (enable toggle, Ollama host, model list from Ollama with saved-model warning, target language, thinking mode, temperature slider 0.0-2.0 step 0.1, context length presets 4k/8k/16k/32k/128k/256k, seed random/fixed with integer value, user system prompt, advanced numeric options with steppers, stop sequences textarea) - icons generated by tools/make-icons.ps1 (System.Drawing, no external tools) - build.ps1 packages manifest.json + icons/ + src/ into dist zip, excluding tests/, doc/, ollama-js/ and tools/ Tests (71 passed, 0 failed) - In-browser test runner (tests/test.html) with custom describe/it/assert framework; no npm, no Node.js - Unit: constants sync between content mirror and shared module, Ollama host validation (localhost/127.0.0.1 + any port only; rejects external hosts, LAN IPs, https, credentials, paths), settings schema defaults and fallback, temperature 0.1-step validation, context length presets, seed modes, advanced option types, buildOptions omission of unset values and absence of tfs_z/mirostat fields, system prompt composition order, message validation with selection length boundary values - Integration: NDJSON streaming across awkward byte boundaries, thinking chunk forwarding, malformed line tolerance, error payload mapping, think/ options inclusion rules, model list, TranslationSession abort semantics, settings round-trip with storage.onChanged cache refresh, full port flow (started/chunk/completed), newer request aborts older with stale chunk discard, malformed message rejection, OLLAMA_UNAVAILABLE and INVALID_SETTINGS error paths, untrusted sender rejection Security audit (Design.md section 24 checklist: all pass) - No innerHTML/outerHTML/document.write/eval/new Function/localStorage - No remote JS/CSS/fonts/CDN resources; no inline scripts in extension pages - Ollama access limited to background; content scripts never fetch Ollama - Background validates message type/length/requestId; single concurrent translation enforced - Clipboard API only (no execCommand fallback) - Minimal permissions: storage + localhost host permissions Docs - README.md with build/load/usage instructions, API list, permission rationale - doc/Testing-Results.md with automated test results, security audit results, and a 14-item manual Firefox verification checklist (to be executed on a real Firefox + Ollama environment)
Diffstat (limited to 'src/options/options.html')
-rw-r--r--src/options/options.html104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/options/options.html b/src/options/options.html
new file mode 100644
index 0000000..b60e66b
--- /dev/null
+++ b/src/options/options.html
@@ -0,0 +1,104 @@
+<!DOCTYPE html>
+<html lang="ja">
+<head>
+ <meta charset="utf-8">
+ <title>Ollama Translations - 設定</title>
+ <link rel="stylesheet" href="options.css">
+</head>
+<body>
+ <main>
+ <h1>Ollama Translations 設定</h1>
+
+ <form id="options-form" novalidate>
+ <fieldset>
+ <legend>基本設定</legend>
+
+ <div class="field">
+ <label class="switch-label">
+ <input type="checkbox" id="enabled" role="switch">
+ 翻訳機能を有効にする
+ </label>
+ </div>
+
+ <div class="field">
+ <label for="ollama-host">Ollama Host</label>
+ <input type="text" id="ollama-host" placeholder="http://localhost:11434" spellcheck="false">
+ <p class="hint">初期版では http://localhost:&lt;port&gt; / http://127.0.0.1:&lt;port&gt; のみ接続できます。</p>
+ </div>
+
+ <div class="field">
+ <label for="model">Model</label>
+ <div class="inline">
+ <select id="model"></select>
+ <button type="button" id="reload-models">再取得</button>
+ </div>
+ <p id="model-status" class="status" hidden></p>
+ </div>
+
+ <div class="field">
+ <label for="target-language">翻訳先言語</label>
+ <select id="target-language"></select>
+ </div>
+
+ <div class="field">
+ <label for="thinking">Thinking</label>
+ <select id="thinking">
+ <option value="off">off</option>
+ <option value="on">on</option>
+ <option value="low">low</option>
+ <option value="medium">medium</option>
+ <option value="high">high</option>
+ </select>
+ </div>
+
+ <div class="field">
+ <label for="temperature">Temperature: <output id="temperature-value">0.2</output></label>
+ <input type="range" id="temperature" min="0" max="2" step="0.1" value="0.2">
+ </div>
+
+ <div class="field">
+ <label for="context-length">Context Length: <output id="context-length-value">16k</output></label>
+ <input type="range" id="context-length" min="0" max="5" step="1">
+ <p class="hint">4k / 8k / 16k / 32k / 128k / 256k</p>
+ </div>
+
+ <div class="field">
+ <span class="label-text">Seed</span>
+ <div class="segmented" role="radiogroup" aria-label="Seed mode">
+ <label><input type="radio" name="seed-mode" value="random"> 可変</label>
+ <label><input type="radio" name="seed-mode" value="fixed"> 固定</label>
+ </div>
+ <div class="inline" id="seed-value-row" hidden>
+ <label for="seed-value">固定値</label>
+ <input type="number" id="seed-value" step="1" placeholder="42">
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="user-system-prompt">ユーザー用システムプロンプト</label>
+ <textarea id="user-system-prompt" rows="3" placeholder="例: カジュアルな口調で訳してください"></textarea>
+ <p class="hint">アプリ固定プロンプトと結合して送信されます。</p>
+ </div>
+ </fieldset>
+
+ <fieldset>
+ <legend>詳細設定(未設定項目は送信されません)</legend>
+ <div id="advanced-fields"></div>
+
+ <div class="field">
+ <label for="stop">stop(1行に1シーケンス)</label>
+ <textarea id="stop" rows="3" placeholder="例: &lt;END&gt;"></textarea>
+ </div>
+ </fieldset>
+
+ <div class="actions">
+ <button type="submit" id="save">保存</button>
+ <span id="save-status" class="status" role="status"></span>
+ </div>
+ </form>
+
+ <p class="dev-link"><a href="../../tests/test.html" target="_blank" rel="noreferrer">開発者向け: テストを実行</a></p>
+ </main>
+ <script src="options.js"></script>
+</body>
+</html> \ No newline at end of file