Skip to content

Commit 4d8f052

Browse files
Merge pull request #89 from socraticDevBlog/20250207-pastelight
clipboard and light mode
2 parents 6acc71a + 767d98b commit 4d8f052

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

client/web/index.html

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,98 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta name="environment" content="local">
4+
<meta name="environment" content="local" />
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Pastebin</title>
88
<style>
9+
:root {
10+
--bg-color: white;
11+
--text-color: black;
12+
--button-bg: #007bff;
13+
--button-hover: #0056b3;
14+
}
15+
16+
body.dark-mode {
17+
--bg-color: #121212;
18+
--text-color: #ffffff;
19+
--button-bg: #ff9800;
20+
--button-hover: #e68900;
21+
}
22+
923
body {
1024
font-family: Arial, sans-serif;
1125
margin: 20px;
1226
text-align: center;
27+
background-color: var(--bg-color);
28+
color: var(--text-color);
29+
transition: background 0.3s, color 0.3s;
1330
}
31+
1432
textarea {
1533
width: 80%;
1634
height: 200px;
1735
margin-bottom: 10px;
36+
background: var(--bg-color);
37+
color: var(--text-color);
38+
border: 1px solid var(--text-color);
39+
padding: 10px;
40+
font-size: 16px;
41+
transition: background 0.3s, color 0.3s;
42+
}
43+
44+
.paste-button {
45+
position: absolute;
46+
top: 5px;
47+
right: 5px;
48+
padding: 5px 10px;
49+
font-size: 14px;
50+
background-color: var(--button-bg);
51+
color: white;
52+
border: none;
53+
border-radius: 5px;
54+
cursor: pointer;
55+
opacity: 0;
56+
transition: opacity 0.3s ease-in-out, background 0.3s;
57+
}
58+
59+
.container:hover .paste-button {
60+
opacity: 1;
61+
}
62+
63+
.paste-button:hover {
64+
background-color: var(--button-hover);
65+
}
66+
67+
/* Toggle Mode Button (Top-Right) */
68+
#toggleModeButton {
69+
position: absolute;
70+
top: 10px;
71+
right: 10px;
72+
padding: 8px 15px;
73+
font-size: 14px;
74+
background-color: var(--button-bg);
75+
color: white;
76+
border: none;
77+
border-radius: 5px;
78+
cursor: pointer;
79+
transition: background 0.3s;
80+
}
81+
82+
#toggleModeButton:hover {
83+
background-color: var(--button-hover);
1884
}
1985
</style>
2086
</head>
2187
<body>
88+
<!-- Toggle Mode Button (Top-Right) with the same id as in the initial code -->
89+
<button id="toggleModeButton" onclick="toggleMode()">☀️</button>
90+
2291
<h1>Pastebin</h1>
2392
<textarea
2493
id="pasteContent"
2594
placeholder="Paste your text here..."
95+
onclick="paste(this)"
2696
></textarea>
2797
<br />
2898
<button onclick="submitText()">Submit</button>

client/web/script.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,39 @@ async function displayPasteUrls() {
118118
}
119119
}
120120

121+
async function paste(input) {
122+
const text = await navigator.clipboard.readText();
123+
input.value = text;
124+
}
125+
126+
function toggleMode() {
127+
document.body.classList.toggle("dark-mode");
128+
const isDark = document.body.classList.contains("dark-mode");
129+
130+
// Save user preference
131+
localStorage.setItem("darkMode", isDark ? "enabled" : "disabled");
132+
133+
// Change button icon
134+
document.getElementById("toggleModeButton").innerHTML = isDark ? "☀️" : "🌙";
135+
}
136+
137+
document
138+
.getElementById("pasteContent")
139+
.addEventListener("keydown", function (event) {
140+
if (event.key === "Enter" && !event.shiftKey) {
141+
event.preventDefault(); // Prevents adding a new line
142+
submitText(); // Triggers submit
143+
}
144+
});
145+
121146
window.onload = function () {
122147
displayPasteUrls();
148+
const darkModeSetting = localStorage.getItem("darkMode");
149+
150+
if (darkModeSetting !== "disabled") {
151+
document.body.classList.add("dark-mode");
152+
document.getElementById("toggleModeButton").innerHTML = "☀️";
153+
} else {
154+
document.getElementById("toggleModeButton").innerHTML = "🌙";
155+
}
123156
};

0 commit comments

Comments
 (0)