PDF 支持自定义注入css/js以实现深色模式
complete
阿豪
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
  var cover = document.createElement("div");
  let css = `
    position: fixed;
    pointer-events: none;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #FFFFFFE0;
    mix-blend-mode: difference;
    z-index: 9999;
  `;
  cover.setAttribute("style", css);
  document.body.appendChild(cover);
}
allentown
marked this post as
complete
allentown
下个版本添加,默认开启跟随系统设置开启暗黑模式,可以在pdf选项中关闭
allentown
marked this post as
planned
allentown
那我直接可以加一个按钮,使用暗黑模式,点击就用你这段代码,并且记住用户的选择。不知道这段代码兼容性如何
阿豪
allentown 理论上应该检测当前模式然后自动开启 const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
不过不同人可能会有自己的配色方案, 所以自定义注入可能会好点, 不过也可以直接用这段代码, 目前感觉还行