JS 捕获键盘快捷键(组合键)

  • 使用 onkeydown (or onkeyup) 事件,而不是 onkeypress
function handleKeyEvent(e) {
	// ctrl/meta + enter
	if (e.keyCode == 13) {
	// if (e.key == "Enter") {
		if (e.ctrlKey || e.metaKey) {
		alert("ctrl/meta + enter")
		}
	}
}

document.onkeydown = KeyPress;
  • Alt key, e.altKey
  • Ctrl + Z, keyCode==90 and e.ctrlKey

Web 网页随浏览器切换亮暗主题色

使用 color-scheme 让网页随浏览器自动切换亮暗主题色(dark/light themes)

HTML:

<meta name="color-scheme" content="light dark">

CSS:

:root {
	color-scheme: light dark; /* both supported */

	/* defaults to light theme */
	--text-color: black;
	--bkg-color: white;
}



@media (prefers-color-scheme: dark) {
	:root{
	  /* for dark theme */
		--text-color: white;
		--bkg-color: black;
	}
}

body {
  background: var(--bkg-color);
  color: var(--text-color);
}
<html>
<head>
<link rel="icon" href="/favicon-light.png" type="image/png" media="(prefers-color-scheme: light)"/>
<link rel="icon" href="/favicon-dark.png" type="image/png" media="(prefers-color-scheme: dark)"/>
</head>
</html>

journalctl 清理日志

使用 journalctl 命令清理 systemd 等产品的日志。

根据时间清理旧的日志文件:

sudo journalctl --vacuum-time=1years

--vacuum-time 选项用于指定保留日志文件的时间跨度。
单位也可以是:1months3days

根据体积清理旧的日志文件:

pm2 定时执行任务

可使用 --cron 参数指定执行周期,但是如果仅使用该参数,例如

pm2 start task.js --cron "*/15 * * * *"

PM2 将启动您的 cron 作业,但它也会在作业程序完成后不断重新启动 cron 作业,无限循环。

macOS 的守护程序和服务

Daemons and Services in macOS

  • 守护程序: launchd。类似 Linux 中的 systemd,负责初始化、加载、启/停和管理系统服务。
  • 管理命令: launchctl。 类似 Linux 中的 systemctl
  • 配置文件类型是 .plist。存放路径:
    • /Library/LaunchDaemons/,无论是否有任何用户登录系统,它们都应运行。 它们将以“root”权限启动。
    • /Library/LaunchAgents,任意用户登录后
    • ~/Library/LaunchAgents/,某(当前)用户登录后

      其中 ~ 是您的主目录。 这些任务将使用您的权限运行,就像您自己通过命令行或双击 Finder 中的文件启动它们一样。

免费可商用中文字体及资源

收集整理的🆓免费可商用的中文字体清单。且多数是开源字体。

  • 思源宋体,许可证是 SIL Open Font License,🆓可免费商用
    是由 Adobe 公司开发和发表的开源字体