Skip to content

Commit 1562ce0

Browse files
committed
MERGE COMPLETED PARTLY
1 parent cc7e351 commit 1562ce0

21 files changed

+268
-2875
lines changed

README.md

+126-50
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,126 @@
1-
# React + TypeScript + Vite
2-
3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4-
5-
Currently, two official plugins are available:
6-
7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9-
10-
## Expanding the ESLint configuration
11-
12-
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13-
14-
- Configure the top-level `parserOptions` property like this:
15-
16-
```js
17-
export default tseslint.config({
18-
languageOptions: {
19-
// other options...
20-
parserOptions: {
21-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
22-
tsconfigRootDir: import.meta.dirname,
23-
},
24-
},
25-
})
26-
```
27-
28-
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
29-
- Optionally add `...tseslint.configs.stylisticTypeChecked`
30-
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
31-
32-
```js
33-
// eslint.config.js
34-
import react from 'eslint-plugin-react'
35-
36-
export default tseslint.config({
37-
// Set the react version
38-
settings: { react: { version: '18.3' } },
39-
plugins: {
40-
// Add the react plugin
41-
react,
42-
},
43-
rules: {
44-
// other rules...
45-
// Enable its recommended rules
46-
...react.configs.recommended.rules,
47-
...react.configs['jsx-runtime'].rules,
48-
},
49-
})
50-
```
1+
# LearnThat
2+
3+
Learning a language is a long and grueling process that takes years of consistent practice and dedication. LearnThat is the perfect Google Chrome Extension to help you make that journey just a little bit easier. When reading your language of choice on your laptop but coming across a word you don’t know, simply double-tap to highlight it and pull up the definition. However, instead of being just a more accessible dictionary, LearnThat will also store the words you don’t know in memory and allow you to access all these words later for you to review!
4+
5+
6+
# MVP
7+
8+
- Double-click on a word (highlight it) to pull up its definition and save it to a vocabulary list
9+
- Click to hear word pronunciation
10+
- Keep track of how many times each word is double-tapped, and display a short quiz of the most double-tapped words often
11+
- Sort different vocabulary words into folders
12+
- Display the “Word You Struggled the Most With” based on data from the past x days
13+
14+
15+
# Stretch Goals
16+
17+
- Keep track of the context that you last saw the word in
18+
- Feature to write your own definition of a word (for slang)
19+
- Display stats of the most saved words, total words searched up
20+
- Allow user to manually type in a word to save (for audio)
21+
- Generate a random daily word in target language for them to practice
22+
- Quiz game feature to practice words (like Quizlet Matching)
23+
24+
# Tech Stack
25+
26+
- React
27+
- Firebase
28+
- Translation API (tbd)
29+
- Google Chrome Extension
30+
31+
# Things to Install
32+
33+
- IDE: <a href = "https://visualstudio.microsoft.com/"> Visual Studio</a>
34+
- Version Control: <a href = "https://git-scm.com/downloads"> Git </a>
35+
- React: <a href = "https://reactjs.org/docs/create-a-new-react-app.html"> React
36+
37+
# Tutorials
38+
- <a href = "https://www.youtube.com/watch?v=0n809nd4Zu4&pp=ygUlaG93IHRvIG1ha2UgYSBnb29nbGUgY2hyb21lIGV4dGVuc2lvbg%3D%3D"> Build a Chrome Extension (for beginners!) </a>
39+
- <a href = "https://www.youtube.com/watch?v=uV4L-wcnK3Y&pp=ygUlaG93IHRvIG1ha2UgYSBnb29nbGUgY2hyb21lIGV4dGVuc2lvbg%3D%3D"> Create a Chrome Extension for beginners </a>
40+
- <a href = "https://www.youtube.com/watch?v=Tn6-PIqc4UM&pp=ygUNd2hhdCBpcyByZWFjdA%3D%3D"> React in 100 Seconds </a>
41+
- <a href = "https://www.youtube.com/watch?v=SqcY0GlETPk&t=485s&pp=ygUOcmVhY3QgdHV0b3JpYWw%3D"> React Tutorial for beginners</a>
42+
- <a href = "https://www.youtube.com/watch?v=4d-gIPGzmK4&list=PL4cUxeGkcC9itfjle0ji1xOZ2cjRGY_WB"> Playlist with a bunch of great Firebase tutorials</a>
43+
44+
45+
# Timeline
46+
47+
#### Week 1:
48+
- Decide on roles
49+
- Confirm app MVP and discuss any other features to be added
50+
- Download software, set up environment and Git, watch tutorials
51+
52+
#### Week 2:
53+
- Learn how to create UI for Google Chrome extensions, research existing extensions for inspo
54+
- Create wireframes and get feedback
55+
- User authentication with Firebase
56+
57+
#### Week 3:
58+
- Get a definition popup when text is highlighlighted
59+
- Decide on a translation API and start getting definitions
60+
- Finalize front-end design after getting input
61+
- Start coding the front-end
62+
63+
#### Week 4:
64+
- Code the front-end of pop-up code display
65+
- Code Home Page
66+
- Keep working on getting a definition pop-up when text is highlighted
67+
- Add API functionality to the definition pop-up
68+
69+
#### Week 5:
70+
- Code the Login page
71+
- Code Settings page
72+
- Store the number of times a word is looked up
73+
- Make the saved words show up in the webpage
74+
75+
#### Week 6:
76+
- Integrate the front-end and back-end
77+
- Ensure that everything connects properly
78+
79+
#### Week 7:
80+
- Code the Vocabulary Page to display history of words
81+
- Display the most frequently searched word of the past 7 days
82+
- Calculate the most frequently searched word of the past 7 days
83+
84+
#### Week 8:
85+
- Add animations to the front-end for extra style points
86+
- begin working on presentation
87+
88+
#### Week 9:
89+
- Finish presentation and being practicing
90+
- Brainstorm fun ideas for presentation
91+
92+
#### Week 10:
93+
- Prepare for presentation and live demo!
94+
95+
# Competition/Inspiration
96+
- Toucan
97+
- Readlang
98+
99+
# Github CheatSheet!
100+
Master cheatsheet: https://www.atlassian.com/dam/jcr:8132028b-024f-4b6b-953e-e68fcce0c5fa/atlassian-git-cheatsheet.pdf
101+
102+
Some basic ones:
103+
| Command | Description |
104+
| --- | --- |
105+
| cd "LearnThat" | Change directories to our repository |
106+
| git branch | Lists branches for you |
107+
| git branch "branch name" | Makes a new branch |
108+
| git checkout "branch name" | Switch to branch |
109+
| git checkout -b "branch name" | Same as the 2 previous commands together |
110+
| git add . | Finds all changed files |
111+
| git commit -m "Testing123" | Commit with message |
112+
| git push origin "branch" | Push to branch |
113+
| git pull origin "branch" | Pull updates from a specific branch |
114+
115+
# Developers
116+
- Oudom Pach
117+
- Ranvir Patel
118+
- Jakob Kuhnen
119+
- Chuanjie Duanmu
120+
121+
# Project Manager
122+
- Kacie Yee
123+
124+
# Industry Mentor
125+
- Joanna Borba
126+
File renamed without changes.

