我如何 运行 在桌面应用程序的夜间模式下松弛

How can I run Slack in Night Mode on Desktop app

Slack 主题在使用 Stylish 的 Web 应用程序中可用,请参阅 https://userstyles.org/styles/browse?search_terms=slack

但是必须有一种方法可以在桌面应用程序上使用它们。什么是黑客?

最新更新! Slack 桌面应用程序现在原生支持深色模式! 刚进入首选项 cmd+, 和 select 主题 > 深色

已更新,之前的 hacks 在 4.0.0 版本中停止工作。

此解决方案自 2019 年 7 月 18 日起有效

https://github.com/LanikSJ/slack-dark-mode

您可能需要查看 https://github.com/LanikSJ/slack-dark-mode/issues/80

上的说明

当我有时间分叉我在上面发布的回购协议并对其进行改进时,我可能会再次更新这个答案。

我写了一个小的 "plugin framework",你只需 运行 一个 shell 脚本来修补你的 slack 安装,然后你就可以启用任何数字"plugins" 我为桌面应用程序编写的,其中一个是深色主题。如果您想加载您在其他地方找到的自己的 CSS 文件,README 中有说明。

https://github.com/glajchs/slack-customizations

Here 是我的脚本,用于在 sunrise/sunset 时自动在明暗模式之间切换。在 /Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js 末尾附加脚本,不要忘记根据您的实际位置更新 LOCATION

document.addEventListener('DOMContentLoaded', async function() {
  // supply your location here, use e.g. https://www.latlong.net/ to find it
  const LOCATION = [50.075539, 14.437800]
  const MS_IN_DAY = 24 * 60 * 60 * 1000

  const initTheme = themeCssUrl => new Promise(resolve => $.ajax({
    url: themeCssUrl,
    success: css => {
      const styleJqueryEl = $('<style>').html(css).appendTo('head')
      const styleElement = styleJqueryEl[0]
      styleElement.disabled = true
      resolve(styleElement)
    }
  }))

  const loadTimeInfo = ([latitude, longitude]) => new Promise(resolve => $.ajax({
    // courtesy of https://sunrise-sunset.org/api
    url: `https://api.sunrise-sunset.org/json?lat=${latitude}&lng=${longitude}&formatted=0`,
    success: ({ results: { sunrise, sunset } }) => resolve({
      sunrise: Number(new Date(sunrise)),
      sunset: Number(new Date(sunset)),
      expires: Math.ceil(Date.now() / MS_IN_DAY) * MS_IN_DAY
    })
  }))

  const updateTheme = (styleElement, timeInfo) => {
    const now = Date.now()
    const { sunrise, sunset } = timeInfo
    styleElement.disabled = now >= sunrise && now < sunset
  }

  const darkModeStyle = await initTheme('https://raw.githubusercontent.com/mattiacantalu/Slack-Dark-Mode/master/dark-mode.css')
  let timeInfo = await loadTimeInfo(LOCATION)
  updateTheme(darkModeStyle, timeInfo)
  // can't simply `setTimeout` to the next update time - if the app is sleeping at that time, the call seems to be lost
  window.setInterval(async () => {
    if (Date.now() > timeInfo.expires) {
      timeInfo = await loadTimeInfo(LOCATION)
    }
    updateTheme(darkModeStyle, timeInfo)
  }, 5 * 60 * 1000)
})

请注意,由于此过程直接修改应用程序文件,因此需要在每次 Slack 更新后重复此过程。

此答案无法解决桌面应用程序问题,但可用作仅基于浏览器的解决方案。

  1. 使用 Chrome 而不是可下载的 Slack 应用程序
  2. 安装Dark Reader chrome add-on
  3. 在 Chrome 而不是应用
  4. 中打开 Slack url(例如 https://team_name.slack.com/