Dark Reader

Toggle dark mode using an icon placed at the bottom left of your screen.

目前为 2023-05-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Dark Reader
  3. // @description Toggle dark mode using an icon placed at the bottom left of your screen.
  4. // @author Schimon Jehudah, Adv.
  5. // @namespace i2p.schimon.dimmer
  6. // @homepageURL https://openuserjs.org/scripts/sjehuda/Dimmer
  7. // @supportURL https://openuserjs.org/scripts/sjehuda/Dimmer/issues
  8. // @copyright 2023, Schimon Jehudah (http://schimon.i2p)
  9. // @license MIT; https://opensource.org/licenses/MIT
  10. // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5SFPC90ZXh0Pjwvc3ZnPgo=
  11. // @include *
  12. // @version 23.04.02
  13. // @require https://unpkg.com/darkreader@4.9.58/darkreader.js
  14. // @noframes
  15. // ==/UserScript==
  16.  
  17. /*
  18.  
  19. TODO
  20.  
  21. Toggle color of button.
  22. btn.style.filter = 'hue-rotate(500deg)'
  23. See https://noscript.net/
  24.  
  25. Or use a plain character '●'.
  26. btn.style.color = 'black'
  27.  
  28. */
  29.  
  30.  
  31. if (document.doctype == null) { return; }
  32.  
  33. const namespace = 'org.openuserjs.sjehuda.dimmer';
  34.  
  35. // create hotkey
  36. createButton();
  37. // set hotkey Ctrl + Shift + <
  38. document.onkeyup = function(e) {
  39. if (e.ctrlKey && e.shiftKey && e.which == 190) {
  40. toggle();
  41. }
  42. };
  43.  
  44. function createButton() {
  45. // create element
  46. let btn = document.createElement(namespace);
  47. document.body.append(btn);
  48. // set content
  49. btn.innerHTML = '🔆'; // 🌕 🌌 ●
  50. btn.id = namespace;
  51. // set position
  52. btn.style.position = 'fixed';
  53. btn.style.bottom = 0;
  54. btn.style.left = 0;
  55. // set appearance
  56. btn.style.marginTop = '100px';
  57. btn.style.marginRight = '10px';
  58. btn.style.minWidth = '50px';
  59. btn.style.minHeight = '50px';
  60. btn.style.fontSize = '20px';
  61. btn.style.zIndex = 10000;
  62. btn.style.opacity = 0.5;
  63. btn.onmouseover = () => {
  64. document
  65. .getElementById(namespace)
  66. .style.opacity = 0.9;
  67. };
  68. btn.onmouseout = () => {
  69. document
  70. .getElementById(namespace)
  71. .style.opacity = 0.3;
  72. };
  73. // center character
  74. btn.style.justifyContent = 'center';
  75. btn.style.alignItems = 'center';
  76. btn.style.display = 'flex';
  77. // disable selection marks
  78. btn.style.outline = 'none';
  79. btn.style.userSelect = 'none';
  80. btn.style.cursor = 'default';
  81. // set button behaviour
  82. btn.onclick = () => {
  83. toggle();
  84. };
  85. }
  86.  
  87. // toggle mode
  88. function toggle() {
  89. let btn = document.getElementById(namespace);
  90. if (btn.innerHTML == '🔆') {
  91. btn.innerHTML = '🔅'; // ☀️ 🌅
  92. DarkReader.setFetchMethod(window.fetch) // https://eligrey.com/
  93. DarkReader.enable({
  94. brightness: 100,
  95. contrast: 90,
  96. sepia: 10
  97. });
  98. } else {
  99. btn.innerHTML = '🔆';
  100. DarkReader.disable({
  101. brightness: 100,
  102. contrast: 90,
  103. sepia: 10
  104. });
  105. }
  106. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址