by roosgit · 4y ago · 0 comments
document.querySelectorAll('p').forEach(elem => {elem.style.color = '#000'})
You can turn this into a bookmarklet or run it from the console(necessary on sites like github.com which do not allow code running from bookmarklets).
Of course, it will not fix all your text color problems. To cover more elements like lists and headings, you'll need to add them to `querySelectorAll`.
document.querySelectorAll('p, ul, ol, h1, h2, h3, h4').forEach(elem => {elem.style.color = '#333'})
`#333` is what Firefox Reader Mode uses because it's less heavy than full black (#000).
I tried a variant of it on GitHub.com. It worked fine. This one turns text red, but you can change it back to black. You can select the text below and drag it to the bookmark toolbar to create the bookmarklet--at least on Chrome/Firefox on Windows. If that doesn't work, you can copy/paste.
javascript:document.querySelectorAll('*').forEach(elem => elem.style.color = 'red')
This one uses a different approach, it adds a dark mode style sheet. javascript:/* /Dark Mode# */(function () {document.head.appendChild(document.createElement('style')).innerHTML = '* {background-color: #121212 !important; color: #888 !important;}';})();My mistake was basing my statement on past experiences using an older Firefox ESR version which would give "Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”)." when clicking on a bookmarklet for sites like Twitter or Github.