public/background.js background.js

File renamed without changes.

contentscript.js

+136-39
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,144 @@
1-
// The file for highlighting the word and making it show up in the browser
2-
document.addEventListener('mouseup', () => {
3-
const highlightedText = window.getSelection().toString().trim();
4-
5-
if (highlightedText.length > 0) {
6-
console.log("The word highlighted by the user is: ", highlightedText);
7-
fetch('http://localhost:3000/translate', {
8-
method: 'POST',
9-
headers: {
10-
'Content-Type': 'application/json',
11-
},
12-
body: JSON.stringify({
13-
text: highlightedText, // The text to translate
14-
targetLanguage: 'es' // Use the selected language
15-
}),
16-
})
17-
.then(response => {
18-
if (!response.ok) {
19-
throw new Error('Network response was not ok: ' + response.statusText);
1+
//The file for highlighting the word and making it show up in the browser 4
2+
3+
document.addEventListener('mouseup', (event) => {
4+
const selectedText = window.getSelection().toString().trim();
5+
6+
if (selectedText.length > 0) {
7+
const selection = window.getSelection();
8+
if (selection.rangeCount > 0) {
9+
const range = selection.getRangeAt(0);
10+
11+
// Get the bounding box of the selected text
12+
const rect = range.getBoundingClientRect();
13+
//This is how the tooltip gets the highlighted text and translated text
14+
function fetchTranslation(text) {
15+
fetch('http://localhost:3000/translate', {
16+
method: 'POST',
17+
headers: {
18+
'Content-Type': 'application/json',
19+
},
20+
body: JSON.stringify({
21+
text: text, // Text to translate
22+
targetLanguage: 'es'
23+
}),
24+
})
25+
.then(response => response.json())
26+
.then(data => {
27+
console.log('Translation:', data.translation);
28+
29+
// Update the tooltip with the translated text
30+
let tooltip = document.getElementById('tooltip');
31+
if (tooltip) {
32+
tooltip.innerHTML = ` Selected Text: ${selectedText} <br> Translation: ${data.translation} <br>
33+
<button id="saveButton">Save</button> `;
34+
35+
}
36+
return data.translation;
37+
})
38+
.catch(error => {
39+
console.error('Error fetching translation:', error);
40+
});
2041
}
21-
return response.json();
22-
})
23-
.then(data => {
24-
console.log('Translated text: ', data.translation);
25-
})
26-
.catch(error => {
27-
console.error('Error fetching translation:', error);
28-
});
42+
43+
44+
45+
// Call your translation API
46+
translation = fetchTranslation(selectedText);
47+
48+
// Show the tooltip with translation (keeping the blue highlight)
49+
showTooltip(event, translation, selectedText, rect);
50+
51+
52+
53+
}
54+
} else {
55+
// Hide tooltip if no text is selected
56+
hideTooltip();
2957
}
3058
});
3159

32-
// Instructions to run this properly:
33-
/*
34-
1. Install necessary packages:
35-
npm install dotenv cors express
60+
// Tooltip logic
61+
function showTooltip(event, translation, text, rect) {
62+
let tooltip = document.getElementById('tooltip');
63+
64+
if (!tooltip) {
65+
tooltip = document.createElement('div');
66+
tooltip.id = 'tooltip';
67+
tooltip.style.position = 'absolute';
68+
tooltip.style.backgroundColor = '#fff';
69+
tooltip.style.border = '1px solid #ccc';
70+
tooltip.style.padding = '50px';
71+
tooltip.style.zIndex = '1000';
72+
tooltip.style.visibility = 'hidden';
73+
document.body.appendChild(tooltip);
74+
}
75+
76+
//tooltip.textContent = `The phrase highlighted is: ${text} Translation: ${translation}`;
77+
78+
79+
tooltip.style.left = `${rect.left + window.scrollX + rect.width / 2}px`; // Align tooltip horizontally
80+
tooltip.style.top = `${rect.top + window.scrollY - 40}px`; // Position tooltip above the selected text
81+
tooltip.style.visibility = 'visible';
82+
83+
}
3684

37-
2. Go to translate.js for more npm installations:
38-
npm install @google-cloud/translate
39-
npm install @google-cloud/text-to-speech
40-
npm install @google-cloud/storage
41-
npm install fs
85+
function hideTooltip() {
86+
const tooltip = document.getElementById('tooltip');
87+
if (tooltip) {
88+
tooltip.style.visibility = 'hidden';
89+
}
90+
}
4291

43-
3. Start the server:
44-
node translate.js (to host the server for our base URL)
92+
//ignore this
93+
/*function updateTooltip(translation, text) {
94+
const tooltip = document.getElementById('tooltip');
95+
if (tooltip) {
96+
// Update the tooltip content with the actual translation
97+
tooltip.textContent = `Selected Text: ${text}\nTranslation: ${translation}`;
98+
}
99+
}*/
100+
/*
101+
// Translation logic
102+
function fetchTranslation(text) {
103+
fetch('http://localhost:3000/translate', {
104+
method: 'POST',
105+
headers: {
106+
'Content-Type': 'application/json',
107+
},
108+
body: JSON.stringify({
109+
text: text, // Text to translate
110+
targetLanguage: 'es'
111+
}),
112+
})
113+
.then(response => response.json())
114+
.then(data => {
115+
console.log('Translation:', data.translation);
45116
46-
4. Make sure to stop the server (control + C in terminal) when done to prevent unnecessary API calls.
117+
// Update the tooltip with the translated text
118+
let tooltip = document.getElementById('tooltip');
119+
if (tooltip) {
120+
tooltip.textContent = ` Translation: ${data.translation}`;
121+
}
122+
return data.translation;
123+
})
124+
.catch(error => {
125+
console.error('Error fetching translation:', error);
126+
});
127+
}
47128
*/
129+
// Hide the tooltip when the selection is cleared (mouse is clicked outside the selected text)
130+
document.addEventListener('mousedown', hideTooltip);
131+
132+
133+
134+
135+
//to run this properly:
136+
/*
137+
npm install dotenv
138+
npm install cors
139+
npm install express
140+
node translate.js (to host the server for our base url)
141+
When done make sure to control c in terminal or else whenever you highlight stuff on your laptop the api will be called
142+
and we will run out of requests
143+
*/
144+
File renamed without changes.

public/offscreen.js offscreen.js

File renamed without changes.

0 commit comments

Comments
 (0)