Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
4 changes: 4 additions & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
node_modules
packages
package-lock.json
5 changes: 5 additions & 0 deletions frontend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": true,
"singleQuote": false,
"trailingComma": "es5"
}
75 changes: 38 additions & 37 deletions frontend/background.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@

chrome.runtime.onMessage.addListener((request, _, sendResponse) => {
if (request.type === "TRANSLATE_CODE") {
const BACKEND_URL = process.env.BACKEND_URL;

chrome.storage.sync.get(['targetLanguage'], (result) => {
const targetLanguage = result.targetLanguage || 'Java';
fetch(BACKEND_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
code: request.code,
targetLanguage: targetLanguage,
}),
})
.then(response => {
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
return response.json();
})
.then(data => {

if (data.error) {
sendResponse({ error: data.error });
} else {
sendResponse({ translation: data.translation });
}
})
.catch(error => {
if (request.type === "TRANSLATE_CODE") {
const BACKEND_URL = process.env.BACKEND_URL;

console.error("Error calling backend:", error);
sendResponse({ error: `Failed to connect to the translation service: ${error.message}` });
});
chrome.storage.sync.get(["targetLanguage"], (result) => {
const targetLanguage = result.targetLanguage || "Java";
fetch(BACKEND_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
code: request.code,
targetLanguage: targetLanguage,
}),
})
.then((response) => {
if (!response.ok) {
throw new Error(
`Network response was not ok: ${response.statusText}`
);
}
return response.json();
})
.then((data) => {
if (data.error) {
sendResponse({ error: data.error });
} else {
sendResponse({ translation: data.translation });
}
})
.catch((error) => {
console.error("Error calling backend:", error);
sendResponse({
error: `Failed to connect to the translation service: ${error.message}`,
});
});
});

return true;
}
});
return true;
}
});
18 changes: 10 additions & 8 deletions frontend/build.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import esbuild from 'esbuild';
import 'dotenv/config';
import esbuild from "esbuild";
import "dotenv/config";

const define = {};
for (const k in process.env) {
define[`process.env.${k}`] = JSON.stringify(process.env[k]);
define[`process.env.${k}`] = JSON.stringify(process.env[k]);
}

esbuild.build({
entryPoints: ['scripts/content.js', 'background.js'],
esbuild
.build({
entryPoints: ["scripts/content.js", "background.js"],
bundle: true,
outdir: 'dist',
outdir: "dist",
define: define,
}).catch(() => process.exit(1));
})
.catch(() => process.exit(1));

console.log('Build complete. Files are in the /dist folder.');
console.log("Build complete. Files are in the /dist folder.");
Loading