{"id":15686248,"url":"https://github.com/jakejarvis/dark-mode","last_synced_at":"2025-05-07T18:23:51.642Z","repository":{"id":36979965,"uuid":"392344482","full_name":"jakejarvis/dark-mode","owner":"jakejarvis","description":"🌓 Super simple CSS theme switching with saved preferences and automatic OS setting detection","archived":false,"fork":false,"pushed_at":"2023-01-24T03:05:38.000Z","size":331,"stargazers_count":10,"open_issues_count":12,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-30T20:53:35.169Z","etag":null,"topics":["css","dark-mode","dark-theme","frontend","javascript","npm"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakejarvis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-03T14:25:24.000Z","updated_at":"2025-01-19T13:59:44.000Z","dependencies_parsed_at":"2023-02-13T14:10:18.057Z","dependency_job_id":null,"html_url":"https://github.com/jakejarvis/dark-mode","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakejarvis%2Fdark-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakejarvis%2Fdark-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakejarvis%2Fdark-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakejarvis%2Fdark-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakejarvis","download_url":"https://codeload.github.com/jakejarvis/dark-mode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252932374,"owners_count":21827287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","dark-mode","dark-theme","frontend","javascript","npm"],"created_at":"2024-10-03T17:37:00.045Z","updated_at":"2025-05-07T18:23:51.623Z","avatar_url":"https://github.com/jakejarvis.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌓 Dark Mode Switcheroo™\n\n[![CI](https://github.com/jakejarvis/dark-mode/actions/workflows/ci.yml/badge.svg)](https://github.com/jakejarvis/dark-mode/actions/workflows/ci.yml)\n[![npm](https://img.shields.io/npm/v/dark-mode-switcheroo)](https://www.npmjs.com/package/dark-mode-switcheroo)\n\nVery simple CSS dark/light mode toggler with saved preference via local storage \u0026 dynamic OS setting detection. Zero dependencies and [only ~500 bytes gzipped!](https://bundlephobia.com/package/dark-mode-switcheroo)\n\n- [View the example.](https://jakejarvis.github.io/dark-mode/)\n- [Read the blog post.](https://jarv.is/notes/dark-mode/)\n- [See it in action.](https://jarv.is/)\n\n## Usage\n\n### Options\n\n`darkMode.init([...options])`\n\n- **`toggle`**: The clickable [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement) used to toggle between the two themes. (optional, default: `null`)\n- **`classes`**: An object containing the `\u003cbody\u003e` class names for the light and dark themes. (optional, default: `{ light: \"light\", dark: \"dark\" }`)\n- **`default`**: The initial `\u003cbody\u003e` class hard-coded into the HTML template. (optional, default: `\"light\"`)\n- **`storageKey`**: Name of the `localStorage` key holding the user's preference. (optional, default: `\"dark_mode_pref\"`)\n- **`onInit([toggle])`**: Callback function executed at the end of initialization. The toggle above is passed in if set. (optional, default: `null`)\n- **`onUserToggle([toggle])`**: Callback function executed when a user manually interacts with the toggle button. The toggle above (if set) is passed in. (optional, default: `null`)\n- **`onChange([theme, toggle])`**: Callback function executed when theme is switched. The new theme and the toggle above (if set) are passed in. (optional, default: `null`)\n\n### Browser\n\n```html\n\u003cbutton class=\"dark-mode-toggle\" style=\"visibility: hidden;\"\u003e💡 Click to see the light... or not.\u003c/button\u003e\n\n\u003cscript src=\"https://unpkg.com/dark-mode-switcheroo/dist/dark-mode.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  window.darkMode.init({\n    toggle: document.querySelector(\".dark-mode-toggle\"),\n    classes: {\n      light: \"light\",\n      dark: \"dark\",\n    },\n    default: \"light\",\n    storageKey: \"dark_mode_pref\",\n    onInit: function (toggle) {\n      toggle.style.visibility = \"visible\"; // toggle appears now that we know JS is enabled\n    },\n    onChange: function (theme, toggle) {\n      console.log(\"Theme is now \" + theme);\n    },\n  });\n\u003c/script\u003e\n```\n\n### Node\n\n```bash\nnpm install dark-mode-switcheroo\n# or...\nyarn add dark-mode-switcheroo\n```\n\n#### Module via `import`\n\n```js\nimport { init } from \"dark-mode-switcheroo\";\n\ninit({\n  // ...same as browser.\n});\n```\n\n#### CommonJS via `require()`\n\n```js\nconst darkMode = require(\"dark-mode-switcheroo\");\n\ndarkMode.init({\n  // ...same as browser.\n});\n```\n\n## To-Do\n\n- [ ] Support more than two themes\n- [ ] Better readme docs\n- [x] Add callback function `onChange` (or `onToggle` etc.) passed in as an option\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakejarvis%2Fdark-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakejarvis%2Fdark-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakejarvis%2Fdark-mode/lists"}