Skip to content

Commit

Permalink
fix: using dark theme in day time or vice verse is not considered (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyn1998 authored Jul 12, 2022
1 parent 3b9e84f commit 1771cc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
11 changes: 1 addition & 10 deletions src/components/Graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ import {
} from '../../utils/utils';
import Settings, { loadSettings } from '../../utils/settings';

let githubTheme = getGithubTheme();
/*若是根据系统主题自动切换*/
if (githubTheme === 'auto') {
/*判断是否处于深色模式*/
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
githubTheme = 'dark';
} else {
githubTheme = 'light';
}
}
const githubTheme = getGithubTheme();

interface GraphProps {
/**
Expand Down
11 changes: 1 addition & 10 deletions src/pages/ContentScripts/DeveloperActiInflTrend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ import Settings, { loadSettings } from '../../utils/settings';
import { getDeveloperActiInfl } from '../../api/developer';
import Bars from '../../components/Bars/index';

let githubTheme = getGithubTheme();
/*若是根据系统主题自动切换*/
if (githubTheme === 'auto') {
/*判断是否处于深色模式*/
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
githubTheme = 'dark';
} else {
githubTheme = 'light';
}
}
const githubTheme = getGithubTheme();

interface DeveloperActiInflTrendViewProps {
currentDeveloper: string;
Expand Down
11 changes: 1 addition & 10 deletions src/pages/ContentScripts/RepoActiInflTrend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ import { utils } from 'github-url-detection';
import { getRepoActiInfl } from '../../api/repo';
import Bars from '../../components/Bars/index';

let githubTheme = getGithubTheme();
/*若是根据系统主题自动切换*/
if (githubTheme === 'auto') {
/*判断是否处于深色模式*/
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
githubTheme = 'dark';
} else {
githubTheme = 'light';
}
}
const githubTheme = getGithubTheme();

interface RepoActiInflTrendViewProps {
currentRepo: string;
Expand Down
27 changes: 26 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,32 @@ export function runsWhen(rules: any[]) {
}

export function getGithubTheme() {
return $('[data-color-mode]')[0].dataset['colorMode'];
// following 3 variables are extracted from GitHub page's html tag properties
// colorMode has 3 values: "auto", "light" and "dark"
// lightTheme and darkTheme means "theme in day time" and "theme in night time" respectively
const colorMode = $('[data-color-mode]')[0].dataset['colorMode'];
const lightTheme = $('[data-light-theme]')[0].dataset['lightTheme'];
const darkTheme = $('[data-dark-theme]')[0].dataset['darkTheme'];

let githubTheme = colorMode;

if (colorMode === 'auto') {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
if (darkTheme?.startsWith('dark')) {
githubTheme = 'dark';
} else {
githubTheme = 'light';
}
} else {
if (lightTheme?.startsWith('dark')) {
githubTheme = 'dark';
} else {
githubTheme = 'light';
}
}
}

return githubTheme;
}

export function getMinMax(data: INode[] | IEdge[]) {
Expand Down

0 comments on commit 1771cc7

Please sign in to comment.