diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..78d7ecd --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "Split Translator Development", + "image": "mcr.microsoft.com/devcontainers/javascript-node:22-bookworm", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {} + }, + "postCreateCommand": "npm install", + "customizations": { + "vscode": { + "extensions": [ + "github.vscode-github-actions", + "ms-vscode.vscode-typescript-next" + ] + } + }, + "remoteUser": "node" +} \ No newline at end of file diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml new file mode 100644 index 0000000..947e8ad --- /dev/null +++ b/.github/workflows/copilot-setup-steps.yml @@ -0,0 +1,33 @@ +name: "Copilot Setup Steps" + +on: + workflow_dispatch: + push: + paths: + - .github/workflows/copilot-setup-steps.yml + pull_request: + paths: + - .github/workflows/copilot-setup-steps.yml + +jobs: + # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. + copilot-setup-steps: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "22" + + - name: Install JavaScript dependencies + run: npm install + + - name: Build TypeScript project + run: npm run build diff --git a/README.md b/README.md index bf76b57..ad387d5 100644 --- a/README.md +++ b/README.md @@ -110,21 +110,57 @@ split-translator/ | **Screen Resolution** | Minimum width of 800px is recommended | | **Browser Version** | Chrome 88+, Edge 88+ (Manifest V3 required) | -## 🛠️ Development & Customization +## 🛠️ Development & Building -### Adjusting Window Overlap -```javascript -const OVERLAP_PIXELS = 8; // Adjustable in background.js +This extension is built with **TypeScript** for enhanced type safety and maintainability. + +### Prerequisites +- Node.js (v22 or higher) +- npm + +### Building from Source +```bash +# Install dependencies +npm install + +# Build TypeScript to JavaScript +npm run build + +# Clean build directory +npm run clean + +# Watch for changes during development +npm run watch + +# Build and package for distribution +npm run package +``` + +### Project Structure +``` +src/ + ├── background.ts # Service worker (TypeScript) + ├── popup.ts # Popup script (TypeScript) +dist/ + ├── background.js # Compiled service worker + ├── popup.js # Compiled popup script +``` + +### Development & Customization + +#### Adjusting Window Overlap +```typescript +const OVERLAP_PIXELS = 8; // Adjustable in src/background.ts ``` -### Adding a Language +#### Adding a Language ```html ``` -### Timeout Setting -```javascript +#### Timeout Setting +```typescript await waitForTabReady(tabId, 3000); // 3 seconds timeout ``` diff --git a/build-package.bat b/build-package.bat index f3173cc..cd10d06 100644 --- a/build-package.bat +++ b/build-package.bat @@ -13,7 +13,7 @@ if exist "dist\split-translator.zip" del "dist\split-translator.zip" echo [*] Creating package... REM Create ZIP file using PowerShell -powershell -Command "& { Add-Type -AssemblyName System.IO.Compression.FileSystem; $zip = [System.IO.Compression.ZipFile]::Open('dist\split-translator.zip', 'Create'); $files = @('manifest.json', 'popup.html', 'popup.js', 'background.js', 'LICENSE', 'PRIVACY_POLICY.md'); foreach ($file in $files) { if (Test-Path $file) { [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $file, $file) | Out-Null; Write-Host \"+ $file\" } }; if (Test-Path 'icons') { Get-ChildItem 'icons\*.png' | ForEach-Object { [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $_.FullName, 'icons\' + $_.Name) | Out-Null; Write-Host \"+ icons\$($_.Name)\" } }; $zip.Dispose() }" +powershell -Command "& { Add-Type -AssemblyName System.IO.Compression.FileSystem; $zip = [System.IO.Compression.ZipFile]::Open('dist\split-translator.zip', 'Create'); $files = @('manifest.json', 'popup.html', 'dist\popup.js', 'dist\background.js', 'LICENSE', 'PRIVACY_POLICY.md'); foreach ($file in $files) { if (Test-Path $file) { [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $file, $file) | Out-Null; Write-Host \"+ $file\" } }; if (Test-Path 'icons') { Get-ChildItem 'icons\*.png' | ForEach-Object { [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $_.FullName, 'icons\' + $_.Name) | Out-Null; Write-Host \"+ icons\$($_.Name)\" } }; $zip.Dispose() }" echo. echo [OK] Package created successfully: dist\split-translator.zip diff --git a/manifest.json b/manifest.json index 2cc9e3a..f7252ff 100644 --- a/manifest.json +++ b/manifest.json @@ -22,7 +22,7 @@ } }, "background": { - "service_worker": "background.js" + "service_worker": "dist/background.js" }, "icons": { "16": "icons/icon-16.png", diff --git a/package.json b/package.json index cc73da6..91f223e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,11 @@ "url": "https://github.com/SIkebe/split-translator/issues" }, "scripts": { - "package": "build-package.bat" + "build": "tsc", + "watch": "tsc --watch --preserveWatchOutput", + "package": "npm run build && build-package.bat", + "clean": "rimraf dist", + "dev": "npm run clean && npm run build && echo 'Development build complete. Load dist/ folder in Chrome Extensions.'" }, "keywords": [ "browser-extension", @@ -31,13 +35,15 @@ }, "license": "MIT", "devDependencies": { - "@types/chrome": "0.0.329" + "@types/chrome": "0.0.329", + "rimraf": "6.0.1", + "typescript": "5.8.3" }, "files": [ "manifest.json", "popup.html", - "popup.js", - "background.js", + "dist/popup.js", + "dist/background.js", "icons/", "LICENSE", "PRIVACY_POLICY.md", diff --git a/popup.html b/popup.html index 7e00244..07bfdb1 100644 --- a/popup.html +++ b/popup.html @@ -228,6 +228,6 @@