Skip to content

Commit 8eb37bc

Browse files
committed
Updated - 8/12/24
1 parent 83f5d8f commit 8eb37bc

File tree

4 files changed

+175
-47
lines changed

4 files changed

+175
-47
lines changed

README.md

+56-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,62 @@
1818
<hr />
1919
</div>
2020

21-
# Notebook
21+
# Notebook [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Follow%20Me)](https://twitter.com/ninjeeter)
2222

23-
A note taking plugin for Caido.
23+
**Notebook** is a frontend note taking plugin for [Caido](https://github.com/caido).
2424

25-
## 🏎️ Usage
25+
This plugin gives you the ability to consolidate your notes as you work directly within the Caido application.
2626

27-
1. `pnpm install`
28-
1. Make some modifications in `src`
29-
1. `pnpm build`
30-
1. Upload the plugin.zip in the `dist-zip` folder to your Caido instance
27+
## Features/Abilities:
28+
29+
- Notes can be added manually or via highlight selecting and using the context menu shortcut.
30+
- Easily send requests and responses to be added as note entries.
31+
- Note entries include date and time stamps.
32+
- If you were working within a Project when the note was added - the Project name will be included.
33+
- Note row panes can be expanded/condensed.
34+
- Add additional comments to the note entries - helpful for providing additional information on requests/responses.
35+
- Notes are available globally across all Projects.
36+
- Easily edit notes after they have been added.
37+
- Delete individual notes or clear the entire table at once.
38+
39+
![image](https://raw.githubusercontent.com/caido-community/notebook/main/notebook_screenshot.png)
40+
41+
## Installation: Documentation Example
42+
43+
If you are looking for the version of the **Notebook** plugin created in the [documentation guide](https://docs.caido.io/guides/plugins/notebook.html):
44+
45+
1. Go to the [Notebook Releases tab](https://github.com/caido-community/notebook/releases) and download the latest `notebook_v1.0.0.zip` package.
46+
2. In your Caido instance, navigate to the `Plugins` page, click `Install Package` and select the downloaded `notebook_v1.0.0.zip` package.
47+
3. Done! 🎉
48+
49+
## Installation: Latest
50+
51+
For **Notebook** with additional features:
52+
53+
1. Go to the [Notebook Releases tab](https://github.com/caido-community/notebook/releases) and download the latest release.
54+
2. In your Caido instance, navigate to the `Plugins` page, click `Install Package` and select the downloaded package.
55+
3. Done! 🎉
56+
57+
## Instructions
58+
59+
### To add a note:
60+
1. Supply input in the textarea located at the bottom and click the `Add Note` button.
61+
2. Highlight select text within a request/response pane and click the `>_ Commands` button located at the topbar in the upper-right corner. Search/Select `Add Note to Notebook`.
62+
3. Highlight select text within a request/response pane and open the context menu by right-clicking. Hover over the `Plugins` item and select `Add Note to Notebook`.
63+
4. `CTRL+C` within request and response panes and `CTRL+V` into the textarea.
64+
65+
### To edit a note:
66+
1. Click inside the note column.
67+
2. Unfocus once done.
68+
69+
### To add a comment:
70+
1. Supply input in the textarea in the third column.
71+
2. Unfocus once done.
72+
73+
### To clear all notes:
74+
***This will reset the notes in storage. This action cannot be undone.***
75+
1. Click the `>_ Commands` button located at the topbar in the upper-right corner. Search/Select `Clear Notes in Notebook`.
76+
77+
## Contribution
78+
79+
If you'd like to request a feature, suggest an improvement or report a bug - please [create a Github Issue](https://github.com/caido-community/notebook/issues).

public/style.css

+46-19
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,85 @@
44

55
#notesTable {
66
width: 100%;
7-
border-collapse: collapse;
7+
border-collapse: collapse; /* Ensures that table borders do not double up */
88
}
99

1010
/* Allow user to select text */
11-
#notesTable tbody {
12-
user-select: text;
13-
-webkit-user-select: text;
11+
#notesTable td {
12+
user-select: auto;
13+
-webkit-user-select: auto;
1414
}
1515

1616
#notesTable td:nth-child(1) {
1717
width: 200px;
1818
white-space: pre-wrap;
1919
text-align: left;
20-
border: 1px solid black;
21-
padding: 5px;
20+
padding: 8px;
21+
box-sizing: border-box;
2222
}
2323

2424
#notesTable td:nth-child(2) {
2525
width: auto;
2626
white-space: pre-line;
2727
word-wrap: break-word;
2828
text-align: left;
29-
border-top: 1px solid black;
30-
border-bottom: 1px solid black;
31-
border-left: 1px solid black;
32-
padding-right: 5px;
33-
padding-left: 5px;
29+
padding: 8px;
30+
box-sizing: border-box;
3431
}
3532

3633
#notesTable td:nth-child(3) {
37-
width: 50px;
38-
border-right: 1px solid black;
39-
border-bottom: 1px solid black;
40-
border-top: 1px solid black;
41-
vertical-align: top;
34+
width: 250px;
35+
white-space: pre-wrap;
36+
text-align: left;
37+
padding: 8px;
38+
box-sizing: border-box;
4239
}
4340

