Git-SCM Background Color Changer

Dynamically replace the background color of Git-SCM pages based on the system theme

2025-02-19 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Git-SCM Background Color Changer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Dynamically replace the background color of Git-SCM pages based on the system theme
// @author       mcwindy
// @match        https://git-scm.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  const darkModeBg = '#1B1B1B'; // for dark mode
  const lightModeBg = '#fff'; // for light mode

  // Detection system theme
  const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;

  const bgColor = isDarkMode ? darkModeBg : lightModeBg;

  const bodyElement = document.querySelector('body');
  if (bodyElement) {
    bodyElement.style.background = bgColor;
  }

  // Replace the background attribute in all style sheets
  const styleSheets = document.styleSheets;
  for (let i = 0; i < styleSheets.length; i++) {
    const styleSheet = styleSheets[i];
    try {
      const cssRules = styleSheet.cssRules || styleSheet.rules;
      for (let j = 0; j < cssRules.length; j++) {
        const rule = cssRules[j];
        if (rule.selectorText === 'body' && rule.style.background) {
          rule.style.background = bgColor;
        }
      }
    } catch (e) {
      // Cross-domain style sheet cannot be accessed, ignored
    }
  }
})();