// ==UserScript== // @name GitHub Latte // @namespace github-latte-pure-theme // @version 3.0.0 // @description GitHub Catppuccin Latte 浅色主题 // @tag github theme // @author deran // @grant GM_addStyle // @run-at document-start // @license MIT // @match *://*.github.com/* // ==/UserScript== (() => { 'use strict'; /* Catppuccin Latte,只列用到的几档 */ const latte = { base: '#eff1f5', mantle: '#e6e9ef', crust: '#dce0e8', surface0: '#ccd0da', surface1: '#bcc0cc', overlay1: '#8c8fa1', subtext0: '#6c6f85', subtext1: '#5c5f77', text: '#4c4f69', blue: '#1e66f5', green: '#40a02b', red: '#d20f39', yellow: '#df8e1d', mauve: '#8839ef', }; // GitHub 的界面颜色全部来自 Primer 语义变量(--bgColor-* / --fgColor-* / // --borderColor-* / --button-*),覆盖它们等于换掉整块画布、文字和描边。 // 这些变量定义在 [data-color-mode] 属性选择器上,权重高,必须 !important。 // // 原生 GitHub 浅色主题就是「页面与卡片同色、靠描边分隔」的平铺结构, // 所以 default 直接给画布,层次交给 muted / inset / border 三档。 const vars = { /* 画布与浮层 */ '--bgColor-default': latte.base, '--overlay-bgColor': latte.base, /* 次级容器、侧栏、表头 */ '--bgColor-muted': latte.mantle, '--bgColor-inset': latte.mantle, '--bgColor-emphasis': latte.surface0, '--bgColor-disabled': latte.mantle, '--bgColor-neutral-muted': latte.crust, '--bgColor-transparent': 'transparent', /* 旧版别名(部分老组件仍在用) */ '--color-canvas-default': latte.base, '--color-canvas-subtle': latte.mantle, '--color-canvas-inset': latte.mantle, '--color-notifications-row-bg': latte.base, '--color-notifications-row-read-bg': latte.mantle, /* 文字 */ '--fgColor-default': latte.text, '--fgColor-muted': latte.subtext0, '--fgColor-subtle': latte.overlay1, '--fgColor-onEmphasis': latte.base, '--color-fg-default': latte.text, '--color-fg-muted': latte.subtext0, '--color-fg-subtle': latte.overlay1, /* 描边 */ '--borderColor-default': latte.crust, '--borderColor-muted': latte.crust, '--borderColor-emphasis': latte.surface1, '--color-border-default': latte.crust, '--color-border-muted': latte.crust, /* 按钮 */ '--button-default-bgColor-rest': latte.mantle, '--button-default-bgColor-hover': latte.crust, '--button-default-bgColor-active': latte.surface0, '--button-default-bgColor-selected': latte.crust, '--button-default-fgColor-rest': latte.text, '--button-default-borderColor-rest': latte.crust, '--button-default-borderColor-hover': latte.surface1, '--button-default-borderColor-active': latte.surface1, /* 强调色:主按钮、链接、状态徽标 */ '--bgColor-accent-emphasis': latte.blue, '--bgColor-success-emphasis': latte.green, '--bgColor-danger-emphasis': latte.red, '--bgColor-attention-emphasis': latte.yellow, '--bgColor-done-emphasis': latte.mauve, '--fgColor-accent': latte.blue, '--fgColor-success': latte.green, '--fgColor-danger': latte.red, '--color-accent-fg': latte.blue, '--color-btn-primary-bg': latte.blue, }; const declarations = Object.entries(vars) .map(([name, value]) => `${name}: ${value} !important;`) .join('\n '); GM_addStyle(` /* ============ 1. 变量层 ============ */ html, body { ${declarations} } /* 顶部导航在 GitHub 原生浅色主题里本来就是深底, 这里刻意不碰:改浅会与白色 logo、深色图标打架。 */ /* ============ 2. 少数写死颜色的组件 ============ */ /* 代码块:统一内陷色,行号区同色避免拼缝 */ .react-code-file-contents, .react-code-lines, .react-line-numbers, .blob-code, .blob-num, .highlight, .highlight pre, pre { background-color: ${latte.mantle} !important; background-image: none !important; } /* 代码内联元素保持透明,避免叠加色块 */ pre span, code span, .pl-s, .pl-k, .pl-c, .pl-e, .pl-pds, .pl-en { background-color: transparent !important; } /* ============ 3. 选中与滚动条 ============ */ ::selection { background-color: ${latte.surface1} !important; color: ${latte.text} !important; } html { scrollbar-color: ${latte.surface1} transparent; } ::-webkit-scrollbar { width: 10px; height: 10px; } ::-webkit-scrollbar-thumb { background-color: ${latte.surface1}; border: 2px solid transparent; border-radius: 999px; background-clip: content-box; } ::-webkit-scrollbar-thumb:hover { background-color: ${latte.overlay1}; } `); })();