-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwriteToday.js
More file actions
96 lines (79 loc) · 3.17 KB
/
Copy pathwriteToday.js
File metadata and controls
96 lines (79 loc) · 3.17 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const buttons = document.querySelectorAll(".btn");
const dashboard = document.querySelector(".dashboardDiv");
const textareas = document.querySelectorAll("textarea");
const saveBtn = document.getElementById("save-btn");
let selectedColor = null; // Store selected color globally
function countLines(textarea) {
const lineHeight = parseInt(getComputedStyle(textarea).lineHeight);
return Math.floor(textarea.scrollHeight / lineHeight);
}
textareas.forEach((textarea) => {
textarea.addEventListener("input", function () {
// Prevents input from exceeding 4 rows
if (countLines(this) > 4) {
this.value = this.value.slice(0, -1); // Remove last character if overflow occurs
}
});
textarea.addEventListener("keydown", function (e) {
// Block Enter key if at max rows
if (e.key === "Enter" && countLines(this) >= 4) {
e.preventDefault();
}
});
});
const removeHoverClasses = () => {
dashboard.classList.remove(
"hover-bg1", "hover-bg2", "hover-bg3", "hover-bg4",
"hover-bg5", "hover-bg6", "hover-bg7", "hover-bg8"
);
buttons.forEach((btn) => {
btn.classList.remove(
"hover-btn-bg1", "hover-btn-bg2", "hover-btn-bg3", "hover-btn-bg4",
"hover-btn-bg5", "hover-btn-bg6", "hover-btn-bg7", "hover-btn-bg8",
"selected-btn"
);
});
};
buttons.forEach((btn) => {
const colorIndex = btn.id.slice(-1); // Extract last number from button ID
btn.addEventListener("mouseenter", () => {
if (!selectedColor) { // Apply hover effect only if no button is clicked
removeHoverClasses();
dashboard.classList.add(`hover-bg${colorIndex}`);
// Apply hover effect to all buttons
buttons.forEach((b) => b.classList.add(`hover-btn-bg${colorIndex}`));
}
});
btn.addEventListener("mouseleave", () => {
if (!selectedColor) { // Remove hover effect if no button is selected
removeHoverClasses();
}
});
btn.addEventListener("click", () => {
selectedColor = colorIndex; // Store clicked button color
removeHoverClasses(); // Remove previous styles
// Apply selected color to all buttons & dashboard
dashboard.classList.add(`hover-bg${colorIndex}`);
buttons.forEach((b) => {
b.classList.add(`hover-btn-bg${colorIndex}`);
});
buttons.forEach((b) => {
if (b === btn) {
// Make only the clicked button white
b.classList.add("selected-btn");
} else {
// Other buttons get the selected button’s background color
b.classList.add(`hover-btn-bg${colorIndex}`);
}
});
});
});
saveBtn.addEventListener("click", async () => {
saveBtn.classList.add('hidden'); // Hide button
// Small delay to ensure button disappears
setTimeout(async () => {
const screenshotPath = await window.electronAPI.takeScreenshot();
alert(`Screenshot saved to: ${screenshotPath}`);
saveBtn.classList.remove('hidden'); // Show button again
}, 100); // Adjust this delay if necessary
});