{"id":4611,"date":"2023-05-08T14:31:09","date_gmt":"2023-05-08T14:31:09","guid":{"rendered":"https:\/\/corbinrose.com\/blog\/?p=4611"},"modified":"2023-05-08T14:31:09","modified_gmt":"2023-05-08T14:31:09","slug":"simple-hacky-dark-mode-for-any-site","status":"publish","type":"post","link":"https:\/\/corbinrose.com\/blog\/technology\/simple-hacky-dark-mode-for-any-site\/","title":{"rendered":"Simple hacky dark mode for any site"},"content":{"rendered":"\n<p>As I type now, I am sleepy an in a dark room with my laptop. It hurts my eyes looking at most websites with white backgrounds and dark text.   So, I thus present to you a bookmarklet that will hack a dark mode for the page at the click of said bookmarklet button.  <\/p>\n\n\n\n<p>This has several flaws, the biggest one perhaps being that background images will appear color-inverted, but hey, if you are working at 2am in the dark, why not have some weird colors jumping out at you? <\/p>\n\n\n\n<p>Here is the super simple JavaScript code I used<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>var newScript = document.createElement(&#39;style&#39;);\nvar content = document.createTextNode(&#39;html{filter: invert(100%); html img{filter: invert(1) hue-rotate(180deg);}&#39;);\nnewScript.appendChild(content);\nvar head = document.getElementsByTagName(&#39;head&#39;)[0];\nhead.appendChild(newScript);<\/code><\/pre><\/div>\n\n\n\n<p>Pretty basic.  <\/p>\n\n\n\n<p>Now we url-safe-ify it:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>javascript:(function()%7Bvar%20newScript%20%3D%20document.createElement(&#39;style&#39;)%3B%0Avar%20content%20%3D%20document.createTextNode(&#39;html%7Bfilter%3A%20invert(100%25)%3B%20html%20img%7Bfilter%3A%20invert(1)%20hue-rotate(180deg)%3B%7D&#39;)%3B%0AnewScript.appendChild(content)%3B%0Avar%20head%20%3D%20document.getElementsByTagName(&#39;head&#39;)%5B0%5D%3B%0Ahead.appendChild(newScript)%3B%7D)()%3B<\/code><\/pre><\/div>\n\n\n\n<p>This code can now be used as a bookmark &#8220;URL&#8221; in your browser.  When you click that bookmark, your webpage will automagically get dark-mode-ified.  <\/p>\n\n\n\n<p>To try it out, drag <a href=\"javascript:(function()%7Bvar%20newScript%20%3D%20document.createElement('style')%3B%0Avar%20content%20%3D%20document.createTextNode('html%7Bfilter%3A%20invert(100%25)%3B%20html%20img%7Bfilter%3A%20invert(1)%20hue-rotate(180deg)%3B%7D')%3B%0AnewScript.appendChild(content)%3B%0Avar%20head%20%3D%20document.getElementsByTagName('head')%5B0%5D%3B%0Ahead.appendChild(newScript)%3B%7D)()%3B\">this link<\/a> to your bookmark bar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I type now, I am sleepy an in a dark room with my laptop. It hurts my eyes looking at most websites with white backgrounds and dark text. So, I thus present to you a bookmarklet that will hack a dark mode for the page at the click of said bookmarklet button. This has [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":6025,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[28,17],"tags":[],"class_list":["post-4611","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-technology","clearfix","post-index"],"acf":[],"jetpack_featured_media_url":"https:\/\/corbinrose.com\/blog\/wp-content\/uploads\/2023\/05\/pexels-photo-614510-1.jpeg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts\/4611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/comments?post=4611"}],"version-history":[{"count":0,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts\/4611\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/media\/6025"}],"wp:attachment":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/media?parent=4611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/categories?post=4611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/tags?post=4611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}