📝 Made note of useful feature of darkreader api
This commit is contained in:
parent
b9755db5b3
commit
60c84e4ff5
2 changed files with 52 additions and 0 deletions
1
darkreader/darkreader.min.js
vendored
Normal file
1
darkreader/darkreader.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
51
darkreader/readme.txt
Normal file
51
darkreader/readme.txt
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
This darkreader.min.js file was downloaded as so:
|
||||||
|
|
||||||
|
wget https://cdnjs.cloudflare.com/ajax/libs/darkreader/4.9.58/darkreader.min.js
|
||||||
|
|
||||||
|
When used within an html project:
|
||||||
|
|
||||||
|
<script src="darkreader.min.js">
|
||||||
|
|
||||||
|
You can then enable it in your front end js files like so:
|
||||||
|
|
||||||
|
DarkReader.enable({
|
||||||
|
brightness: 100,
|
||||||
|
contrast: 90,
|
||||||
|
sepia: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
You can also disable it like so:
|
||||||
|
|
||||||
|
DarkReader.disable()
|
||||||
|
|
||||||
|
The main use I have found for this, however, is not to src this file, but rather to utilize it to generate
|
||||||
|
dark mode versions of personal sites using its exportGeneratedCSS() function:
|
||||||
|
|
||||||
|
const CSS = await DarkReader.exportGeneratedCSS()
|
||||||
|
console.log(CSS)
|
||||||
|
|
||||||
|
copying this from the console into a ./styles/darkreader.css file and then href from a link tag in your main css file allows you to have a baseline dark mode from which to further work on:
|
||||||
|
|
||||||
|
// grab the head element
|
||||||
|
const head = document.getElementByTagName('HEAD')
|
||||||
|
|
||||||
|
// start off in light mode
|
||||||
|
let hasDarkCSS = false
|
||||||
|
|
||||||
|
function toggleLight() {
|
||||||
|
if (!hasDarkCSS) return
|
||||||
|
head[0].removeChild(head[0].lastChild)
|
||||||
|
hasDarkCSS = !hasDarkCSS
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleDark() {
|
||||||
|
if (hasDarkCSS) return
|
||||||
|
const link = document.createElement('link')
|
||||||
|
link.rel = 'stylesheet'
|
||||||
|
link.type = 'text/css'
|
||||||
|
link.href = 'styles/darkreader.css'
|
||||||
|
head[0].appendChild(link)
|
||||||
|
hasDarkCSS = !hasDarkCSS
|
||||||
|
}
|
||||||
|
|
||||||
|
Please note that the generated CSS file should be used as a TEMPLATE, unless the site's color scheme is very simple, but it is very handy as it can generate dark versions of your project websites that are a great baseline to work off of.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue