From 13e0932ef78fe093ffbd22a10b5498d5ff9fca6e Mon Sep 17 00:00:00 2001 From: odnar-dev <73726132+odnar-dev@users.noreply.github.com> Date: Thu, 18 Mar 2021 22:39:00 +0100 Subject: [PATCH 1/4] adapt to github's night mode --- project/useful-forks.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/project/useful-forks.js b/project/useful-forks.js index 60d8f235..29a2fd72 100644 --- a/project/useful-forks.js +++ b/project/useful-forks.js @@ -9,13 +9,43 @@ const UF_ID_TABLE = 'useful_forks_table'; const svg_literal_fork = ''; const svg_literal_star = ''; +function getSyntaxTheme() { + switch (document.querySelector('[data-color-mode]')?.dataset.colorMode) { + case 'dark': { + return "dark" + break + } + + case 'auto': { + if ( + window.matchMedia && + window.matchMedia('(prefers-color-scheme: dark)').matches + ) { + return "dark" + break + } + } + + case 'light': + default: { + return "light" + } + } +} + +let SyntaxTheme = getSyntaxTheme(); + +const hovercolor = SyntaxTheme == "dark" ? '#424242' : '#e2e2e2'; + +const tr_bgcolor = SyntaxTheme == "dark" ? '#333' : '#f5f5f5'; + const additional_css_literal = ` .uf_badge svg { display: table-cell; padding-top: 3px; } -tr:hover {background-color: #e2e2e2 !important;} -tr:nth-child(even) {background-color: #f5f5f5;} +tr:hover {background-color: ${hovercolor} !important;} +tr:nth-child(even) {background-color: ${tr_bgcolor};} #${UF_ID_MSG} {color: red} `; From 53d813ce746862615d2fe85a6375f77471f7f074 Mon Sep 17 00:00:00 2001 From: payne911 <38117856+payne911@users.noreply.github.com> Date: Thu, 18 Mar 2021 23:33:30 -0400 Subject: [PATCH 2/4] * Slightly different colors * Minor code style touch ups * Fixed needlessly global CSS variables --- project/useful-forks.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/project/useful-forks.js b/project/useful-forks.js index 29a2fd72..738fce24 100644 --- a/project/useful-forks.js +++ b/project/useful-forks.js @@ -308,10 +308,36 @@ function prepare_display() { ); } +/** To determine if Dark Mode is enabled. */ +function getGitHubTheme() { + let colorMode = document.querySelector('[data-color-mode]')?.dataset.colorMode; + if (colorMode === 'dark') { + return "dark"; + } else if (colorMode === 'auto') { + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + return "dark"; + } + } + return "light"; // default +} + function add_css() { + const GITHUB_THEME = getGitHubTheme(); + const TR_HOVER_COLOR = GITHUB_THEME === "dark" ? '#2f353e' : '#e2e2e2'; + const TR_BG_COLOR = GITHUB_THEME === "dark" ? '#161b22' : '#f5f5f5'; + const ADDITIONAL_CSS = ` + .uf_badge svg { + display: table-cell; + padding-top: 3px; + } + tr:hover {background-color: ${TR_HOVER_COLOR} !important;} + tr:nth-child(even) {background-color: ${TR_BG_COLOR};} + #${UF_ID_MSG} {color: red;} + `; + let styleSheet = document.createElement('style'); styleSheet.type = "text/css"; - styleSheet.innerText = additional_css_literal; + styleSheet.innerText = ADDITIONAL_CSS; document.head.appendChild(styleSheet); } From 6db3dc8931be5841d2a76f64864be3afe508efbf Mon Sep 17 00:00:00 2001 From: payne911 <38117856+payne911@users.noreply.github.com> Date: Thu, 18 Mar 2021 23:35:45 -0400 Subject: [PATCH 3/4] * Removed deprecated tags on SVGs * Fix IntelliJ commit bug --- project/useful-forks.js | 44 ++--------------------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/project/useful-forks.js b/project/useful-forks.js index 738fce24..b895c2a4 100644 --- a/project/useful-forks.js +++ b/project/useful-forks.js @@ -6,48 +6,8 @@ const UF_ID_MSG = 'useful_forks_msg'; const UF_ID_DATA = 'useful_forks_data'; const UF_ID_TABLE = 'useful_forks_table'; -const svg_literal_fork = ''; -const svg_literal_star = ''; - -function getSyntaxTheme() { - switch (document.querySelector('[data-color-mode]')?.dataset.colorMode) { - case 'dark': { - return "dark" - break - } - - case 'auto': { - if ( - window.matchMedia && - window.matchMedia('(prefers-color-scheme: dark)').matches - ) { - return "dark" - break - } - } - - case 'light': - default: { - return "light" - } - } -} - -let SyntaxTheme = getSyntaxTheme(); - -const hovercolor = SyntaxTheme == "dark" ? '#424242' : '#e2e2e2'; - -const tr_bgcolor = SyntaxTheme == "dark" ? '#333' : '#f5f5f5'; - -const additional_css_literal = ` -.uf_badge svg { - display: table-cell; - padding-top: 3px; -} -tr:hover {background-color: ${hovercolor} !important;} -tr:nth-child(even) {background-color: ${tr_bgcolor};} -#${UF_ID_MSG} {color: red} -`; +const svg_literal_fork = ''; +const svg_literal_star = ''; const UF_MSG_HEADER = "Useful forks"; const UF_MSG_NO_FORKS = "No one forked this specific repository."; From 7a20649d4cbad0a484c3d547bdae15f2452ffd7d Mon Sep 17 00:00:00 2001 From: payne911 <38117856+payne911@users.noreply.github.com> Date: Thu, 18 Mar 2021 23:47:06 -0400 Subject: [PATCH 4/4] * Bump plugin version * Improve plugin description --- project/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/manifest.json b/project/manifest.json index f678d991..6c62c44d 100644 --- a/project/manifest.json +++ b/project/manifest.json @@ -1,7 +1,7 @@ { "name": "Useful Forks", - "version": "1.5", - "description": "Displays GitHub forks ordered by stars, and with additional information and automatic filters.", + "version": "1.6", + "description": "Displays GitHub forks ordered by stars, with additional information and automatic filtering of irrelevant ones.", "permissions": [ "*://github.com/*", "*://api.github.com/*",