如何在桌面应用程序上以夜间模式运行Slack

时间:2018-03-17 10:35:10

标签: themes desktop slack

使用时尚的https://userstyles.org/styles/browse?search_terms=slack

在Web应用程序中提供了Slack主题

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

3 个答案:

答案 0 :(得分:1)

已更新!重要事项请在使用此脚本之前分叉git repo并更新ajax中的URL以从fork中提取。另请参阅instructions on the gist

这里提供了黑客https://github.com/laCour/slack-night-mode/issues/73,但我编写了一个红宝石脚本,可以在日夜模式之间轻松切换。

以下是ruby代码,但请确保在分配后使用您的用户名替换GITHUB_USERNAME

#!/usr/bin/env ruby
js_code = <<-JS
document.addEventListener('DOMContentLoaded', async function() {
  const initTheme = themeCssUrl => new Promise(resolve => $.ajax({
    url: themeCssUrl,
    success: css => {
      const styleJqueryEl = $('<style>').html(css).appendTo('head')
      const styleElement = styleJqueryEl[0]
      resolve(styleElement)
    }
  }))
  initTheme("#{remote_repo}")
})
JS

@file_target = '/Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js'
`cp #{@file_target} #{@file_target}.bak`
@current_file = File.read(@file_target) 
@normal_mode = @day_mode_set ? @current_file : 
@current_file.split(js_code).first
@night_mode = @normal_mode + js_code

use_day_mode = ARGV[0] == '-d'
def set_mode(mode)
  if mode == 'd'
    File.open(@file_target, 'w'){|f| f.puts @normal_mode}
        puts "Slack Normal (day) mode has been set!"
  else
    File.open(@file_target, 'w'){|f| f.puts @night_mode}
        puts "Slack Normal night mode has been set!"
  end
end

use_day_mode ? set_mode('d') : set_mode('n')

或者您可以从这个要点中复制:https://gist.github.com/lacostenycoder/23d05ace816de0f39e9e6aa940172b91

使用chmod +x nightslack.rb和/或删除.rb使文件可执行,并在/usr/local/bin/或您保存可执行文件的任何位置对其进行符号链接。

答案 1 :(得分:1)

Here是我的脚本,可以在日出/日落时自动在亮和暗模式之间切换。在/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更新后都需要重复执行该过程。

答案 2 :(得分:0)

最简单的方法

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