41+
/* Style for the textareas in the third column */
4442
.text-area {
4543
width: 100%;
4644
resize: none;
45+
box-sizing: border-box;
4746
}
4847

49-
.center {
50-
text-align: center;
48+
.text-area-edit {
49+
width: 100%;
50+
resize: vertical;
51+
overflow: auto;
52+
box-sizing: border-box;
53+
white-space: pre-wrap;
54+
word-wrap: break-word;
5155
}
5256

57+
/* Additional styling for textarea in table */
58+
.comment-text-area {
59+
border: 1px solid #ccc;
60+
padding: 4px;
61+
border-radius: 4px;
62+
min-width: 230px;
63+
min-height: 75px;
64+
color: goldenrod;
65+
}
66+
67+
/* General table styling */
5368
.table-container {
5469
overflow: auto;
5570
max-height: 100%;
5671
max-width: 100%;
5772
}
5873

74+
.table-container table td {
75+
border: 1px solid black;
76+
padding: 5px;
77+
}
78+
79+
/* Button container styling */
5980
.button-container {
6081
display: flex;
6182
justify-content: space-between;
6283
}
6384

85+
/* Text and color styling */
6486
.bold-brown {
6587
font-weight: bold;
6688
color: #b49566;
@@ -82,4 +104,9 @@
82104
.datetime-cell {
83105
vertical-align: top;
84106
color: #d1bfa5;
85-
}
107+
}
108+
109+
/* Center align utility */
110+
.center {
111+
text-align: center;
112+
}

src/index.ts

+72-20
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ const addNoteStorage = async (
2323
datetime: string,
2424
note: string,
2525
projectName?: string,
26+
comment?: string,
2627
) => {
2728
const currentNotes = getNotes(caido);
28-
const updatedNotes = [...currentNotes, { datetime, note, projectName }];
29+
const updatedNotes = [...currentNotes, { datetime, note, projectName, comment: "" }];
2930
await caido.storage.set({ notes: updatedNotes });
3031

3132
// Print added note to console.
@@ -64,6 +65,8 @@ const addNoteMenu = async (caido: Caido) => {
6465

6566
// Add the note to storage.
6667
await addNoteStorage(caido, datetime, currentSelect, projectName);
68+
69+
caido.window.showToast(`${currentSelect} added to Notebook.`, {variant: "info", duration: 5000})
6770
}
6871
}
6972
};
@@ -85,9 +88,17 @@ const addPage = (caido: Caido) => {
8588
const instructions = document.createElement("p");
8689
instructions.innerHTML = `<span class="bold-brown">To add a note:</span><br>
8790
1. Supply input in the textarea located at the bottom and click the <span class="light-brown">Add Note</span> button.<br>
88-
2. Click the <span class="light-brown">>_ Commands</span> button located at the topbar in the upper-right corner. Search/Select <span class="light-brown">Add Note to Notebook</span>. Supply input in the prompt and click <span class="light-brown">OK</span>.<br>
91+
2. Highlight select text within a request/response pane and click the <span class="light-brown">>_ Commands</span> button located at the topbar in the upper-right corner. Search/Select <span class="light-brown">Add Note to Notebook</span>.<br>
8992
3. Highlight select text within a request/response pane and open the context menu by right-clicking. Hover over the <span class="light-brown">Plugins</span> item and select <span class="light-brown">Add Note to Notebook</span>.<br>
90-
4. <span class="light-brown">CTRL+C</span> and <span class="light-brown">CTRL+V</span> within request and response panes is available as well but <span class="red">ensure to deselect the text and unfocus the pane to avoid needing to restart the Caido application.</span><br>***Copying within panes using <span class="light-brown">Copy</span> from the right-click context menu is functional as normal.***<br>
93+
4. <span class="light-brown">CTRL+C</span> within request and response panes and <span class="light-brown">CTRL+V</span> into the textarea.<br>
94+
<br>
95+
<span class="bold-brown">To edit a note:</span><br>
96+
1. Click inside the note column.<br>
97+
2. Unfocus once done.<br>
98+
<br>
99+
<span class="bold-brown">To add a comment:</span><br>
100+
1. Supply input in the textarea in the third column.<br>
101+
2. Unfocus once done.<br>
91102
<br>
92103
<span class="bold-brown">To clear all notes:</span><br>
93104
<span class="bold-red">***This will reset the notes in storage. This action cannot be undone.***</span><br>
@@ -170,33 +181,74 @@ const displayNotes = (caido: Caido, notes: PluginStorage["notes"] | undefined) =
170181
const row = table.insertRow();
171182
const datetimeCell = row.insertCell();
172183
const noteCell = row.insertCell();
173-
const removeCell = row.insertCell();
184+
const commentCell = row.insertCell(); // New cell for comments
174185

175-
datetimeCell.textContent = `${note.datetime} Project: ${note.projectName}`;
176-
datetimeCell.classList.add("datetime-cell");
177-
noteCell.textContent = note.note;
186+
// Create container for datetime text and delete button
187+
const datetimeContainer = document.createElement("div");
188+
datetimeContainer.classList.add("datetime-container");
189+
190+
// DateTime text
191+
const datetimeText = document.createElement("span");
192+
datetimeText.textContent = `${note.datetime} Project: ${note.projectName}`;
193+
datetimeText.classList.add("datetime-text");
178194

179-
// `Remove note.` button.
195+
// `Remove note.` button
180196
const removeNoteButton = caido.ui.button({
181197
variant: "primary",
182198
label: "Delete",
183199
trailingIcon: "fas fa-trash-can",
184200
size: "small"
185201
});
186-
202+
187203
removeNoteButton.addEventListener("click", async () => {
188204
const currentNotes = getNotes(caido);
189-
const indexToRemove = currentNotes.length - 1;
190-
191-
if (indexToRemove !== -1) {
192-
currentNotes.splice(indexToRemove, 1);
193-
await caido.storage.set({ notes: currentNotes });
194-
195-
displayNotes(caido, currentNotes);
196-
}
197-
});
198-
removeCell.appendChild(removeNoteButton);
199-
});
205+
const updatedNotes = currentNotes.filter((_, i) => i !== index);
206+
207+
await caido.storage.set({ notes: updatedNotes });
208+
displayNotes(caido, updatedNotes);
209+
});
210+
211+
// Append text and button to container
212+
datetimeContainer.appendChild(datetimeText);
213+
datetimeContainer.appendChild(removeNoteButton);
214+
215+
// Add container to datetime cell
216+
datetimeCell.appendChild(datetimeContainer);
217+
datetimeCell.classList.add("datetime-cell");
218+
219+
// Editable div for note
220+
const editableNote = document.createElement("div");
221+
editableNote.contentEditable = "true";
222+
editableNote.spellcheck = false;
223+
editableNote.textContent = note.note;
224+
editableNote.classList.add("text-area-edit");
225+
226+
editableNote.addEventListener("blur", async () => {
227+
// Update the note in storage when editing is finished
228+
const updatedNotes = [...notes];
229+
updatedNotes[index].note = editableNote.textContent || "";
230+
await caido.storage.set({ notes: updatedNotes });
231+
displayNotes(caido, updatedNotes);
232+
});
233+
234+
noteCell.appendChild(editableNote);
235+
236+
// Create textarea for comments
237+
const commentTextarea = document.createElement("textarea");
238+
commentTextarea.placeholder = "Add your comments here...";
239+
commentTextarea.value = note.comment || ""; // Use existing comment if present
240+
commentTextarea.classList.add("comment-text-area");
241+
242+
commentTextarea.addEventListener("blur", async () => {
243+
// Update the comment in storage when editing is finished
244+
const updatedNotes = [...notes];
245+
updatedNotes[index].comment = commentTextarea.value;
246+
await caido.storage.set({ notes: updatedNotes });
247+
displayNotes(caido, updatedNotes);
248+
});
249+
250+
commentCell.appendChild(commentTextarea);
251+
})
200252
};
201253

202254
export const init = (caido: Caido) => {

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export type PluginStorage = {
2-
notes: { datetime: string; note: string; projectName?: string }[];
2+
notes: { datetime: string; note: string; projectName?: string; comment?: string; }[];
33
}

0 commit comments

Comments
 (0)