-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
642 lines (451 loc) · 18.3 KB
/
index.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=yes">
<style>
/*
-++ CSS Dark Mode and Color Theme switch for websites and HTML apps. +++-
--- Original author :: Nik K. linkedin.com/in/nik--k---/ ( 4.Feb 2020).
--- Code adoption :: YourName (date).
--- License :: GNU General Public License v 3.0.
--- Latest version :: github.com/Dorson/CSS-Dark-Mode-and-color-switch
*/
/* Set default color variables. */
:root , :root.snow-white {
--color-html: #F9F9F9 ;
--color-body: #fdfdfd ;
--color-text: #051105 ;
--color-link: #1122D8 ;
--color-selected-text: #000 ;
--color-selected-bg: #CF7 ;
}
/* If "dark mode" was set in browser or app settings already. */
@media screen and (prefers-color-scheme: dark) {
html:not(.snow-white) {
--color-html: #0e0b0b ;
--color-body: #241818 ;
--color-text: #d1d1d1 ;
--color-link: #4fbcff ;
--color-selected-text: #000 ;
--color-selected-bg: #CF7 ;
}
}
/* Dark color variables, if "dark" is set as HTML tag's CSS class */
html.dark {
--color-html: #0e0b0b ;
--color-body: #1a1010 ;
--color-text: #d1d1d1 ;
--color-link: #4fbcff ;
--color-selected-text: #000 ;
--color-selected-bg: #CF7 ;
}
/* Deep Purple color variables, if "purple" is set as HTML tag's CSS class */
html.purple {
--color-html: #0a0614 ;
--color-body: #120b24 ;
--color-text: #d1d1d1 ;
--color-selected-text: #000 ;
--color-selected-bg: #CF7 ;
--color-link: #4fbcff ;
}
/* Deep Green color variables, if "green" is set as HTML tag's CSS class */
html.green {
--color-html: #04160a ;
--color-body: #072813 ;
--color-text: #d1d1d1 ;
--color-selected-text: #000 ;
--color-selected-bg: #CF7 ;
--color-link: #4fbcff ;
}
/* Cobalt Blue color variables, if "blue" is set as HTML tag's CSS class */
html.blue {
--color-html: #000d1a ;
--color-body: #001830 ;
--color-text: #d1d1d1 ;
--color-selected-text: #000 ;
--color-selected-bg: #CF7 ;
--color-link: #4fbcff ;
}
/* html box frame and global sizes */
html { box-sizing: border-box ; }
html *, *:before, *:after { box-sizing: inherit ; }
html { font-size: 115% ; padding: 0px 1em 0px 1em ; background: var(--color-html) ; }
html, body { margin: 0px ; }
/* limit max-width to avoid over-sized elements. */
body,img,iframe,input,select,element,script,embed,form {
max-width: calc(100% - 4px) ;
}
body {
padding: 2rem 3% 3rem 3% ;
min-height: 99% ; display: block ;
background: var(--color-body) ; color: var(--color-text) ;
}
/* Default minimal margin between all elements. */
body * { margin: 0.5rem 0.3rem ; }
/* Typography and font styles. */
@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
body, input, select, textarea, body iframe {
font:1.14em/1.5em Montserrat, sans-serif ;
}
h1,h2,h3,h4,h5,h6 {
margin: 1rem 0rem 1rem 0rem ;
font-family: Montserrat, Roboto, Verdana, sans-serif ;
letter-spacing: 0.1rem ;
}
h1 { font:1.555rem/1.777rem medium ; }
h2 { font:1.444rem/1.666rem medium ; }
h3 { font:1.333rem/1.555rem medium ; }
h4 { font:1.222rem/1.444rem sans ; }
h5 { font:1.161rem/1.333rem sans ; }
h6 { font:1.145rem/1.250rem sans ; }
* > h1:not(:first-of-type):not(:first-child ) ,
* > h2:not(:first-of-type):not(:first-child ) ,
* > h3:not(:first-of-type):not(:first-child ){
margin: 2rem 0rem 1rem 0rem ;
}
::selection {
background: var(--color-selected-bg) ; color: var(--color-selected-text) ;
}
/* Style for links. */
a:link, a:visited { color : var(--color-link) ; text-decoration: none ; }
a:hover { border-bottom: 0.185rem dashed var(--color-link) ; border-radius: 0.4em ; }
button {
margin: 0.244rem ;
box-shadow:inset 1px 3px 3px 0px #f7c5c0;
background: linear-gradient(to bottom, #f04257 1%, #e0122a 99%);
background-color: #e0122a ;
border-radius: 0.4rem ;
border: 0px ;
display: inline ;
cursor: pointer ;
color: #f1f1f1 ;
text-shadow: 0px 1px 1px #222 ;
font-family: Arial ;
font-size: 1.2rem ;
font-weight: bold ;
padding: 0.2rem 0.5rem 0.2rem 0.5rem ;
text-decoration: none ;
}
button:hover {
background: linear-gradient(to bottom, #ee2b41 3%, #f47181 99%) ;
background-color: #ee2b41 ;
box-shadow: 1px 2px 2px 0px #f04257 ;
}
button:active {
background: #e0122a ;
box-shadow: none ;
text-decoration: none ;
}
/* scroll-bar style. */
body::-webkit-scrollbar {
margin: 0px ; padding: 0px ;
width: 0.99rem ;
background: transparent ;
}
body::-webkit-scrollbar-thumb {
margin: 0px ; padding:0px;
width: 0.99rem ;
border: 4px double #ccc ;
background: #edf0f3 ; border-radius: 9px ;
box-shadow: 0rem 0.1rem 0.3rem #ccc ;
}
/* docker sticker menu dock. */
.docker { margin: 1px ; padding: 0px ; position: fixed ;
bottom:0%; left: 15%; z-index:99; width: 13.5rem; height: 2.7rem; color: var(--color-text) ;
text-align: left ; overflow: hidden ; background: transparent ; border: 0px ;
}
.docker:hover , .docker:active { background: var(--color-body) ; color: var(--color-text) ;
margin: 1px ; padding: 0.1rem 0.4rem 1rem 0.4rem ;
position: fixed; bottom: 0px ; left: 2% ; z-index:250; width: 73% ; height: 75% ;
border-radius: 8px ; box-shadow: 0px 1px 33px #aaa ; border-bottom: 3rem double rgba(150, 150, 150, 0.1) ;
display: block ; overflow: auto ; vertical-align: top ; text-align: center ;
}
.code-box {
color: #000 ; background: #d7dbda ; border: solid #668f99 ;
border-width: 0.155rem .2rem .2rem .444rem ; border-radius: 0.9rem 1.5rem 0.5rem 2rem ;
padding: .8em .6em ; overflow: auto ; width: auto ; margin: 1rem ;
}
/* Print exception rules. Very useful to print website as PDF and grandma :-) */
@media print
{
.docker , .menue { visibility: hidden; }
.no-print, .no-print *
{
display: none !important;
}
}
</style>
<script>
/*
-+++++ JavaScript CSS Class Switch function for websites and HTML apps. +++-
--- Original author :: Nik K. linkedin.com/in/nik--k---/ ( 4.Feb 2020).
--- Code adoption :: YourName (date).
--- License :: GNU General Public License v 3.0.
--- Latest version :: github.com/Dorson/CSS-Dark-Mode-and-color-switch
*/
window.onerror = null ;
/*
During load time, we remember the saved CSS classes from localStorage
Only works with HTML Tags that are already loaded before the script run !
Optimally the HTML tag. Works for the first Tag of it's type only !
*/
document.addEventListener( 'DOMContentLoaded' , function() {
RememberClasses() ;
});
function RememberClasses() {
const ClassMemory = [
["html" , "ColorMode"] ,
["html" , "TextSize"]
] ;
for ( let [ Tag , MemoryName ] of ClassMemory ) {
let TagNotAlive = !(document.querySelector( Tag )) ;
let MemoryValue = window.localStorage.getItem( MemoryName ) ;
/* On logic Errors we skip one loop. */
if ( !MemoryValue || TagNotAlive ) {
continue ;
}
/* Else we remember and set CSS classes. */
else {
document.querySelector( Tag ).classList.add( MemoryValue );
}
}
}
/* In the dark, IF ColorMode was NOT set, and the hour is between 20:00 and 7:00 */
document.addEventListener("DOMContentLoaded", AfterDark() , true ) ;
function AfterDark() {
let hour = new Date().getHours() ;
let ColorWasSet = localStorage.getItem( "ColorMode" ) ;
let DarkWasSet = document.querySelector("html").classList.contains("dark") ;
if ( ( hour >= 20 || hour < 7 ) && !( ColorWasSet || DarkWasSet ) )
{
document.querySelector("html").classList.add( "dark" ) ;
}
}
/* CSS class Toggle Switch. ON,OFF CSS class + remember in localStorage memory. */
function ClassSwitch( TagName, ClassName, MemoryName ) {
/* We use const variables to avoid logic errors, if their values change during process. */
const ClassWasActive = document.querySelector( TagName ).classList.contains( ClassName ) ;
const OldMemory = window.localStorage.getItem( MemoryName ) ;
/* If class is New and NOT-active. We remove possible OldMemory class.
Deep Clean memory cell. Activate and remember new CSS class in clean memory.
*/
if ( !ClassWasActive && ( OldMemory !== ClassName ) ) {
if ( OldMemory ) {
document.querySelector( TagName ).classList.remove( OldMemory ) ;
window.localStorage.removeItem( MemoryName ) ;
}
document.querySelector( TagName ).classList.add( ClassName ) ;
window.localStorage.setItem( MemoryName , ClassName ) ;
}
/* Else CSS class was already active OR the switch memory was not clean.
We toggle given class. Remove possible OldMemory class. Deep Clean memory cell.
*/
else {
document.querySelector( TagName ).classList.toggle( ClassName ) ;
if ( OldMemory ) {
document.querySelector( TagName ).classList.remove( OldMemory ) ;
window.localStorage.removeItem( MemoryName ) ;
}
}
return false ;
}
/*
Dual Flip CSS class Toggle Switch. Set THis OR the OTher CSS class.
Flips or changes CSS class between two given options.
If Class1 was NOT active: We switch it ON. Else: we flip switch Class2 ON.
Only one can exist at the same time ! Class1 will always be switched on first !
*/
function DualFlipClassSwitch( TagName , Class1 , Class2 , MemoryName ) {
const ClassWasActive = document.querySelector( TagName ).classList.contains( Class1 ) ;
if ( !ClassWasActive ) { ClassSwitch( TagName , Class1 , MemoryName ) ; }
else { ClassSwitch( TagName , Class2 , MemoryName ) ; }
return false ;
}
</script>
<title>CSS Dark Mode and Color Theme Switch for Websites and HTML Apps.</title>
</head><body>
<div style="margin: 0rem 0px 5px 0px; width:99%; display:block;">
<b style="font: 3rem/3.5rem bold sans ;"> LOGO </b>
/ ☰ MENU / Top 5 links / Search box / Login.
</div>
<h1> JS Color Theme Switch = CSS Dark Mode for Websites and HTML Apps. </h1>
<p>
The human day and night cycle is important for our sleep and the eyes.
The correct amount of light is very important for good health.
During the evening and the night we need dark colors on websites and apps.
It is more natural to have the dark background colors at night.
This is the live demo page for the open source code that we can use for
the Night/Dark Mode = light switch for websites and HTML apps.
</p>
<p>
Use this code for free and where you want. It is open source, free and
can be changed for re-use too.
Use it as you like, as long as you keep the code open source, as same as the original.
If you improve or publish the code, please include the same open source license
and the names of the original author or contributors. Please also include yourself
as a contributor, if you improve or publish the code in the future.
Have a lot of fun with this CSS + JS code for the dynamic website color switch !
</p>
<h2> :: Click and Switch the Colors :: </h2>
<p>
Dark Mode:
<a href="javascript:void(0);" onclick="DualFlipClassSwitch('html' , 'dark' , 'snow-white' , 'ColorMode');" title="Lights ON, OFF." >
🌓 ⇄ 💡
</a>
Purple Mode:
<a href="javascript:void(0);" onclick="ClassSwitch('html' , 'purple' , 'ColorMode');" title="Set Purple Colors." >
💜 ⇄ 💡
</a>
Green Mode:
<a href="javascript:void(0);" onclick="ClassSwitch('html' , 'green' , 'ColorMode');" title="Set Green Colors." >
🍏 ⇄ 💡
</a>
Cobalt Blue :
<a href="javascript:void(0);" onclick="ClassSwitch('html' , 'blue' , 'ColorMode');" title="Set Blue Colors." >
🌊 ⇄ 💡
</a>
</p>
<p>
Try clicking the same button link two times and see what happens.
<br />
<button onclick="DualFlipClassSwitch('html' , 'snow-white' , 'dark' , 'ColorMode');" >
<b style="font-size:1.2rem; background-color: #ddd ; color:#fff;"> ❅ </b>
</button>
<button onclick="DualFlipClassSwitch('html' , 'dark' , 'snow-white' , 'ColorMode');" >
Dark <b style="font-size:1.2rem; background-color: #1a1414 ; color:#d1d1d1;"> 🌓 ⇄ 💡 </b>
</button>
<button onclick="ClassSwitch('html' , 'purple' , 'ColorMode');" >
Purple <b style="font-size:1.2rem; background-color: #120b24 ; color: #724fc9 ;"> 💜 ⇄ 💡 </b>
</button>
<button onclick="ClassSwitch('html' , 'green' , 'ColorMode');" >
Green <b style="font-size:1.2rem; background-color: #072813 ; color: #26d968 ;"> 🍏 ⇄ 💡 </b>
</button>
<button onclick="ClassSwitch('html' , 'blue' , 'ColorMode');" >
Cobalt <b style="font-size:1.2rem; background-color: #001830 ; color: #0080ff ;"> 🌊 ⇄ 💡 </b>
</button>
<br />
</p>
<h2> Give us a like and stars on Github ☆☆☆☆☆ ! </h2>
Have fun using our code. Keep it fun for others too.
Keep the code open source as the original !
<p>
<a href="https://github.com/Dorson/CSS-Dark-Mode-and-color-switch/" >
<b> Original Github Repo Source: </b>
<br />
github.com/Dorson/CSS-Dark-Mode-and-color-switch/
</a>
</p>
<h5> Be healthy and happy ! </h5>
<div class="docker">
<div alt="docker icon bar"
style=" background: #f1f1f1 ; opacity:0.7 ; color: #222 ;
padding: 0.1rem 0.6rem ; margin: 1px ;
position: sticky ; top: 1px ; left: 1px ;
font: bold 1.7rem/3rem sans ; border-radius: 0.3rem ; border: 0px ; " >
<b> ☰ ♡ ☼ ⚙ ⇡ </b>
</div>
<br />
<b> ⏻ On / Off Color : </b> <br />
<button onclick="DualFlipClassSwitch('html' , 'snow-white' , 'dark' , 'ColorMode');" >
<b style="font-size:1.2rem; background-color: #ddd ; color:#fff;"> ❅ </b>
</button>
<button onclick="DualFlipClassSwitch('html' , 'dark' , 'snow-white' , 'ColorMode');" >
<b style="font-size:1.2rem; background-color: #1a1414 ; color:#d1d1d1;"> 🌓 </b>
</button>
<button onclick="ClassSwitch('html' , 'purple' , 'ColorMode');" >
<b style="font-size:1.2rem; background-color: #120b24 ; color: #724fc9 ;"> 💜 </b>
</button>
<button onclick="ClassSwitch('html' , 'green' , 'ColorMode');" >
<b style="font-size:1.2rem; background-color: #072813 ; color: #26d968 ;"> 🍏 </b>
</button>
<button onclick="ClassSwitch('html' , 'blue' , 'ColorMode');" >
<b style="font-size:1.2rem; background-color: #001830 ; color: #0080ff ;"> 🌊 </b>
</button>
<p> Be happy. Talk with people.</p>
<a href="" onclick="window.open('https://twitter.com/share?url='+encodeURIComponent(location.href),'_blank','toolbar=0,location=0,status=0,width=600,height=500,left=50,top=40');return false;"> <b>🐦 </b> Share on Twitter </a>
<p>
<a href="" onclick="window.open('https://www.linkedin.com/shareArticle?mini=true&url='+encodeURIComponent(location.href),'_blank','toolbar=0,location=0,status=0,width=600,height=500,left=50,top=40');return false;"> <b> ㏑</b> Share on Linked-in</a>
</p>
<a href="" onclick="window.open('https://www.facebook.com/share.php?u='+encodeURIComponent(location.href),'_blank','toolbar=0,location=0,status=0,width=600,height=500,left=50,top=40');return false;"> <b> FB </b> Share on Facebook </a>
<p><b> Thank you for sharing !</b></p>
</div>
<div title=" Top-right Night-Mode dual Flip Switch. "
style=" background: rgba(229, 229, 229, 0.5) ; color: #111 ;
padding: 1px ; margin: 1px ; width : 1.5rem ;
position: fixed ; top: 6rem ; right: 0.45rem ;
z-index: 15 ; text-align: center ; word-wrap: break-word ;
font: bold 1rem/1.1rem sans ; border-radius: 1rem ; border: 0px ; "
>
<a title=" Lights ON, OFF. "
href="javascript:void(0);" onclick="DualFlipClassSwitch('html' , 'dark' , 'snow-white' , 'ColorMode');"
style=" color: #111 ; padding: 0.4em 0.1em ; margin: 1px ; text-decoration: none ; float: right ; "
>
🌓<br />
⇄<br />
💡
</a>
</div>
<style>
.search-box {
background-color: #f1f1f1 ; color: #111 ; opacity: 0.7 ; overflow: hidden ;
padding: 0.1rem 0.5rem ; margin: 1px ; text-align: right ;
position: fixed ; top: 1px ; right: 2.5rem ; width : 10rem ; height: 1.9rem ;
z-index: 10 ;
font: bold 1rem/1.1rem sans ; border-radius: 1rem ; border: 0px ;
}
.search-box:hover , .search-box:active {
background: #edf5f7 ; color: #111 ; opacity: 1 ;
padding: 0.7rem ; margin: 1px ; text-align: right ;
position: fixed ; top: 1px ; right: 2.5rem ; width : 70% ; height: auto ;
z-index: 10 ;
font: bold 1rem/1.1rem sans ; border-radius: 1rem ; border: 0px ;
box-shadow:9px 9px 20px #bbb;z-index:250; overflow: visible ;
}
.search-box:hover .invisible-on-hover , .search-box:active .invisible-on-hover { display: none ; }
.search-box .visible-on-hover { visibility: hidden ; }
.search-box:hover .visible-on-hover, .search-box:active .visible-on-hover { visibility: visible ; }
</style>
<div title=" Top Search Box " class="search-box" >
<div title=" fake input box " class="invisible-on-hover"
style=" background: #efefef ; color: #111 ;
padding: 0.1rem 0.5rem ; margin: 1px ; text-align: left ;
position: inline ; width : 5rem ; height : 1.4rem ; float : left ;
font: bold 0.9rem/1rem sans ; border-radius: 0.7rem ; border: 0.111rem solid #00B4CC; "
>
...
</div>
<div alt="search icon " class="invisible-on-hover"
style=" background: #34b8e5 ; color: #000 ; opacity: 1 ;
padding: 0.111rem ; margin: 1px ; text-align: center ; text-shadow: 1px 1px 0.3rem #fff;
position: inline ; width : 3rem ; height : 1.5rem ; white-space: nowrap; float : right ;
font: bold 1rem/1.3rem sans ; border-radius: 0.6rem ; border: 0px; "
>
🔍
</div>
<div class="visible-on-hover" >
<input type="text" placeholder="Search..." title=" fake input box "
style=" background: #efefef ; color: #111 ;
padding: 0.1rem 0.5rem ; margin: 1px ; text-align: left ;
position: inline ; width : 60% ; height : 2rem ; clear : none ; float : right ;
font: bold 0.9rem/1rem sans ; border-radius: 0.7rem ; border: 0.111rem solid #00B4CC; "
>
<div type="submit" alt="fake search icon "
style=" background: #34b8e5 ; color: #000 ; opacity: 1 ;
padding: 0.111rem ; margin: 1px ; text-align: center ; text-shadow: 1px 1px 0.3rem #fff;
position: inline ; width : 4rem ; height : 2rem ; clear: none ; float : right ;
font: bold 1.5rem/1.9rem sans ; border-radius: 0.8rem ; border: 0px; "
>
🔍
</div>
</div>
</div>
<!--
-++ CSS Dark Mode and Color Theme switch for websites and HTML apps. +++-
--- Original author :: Nik K. linkedin.com/in/nik--k---/ ( 4.Feb 2020).
--- Code adoption :: YourName (date).
--- License :: GNU General Public License v 3.0.
--- Latest version :: github.com/Dorson/LTS-flex-css-style-theme-generator
-->
<div style="clear:both;">.</div>
</body></html>