Skip to content

Commit e5a47f4

Browse files
committed
add more comments
1 parent 8879a1b commit e5a47f4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/js/background.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Constant for sidebar toggle command name
12
const sidebarToggle = "_execute_sidebar_action";
23

34
// Update UI and set value of textbox
@@ -15,6 +16,8 @@ function openSidebar() {
1516
browser.sidebarAction.toggle();
1617
}
1718

19+
// Listen for clicks on the browser action (toolbar icon)
1820
browser.browserAction.onClicked.addListener(openSidebar);
1921

22+
// Initialize UI when DOM is ready
2023
document.addEventListener("DOMContentLoaded", updateUI);

src/js/tabnotes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
var timeoutId;
22
const notes = document.getElementById("notes");
3+
// Add event listener for keyup to save notes automatically
34
document.addEventListener("keyup", logKey);
45

6+
// Determine browser type and set appropriate browser object
57
const browser_type = getBrowser();
68
if (browser_type === "Chrome") {
79
var browser_obj = chrome;
810
} else {
911
var browser_obj = browser;
1012
}
1113

14+
// Listen for tab and window focus changes
1215
browser_obj.tabs.onActivated.addListener(tabOpen);
1316
browser_obj.windows.onFocusChanged.addListener(tabOpen);
1417

18+
// Debounce the save operation to prevent too frequent storage updates
1519
function logKey(e) {
1620
clearTimeout(timeoutId);
1721
timeoutId = setTimeout(function () {
1822
saveToDB();
1923
}, 10);
2024
}
2125

26+
// Detect browser type for compatibility
2227
function getBrowser() {
2328
if (typeof chrome !== "undefined") {
2429
if (typeof browser !== "undefined") {
@@ -31,6 +36,7 @@ function getBrowser() {
3136
}
3237
}
3338

39+
// Save notes to browser's sync storage
3440
function saveToDB() {
3541
data = {
3642
tab_note: document.querySelector("#notes").value,
@@ -42,6 +48,7 @@ function saveToDB() {
4248
}
4349
}
4450

51+
// Load notes when tab changes or window focuses
4552
function tabOpen(tab) {
4653
if (browser_type === "Chrome") {
4754
chrome.storage.sync.get(["tab_note"], function (result) {
@@ -58,6 +65,7 @@ function tabOpen(tab) {
5865
}
5966
}
6067

68+
// Initialize notes when page loads
6169
window.addEventListener("load", () => {
6270
tabOpen();
6371
});

0 commit comments

Comments
 (0)