Skip to content

Commit 465ca5c

Browse files
committed
v 1.1.0
1 parent 9d204ae commit 465ca5c

File tree

5 files changed

+130
-18
lines changed

5 files changed

+130
-18
lines changed

README.md

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,73 @@
44

55
![video](https://github.com/user-attachments/assets/c59884bf-e87a-4a47-a028-e18eaf783d4a)
66

7+
## New Version 1.1.0
8+
9+
The new update adds the following feature:
10+
11+
1. Feature to update the problem details of problems already added to your spreadsheet
12+
13+
Requirements for this new update:
14+
15+
1. Update AppScript
16+
2. New Version of chrome-extension
17+
18+
## How to update AppScript:
19+
20+
- Your web app url remains the same even after updating your deploy
21+
22+
https://github.com/user-attachments/assets/84484cb1-668b-4abb-afa9-b84a803c4d82
23+
724
## Contribute
825

9-
Want to contribute to this chrom-extension? Go to this repo :[My Codeforces Journal Development](https://github.com/Dev-Code24/My-Codeforces-Journal-Development)
26+
Want to contribute to this Chrome extension? Check out the repository here: [My Codeforces Journal Development](https://github.com/Dev-Code24/My-Codeforces-Journal-Development).
27+
28+
### Steps to Get Started:
29+
30+
1. **Clone the Repository**
31+
Clone this repo to your local machine:
32+
33+
```bash
34+
git clone https://github.com/Dev-Code24/My-Codeforces-Journal-Development.git
35+
```
36+
37+
2. **Navigate to the Repository Directory**
38+
Open the directory where the repo is cloned and ensure you are at the root:
39+
40+
```bash
41+
cd My-Codeforces-Journal-Development
42+
```
43+
44+
3. **Create a Development Environment File**
45+
Run the following command to create an `.env.development` file:
46+
47+
```bash
48+
touch .env.development
49+
```
50+
51+
4. **Add Environment Variables**
52+
Open the `.env.development` file and add the following configuration:
53+
54+
```env
55+
VITE_DEV_OR_PROD="development"
56+
DEV_CODEFORCES_ID="your codeforces profile URL"
57+
DEV_APPSCRIPT_URL="your appscript URL"
58+
```
59+
60+
- Replace `your codeforces profile URL` with the URL of your Codeforces profile.
61+
- Replace `your appscript URL` with your Apps Script URL.
62+
63+
5. **Run the Development Server**
64+
Start the development server:
65+
66+
```bash
67+
npm run dev:chrome
68+
```
69+
70+
6. **Load the Extension in Chrome/Brave**
71+
- Open Chrome or Brave and go to `chrome://extensions`.
72+
- Turn on **Developer Mode** (toggle in the top-right corner).
73+
- Click on **Load unpacked** and select the `dist` folder located in the root of the repo you cloned.
1074

1175
## Features
1276

@@ -63,10 +127,9 @@ Before you can use the extension, make sure you have the following:
63127
#### App Script Code
64128

65129
```javascript
130+
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
66131
function doPost(e) {
67132
try {
68-
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
69-
70133
// Parse the incoming request data
71134
var data;
72135
try {
@@ -86,7 +149,7 @@ function doPost(e) {
86149
return ContentService.createTextOutput(JSON.stringify({ status: "success", exists: problemExists })).setMimeType(ContentService.MimeType.JSON);
87150
}
88151

89-
// (Your existing 'initialize' and 'addProblem' logic here)
152+
// Existing 'initialize' and 'addProblem' logic here
90153
if (data.action === "initialize") {
91154
var headers = ["Rating", "Problem", "Status", "Remarks", "Date", "Takeaway", "Topics"];
92155
if (sheet.getLastRow() === 0 || sheet.getRange("A1").getValue() === "") {
@@ -124,7 +187,7 @@ function doPost(e) {
124187
'{"status":"success","message":"Headers initialized with formatting, custom column widths, and row added."}'
125188
).setMimeType(ContentService.MimeType.TEXT);
126189
} else {
127-
return ContentService.createTextOutput('{"status":"success","message":"Headers already exist."}').setMimeType(ContentService.MimeType.TEXT);
190+
return ContentService.createTextOutput('{"status":"success","message":"Verified !."}').setMimeType(ContentService.MimeType.TEXT);
128191
}
129192
} else if (data.action === "addProblem") {
130193
try {
@@ -146,10 +209,59 @@ function doPost(e) {
146209
);
147210
}
148211
}
212+
213+
// New feature: Update problem data
214+
if (data.action === "updateProblem") {
215+
const rows = sheet.getDataRange().getValues();
216+
const problemName = data.problemName;
217+
218+
// Find the row with the matching problem name
219+
for (let i = 0; i < rows.length; i++) {
220+
if (rows[i][1] === problemName) {
221+
// Assuming column B has the problem name
222+
sheet.getRange(i + 1, 3).setValue(data.problemStatus); // Update "Status" in column C
223+
sheet.getRange(i + 1, 4).setValue(data.remarks); // Update "Remarks" in column D
224+
sheet.getRange(i + 1, 6).setValue(data.takeaways); // Update "Takeaway" in column F
225+
226+
return ContentService.createTextOutput(JSON.stringify({ status: "success", message: "Problem data updated successfully." })).setMimeType(
227+
ContentService.MimeType.JSON
228+
);
229+
}
230+
}
231+
232+
return ContentService.createTextOutput(JSON.stringify({ status: "error", message: "Problem not found." })).setMimeType(
233+
ContentService.MimeType.JSON
234+
);
235+
}
149236
} catch (error) {
150237
return ContentService.createTextOutput('{"status":"error","message":"' + error.message + '"}').setMimeType(ContentService.MimeType.TEXT);
151238
}
152239
}
240+
241+
// New feature: Handle GET requests for fetching problem data
242+
function doGet(e) {
243+
const problemName = e.parameter.problemName;
244+
const data = sheet.getDataRange().getValues();
245+
246+
// Find the row with the matching problem name
247+
const row = data.find((row) => row[1] === problemName); // Assuming column B has the problem name
248+
if (row) {
249+
return ContentService.createTextOutput(
250+
JSON.stringify({
251+
status: "success",
252+
problem: {
253+
status: row[2], // Assuming "Status" is column C
254+
remarks: row[3], // Assuming "Remarks" is column D
255+
takeaways: row[5], // Assuming "Takeaway" is column F
256+
},
257+
})
258+
).setMimeType(ContentService.MimeType.JSON);
259+
} else {
260+
return ContentService.createTextOutput(JSON.stringify({ status: "error", message: "Problem not found." })).setMimeType(
261+
ContentService.MimeType.JSON
262+
);
263+
}
264+
}
153265
```
154266

155267
## Usage

dist/assets/background.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assets/contentScript.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(){
2-
var c=(p,n,t)=>new Promise((s,r)=>{var i=e=>{try{a(t.next(e))}catch(o){r(o)}},l=e=>{try{a(t.throw(e))}catch(o){r(o)}},a=e=>e.done?s(e.value):Promise.resolve(e.value).then(i,l);a((t=t.apply(p,n)).next())});(function(){"use strict";document.body.insertAdjacentHTML("beforeend",`
2+
var m=(p,s,a)=>new Promise((e,d)=>{var i=o=>{try{t(a.next(o))}catch(r){d(r)}},n=o=>{try{t(a.throw(o))}catch(r){d(r)}},t=o=>o.done?e(o.value):Promise.resolve(o.value).then(i,n);t((a=a.apply(p,s)).next())});(function(){"use strict";document.body.insertAdjacentHTML("beforeend",`
33
<style>
44
/* Loader Styles */
55
.loader {
@@ -45,6 +45,6 @@ var c=(p,n,t)=>new Promise((s,r)=>{var i=e=>{try{a(t.next(e))}catch(o){r(o)}},l=
4545
</div>
4646
</div>
4747
</div>
48-
`),chrome.runtime.onMessage.addListener((n,t,s)=>{n.action==="openModal"&&(document.getElementById("extensionModalBackground").style.display="block",document.getElementById("modalMessage").textContent="")}),document.getElementById("cancelModalButton").addEventListener("click",()=>{document.getElementById("extensionModalBackground").style.display="none"}),document.getElementById("submitModalButton").addEventListener("click",n=>c(this,null,function*(){n.preventDefault();const t=document.getElementById("submitButtonText"),s=document.getElementById("loadingSpinner"),r=document.getElementById("loadingSpinnerWrapper");t.style.display="none",r.style.display="inline-block",s.style.display="inline-block";const i=document.getElementById("status").value,l=document.getElementById("remarks").value,a=document.getElementById("takeaways").value,e={remarks:l,takeaways:a,status:i};chrome.runtime.sendMessage({action:"submitProblem",data:e},o=>{t.style.display="inline",r.style.display="none",s.style.display="none";const d=document.getElementById("modalMessage");o.status==="success"?(d.textContent="Submission successful!",d.style.color="green"):(d.textContent=`Error: ${o.error}`,d.style.color="red")})}))})();
48+
`);let s;chrome.runtime.onMessage.addListener((e,d,i)=>{if(e.action==="openModal"&&(document.getElementById("extensionModalBackground").style.display="block",document.getElementById("modalMessage").textContent=""),e.action==="prefillModal"){const{data:n}=e,t=document.getElementById("submitButtonText");n.status==="success"&&n.problem?(s="updateProblem",t&&(t.innerText="Edit"),a(n.problem)):t&&(t.innerText="Submit")}});function a(e){document.getElementById("status").value=e.status,document.getElementById("remarks").value=e.remarks,document.getElementById("takeaways").value=e.takeaways,document.getElementById("extensionModalBackground").style.display="block"}document.getElementById("cancelModalButton").addEventListener("click",()=>{document.getElementById("extensionModalBackground").style.display="none"}),document.getElementById("submitModalButton").addEventListener("click",e=>m(this,null,function*(){e.preventDefault();const d=document.getElementById("submitButtonText"),i=document.getElementById("loadingSpinner"),n=document.getElementById("loadingSpinnerWrapper");d.style.display="none",n.style.display="inline-block",i.style.display="inline-block";const t=document.getElementById("status").value,o=document.getElementById("remarks").value,r=document.getElementById("takeaways").value,u={remarks:o,takeaways:r,status:t};s||(s="submitProblem"),chrome.runtime.sendMessage({action:s,data:u},c=>{d.style.display="inline",n.style.display="none",i.style.display="none";const l=document.getElementById("modalMessage");c.status==="success"?(l.textContent="Submission successful!",l.style.color="green"):(l.textContent=`Error: ${c.error}`,l.style.color="red")})}))})();
4949

5050
})();

0 commit comments

Comments
 (0)