-
Notifications
You must be signed in to change notification settings - Fork 0
/
transparent.html
207 lines (184 loc) · 6.64 KB
/
transparent.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html>
<head>
<title>Tiny Calculator</title>
<!-- Meta information -->
<meta name="author" content="Levi de Pruyssenaere de la Woestijne">
<meta name="version" content="Version 1.0">
<meta name="date" content="25 July, 2023">
<link rel="icon" href="TinyCalculatorLogo.png" type="image/Png">
<style>
body {
margin: 0; /* Remove default body margin */
background-color: transparent; /* Set body background to transparent */
}
.calculator-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: transparent; /* Set container background to transparent */
}
/* Light mode styles */
.light-mode .calculator {
background-color: #ffffff; /* White background in light mode */
color: #000000; /* Black text in light mode */
}
/* Dark mode styles */
.dark-mode .calculator {
background-color: #201f1f; /* Dark mode background color for calculator */
color: #ffffff; /* White text in dark mode */
}
.calculator {
width: 150px;
border: 1px solid #cccccc;
border-radius: 10px;
padding: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.calculator input {
width: 100%;
margin-bottom: 10px;
padding: 8px;
font-size: 16px;
border: 1px solid #cccccc;
border-radius: 5px;
text-align: right;
box-sizing: border-box;
background-color: #ffffff; /* White background for input */
}
/* Dark mode input style */
.dark-mode .calculator input {
background-color: #201f1f; /* Dark mode background color for input */
color: #ffffff; /* White text for input in dark mode */
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); /* Shadow for input in dark mode */
}
.calculator button {
width: 40px;
height: 40px;
font-size: 16px;
border: none;
border-radius: 50%;
margin: 2px;
cursor: pointer;
background-color: #ffffff; /* White background for buttons */
}
/* Dark mode button style */
.dark-mode .calculator button {
background-color: #201f1f; /* Dark gray background for buttons in dark mode */
color: #ffffff; /* White text for buttons in dark mode */
box-shadow: none; /* Remove box shadow for buttons in dark mode */
}
.calculator button:hover {
background-color: #f0f0f0; /* Light gray background on hover */
}
/* Dark mode button hover style */
.dark-mode .calculator button:hover {
background-color: #333333; /* Dark gray background on hover in dark mode */
}
/* Center the button rows */
.calculator > div {
display: flex;
justify-content: center;
}
/* Add some margin to the bottom row for better spacing */
.calculator > div:last-child {
margin-top: 10px;
}
</style>
</head>
<body class="light-mode">
<!-- Calculator container -->
<div class="calculator-container">
<div class="calculator" id="calculator">
<input type="text" id="display" readonly>
<!-- Button rows -->
<div>
<button onclick="clearDisplay()">C</button>
<button onclick="toggleSign()">+/-</button> <!-- (+/-) function button -->
<button onclick="calculatePercentage()">%</button>
<button onclick="appendToDisplay('/')">/</button>
</div>
<div>
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('*')">*</button>
</div>
<div>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="appendToDisplay('-')">-</button>
</div>
<div>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('+')">+</button>
</div>
<div>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="appendToDisplay('.')">.</button>
<button onclick="toggleDarkMode()">ⓘ</button> <!-- Dark/light mode button with "ⓘ" text -->
<button onclick="calculate()">=</button>
</div>
</div>
</div>
<!-- JavaScript code for calculator functionality and dark mode toggle -->
<script>
// Function to set the dark mode preference in local storage
function setDarkModePreference(darkModeEnabled) {
localStorage.setItem('darkMode', darkModeEnabled ? '1' : '0');
}
// Function to get the dark mode preference from local storage
function getDarkModePreference() {
return localStorage.getItem('darkMode') === '1';
}
// Function to update the dark mode class on the body and calculator elements
function updateDarkModeClass() {
const darkModeEnabled = getDarkModePreference();
const calculator = document.getElementById('calculator');
const display = document.getElementById('display');
if (darkModeEnabled) {
calculator.classList.add('dark-mode');
document.body.classList.add('dark-mode');
display.classList.add('dark-mode');
} else {
calculator.classList.remove('dark-mode');
document.body.classList.remove('dark-mode');
display.classList.remove('dark-mode');
}
}
// Call the function on page load to set the initial mode
updateDarkModeClass();
function appendToDisplay(value) {
document.getElementById('display').value += value;
}
function clearDisplay() {
document.getElementById('display').value = '';
}
function calculate() {
const display = document.getElementById('display');
try {
display.value = eval(display.value);
} catch (e) {
display.value = 'Error';
}
}
function calculatePercentage() {
const display = document.getElementById('display');
display.value = eval(display.value) / 100;
}
function toggleSign() {
const display = document.getElementById('display');
display.value = -1 * eval(display.value);
}
function toggleDarkMode() {
const darkModeEnabled = getDarkModePreference();
setDarkModePreference(!darkModeEnabled);
updateDarkModeClass();
}
</script>
</body>
</html>