Skip to content

Instantly share code, notes, and snippets.

@socheatsok78
Last active October 7, 2024 00:39
Show Gist options
  • Save socheatsok78/32b0bf4ebfc6034ea74f47f4dfd3884c to your computer and use it in GitHub Desktop.
Save socheatsok78/32b0bf4ebfc6034ea74f47f4dfd3884c to your computer and use it in GitHub Desktop.
Add a simple Dark Mode toggle to any site without using extensions.

About

Add a simple Dark Mode toggle to any site without using extensions.

Bookmarklet

You can add this code to any page using the following bookmarklet:

javascript: (function (d) { sl = d.createElement('style'), s = d.createElement('script'); sl.innerHTML = '.darkmode-layer, .darkmode-toggle { z-index: 500; }'; d.head.appendChild(sl); s.onload = function () { new Darkmode({ saveInCookies: false, label: '๐ŸŒ“', right: 'unset', left: '32px' }).showWidget(); }; s.src = '//cdn.jsdelivr.net/npm/[email protected]/lib/darkmode-js.min.js'; d.head.appendChild(s); })(document)
(function (d) {
s = d.createElement('script');
s.src = '//gist.githubusercontent.com/socheatsok78/32b0bf4ebfc6034ea74f47f4dfd3884c/raw/b673ee8a25be03a43574a94cb3163aedaf9d1f83/script.js';
d.head.appendChild(s);
})(document)
(function (d) {
sl = d.createElement('style'),
s = d.createElement('script');
sl.innerHTML = '.darkmode-layer, .darkmode-toggle { z-index: 500; }';
d.head.appendChild(sl);
s.onload = function () { new Darkmode({ saveInCookies: false, label: '๐ŸŒ“', right: 'unset', left: '32px' }).showWidget(); };
s.src = '//cdn.jsdelivr.net/npm/[email protected]/lib/darkmode-js.min.js'; d.head.appendChild(s);
})(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment