-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle-script.js
41 lines (37 loc) · 1.34 KB
/
google-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function doGet(e) {
var ss = SpreadsheetApp.openByUrl("LINK TO SPREADSHEET");
var sheet = ss.getSheetByName("Notes");
var name = e.parameter.name;
var note = e.parameter.note;
var link = e.parameter.link;
// If name is "load", return all notes along with their names and links
if (name == "load") {
var data = sheet.getDataRange().getValues();
var notes = {};
for (var i = 1; i < data.length; i++) {
notes[data[i][2]] = [data[i][0], data[i][1]];
}
return ContentService.createTextOutput(JSON.stringify(notes));
}
// If note is empty, delete row
if (note == "") {
var data = sheet.getDataRange().getValues();
for (var i = 1; i < data.length; i++) {
if (data[i][2] == link) {
sheet.deleteRow(i + 1);
return ContentService.createTextOutput("Note deleted");
}
}
}
// Check if link already exists
var data = sheet.getDataRange().getValues();
for (var i = 1; i < data.length; i++) {
if (data[i][2] == link) {
sheet.getRange(i + 1, 2).setValue(note);
return ContentService.createTextOutput("Note updated");
}
}
// Otherwise, add new row
sheet.appendRow([name, note, link]);
return ContentService.createTextOutput("Note added");
}