Dark Reader

Toggle dark mode using an icon placed at the bottom left of your screen. Hotkey: Command + Shift + B.

当前为 2023-05-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Dark Reader
  3. // @description Toggle dark mode using an icon placed at the bottom left of your screen. Hotkey: Command + Shift + B.
  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.05.27
  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. // set hotkey Command + Shift + B
  36. createButton();
  37. document.onkeyup = function(e) {
  38. if (e.metaKey && e.shiftKey && e.which == 66) {
  39. toggle();
  40. }
  41. };
  42.  
  43. function createButton() {
  44. // create element
  45. let btn = document.createElement(namespace);
  46. document.body.append(btn);
  47. // set content
  48. btn.innerHTML = '🔆'; // 🌕 🌌 ●
  49. btn.id = namespace;
  50. // set position
  51. btn.style.position = 'fixed';
  52. btn.style.bottom = 0;
  53. btn.style.left = 0;
  54. // set appearance
  55. btn.style.marginTop = '100px';
  56. btn.style.marginRight = '10px';
  57. btn.style.minWidth = '50px';
  58. btn.style.minHeight = '50px';
  59. btn.style.fontSize = '20px';
  60. btn.style.zIndex = 10000;
  61. btn.style.opacity = 0.5;
  62. btn.onmouseover = () => {
  63. document
  64. .getElementById(namespace)
  65. .style.opacity = 0.9;
  66. };
  67. btn.onmouseout = () => {
  68. document
  69. .getElementById(namespace)
  70. .style.opacity = 0.3;
  71. };
  72. // center character
  73. btn.style.justifyContent = 'center';
  74. btn.style.alignItems = 'center';
  75. btn.style.display = 'flex';
  76. // disable selection marks
  77. btn.style.outline = 'none';
  78. btn.style.userSelect = 'none';
  79. btn.style.cursor = 'default';
  80. // set button behaviour
  81. btn.onclick = () => {
  82. toggle();
  83. };
  84. }
  85.  
  86. // toggle mode
  87. function toggle() {
  88. let btn = document.getElementById(namespace);
  89. if (btn.innerHTML == '🔆') {
  90. btn.innerHTML = '🔅'; // ☀️ 🌅
  91. DarkReader.setFetchMethod(window.fetch) // https://eligrey.com/
  92. DarkReader.enable({
  93. brightness: 100,
  94. contrast: 90,
  95. sepia: 10
  96. });
  97. } else {
  98. btn.innerHTML = '🔆';
  99. DarkReader.disable({
  100. brightness: 100,
  101. contrast: 90,
  102. sepia: 10
  103. });
  104. }
  105. }

QingJ © 2025

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