Slack主题可以在网络应用程序中使用Stylish see https://userstyles.org/styles/browse?search_terms=slack
但是必须有一种方法可以在桌面应用程序上使用它们。什么是黑客?
更新,之前的黑客已停止使用4.0.0版本。
此解决方案的工作时间为2019年7月18日
见https://github.com/LanikSJ/slack-dark-mode
您可能需要查看有关https://github.com/LanikSJ/slack-dark-mode/issues/80的说明
当我有时间分配我上面发布的回购并改进它时,我可能会再次更新这个答案。
我写了一个小的“插件框架”,你只需运行一个shell脚本来修补你的松弛安装,然后你就可以启用我为桌面应用程序编写的任意数量的“插件”,一个其中一个黑暗的主题。如果您想加载自己在其他地方找到的CSS文件,请在README中有说明。
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更新后重复。
此答案不能解决桌面应用程序问题,但可以用作基于浏览器的解决方案。