Skip to content

Commit a3fa18e

Browse files
Dark mode (#36)
* css fixed * dark enabled always * funcs done * themeList refactor * SVG [PENDING] * README.md updated * fix svgs * navbar height styling * min width fixed * remove errors * css fixes * chrome whiteFlash removed * remove remove css statement * firefox whiteflash removed * darkmode scroll-bars * corner fixed * overall scroll fixed * scroll on hover * add comments to contentDark.js * height 8px * execution at the end * version change * comments change * remove event listener * Seperate imports from packages and local modules * CHROME_EXTENSION => NODE_ENV * gif updated Co-authored-by: Taveesh Anand <tavy.andy97@gmail.com>
1 parent cc4c5eb commit a3fa18e

File tree

16 files changed

+6755
-13
lines changed

16 files changed

+6755
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ SpanTree uses the following open-source packages:
5858
- [redux](https://github.com/reduxjs/redux)
5959
- [webext-redux](https://github.com/tshaddix/webext-redux)
6060
- [file-icons](https://github.com/file-icons/atom)
61+
- [dark-gitlab](https://gitlab.com/vednoc/dark-gitlab)
6162
- [axios](https://github.com/axios/axios)
6263
- [immer](https://github.com/immerjs/immer)

content/src/scripts/components/Pane/Pane.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SVG from "../SVG";
44
import TreeList from "../../containers/TreeList/TreeList";
55
import Resizer from "../../containers/Resizer/Resizer";
66
import { fetchURLDetails } from "../../utils/url";
7+
import { switchTheme } from "../../utils/themeList";
78

89
import "./styles.css";
910

@@ -35,8 +36,13 @@ function Pane({ toggleOpened, width, firstPageLoad, setFirstPageLoad }) {
3536
/>{" "}
3637
{URLDetails.dirFormatted}
3738
</div>
38-
<div onClick={toggleOpened} className="close-button">
39-
<SVG icon="close" height="12" />
39+
<div className="pane-icons">
40+
<span onClick={switchTheme} className="close-button">
41+
<SVG icon="half" height="9" />
42+
</span>
43+
<span onClick={toggleOpened} className="close-button">
44+
<SVG icon="close" height="12" />
45+
</span>
4046
</div>
4147
</div>
4248
<div className="pane-details" style={{ width: width - 12 + "px" }}>

content/src/scripts/components/Pane/styles.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
background-color: rgb(77, 61, 146);
2626
color: white;
2727
padding: 5px;
28+
display: flex;
29+
flex-direction: column;
30+
justify-content: space-around;
2831
}
2932

3033
.close-button {
3134
cursor: pointer;
35+
margin: 0 4px;
3236
}
3337

3438
.spread {
@@ -48,3 +52,7 @@
4852
text-overflow: ellipsis;
4953
font-weight: bold;
5054
}
55+
56+
.pane-icons{
57+
min-width: 35px;
58+
}

content/src/scripts/components/SVG/SVG.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from "react";
2+
23
import Branch from "./assets/Branch";
34
import Repo from "./assets/Repo";
45
import Close from "./assets/Close";
6+
import Half from "./assets/Half";
57

68
function SVG({ icon, height, style }) {
79
switch (icon) {
@@ -11,6 +13,8 @@ function SVG({ icon, height, style }) {
1113
return <Repo height={height} style={style} />;
1214
case "close":
1315
return <Close height={height} style={style} />;
16+
case "half":
17+
return <Half height={height} style={style} />;
1418
default:
1519
return "faulty svg";
1620
}

content/src/scripts/components/SVG/assets/Close.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Close({ height, style }) {
44
let heightSVG = height ? height : "16";
55
let widthSVG = height ? `${(3 * height) / 4}` : "12";
66
return (
7-
<svg width={widthSVG} height={heightSVG} viewBox="0 0 12 16" style={style}>
7+
<svg width={widthSVG} height={heightSVG} viewBox="0 0 12 12" style={style}>
88
<path d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48L7.48 8z" />
99
</svg>
1010
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
3+
function Half({ height, style }) {
4+
let heightSVG = height ? height : "9";
5+
let widthSVG = height ? height : "9";
6+
return (
7+
<svg height={heightSVG} width={widthSVG} viewBox="0 0 20 20" style={style}>
8+
<g id="Page-1" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
9+
<g id="Dribbble-Light-Preview" transform="translate(-180.000000, -4199.000000)" fill="#ffffff">
10+
<g id="icons" transform="translate(56.000000, 160.000000)">
11+
<path d="M126,4049 C126,4044.589 129.589,4041 134,4041 L134,4057 C129.589,4057 126,4053.411 126,4049 M134,4039 C128.477,4039 124,4043.477 124,4049 C124,4054.523 128.477,4059 134,4059 C139.523,4059 144,4054.523 144,4049 C144,4043.477 139.523,4039 134,4039" id="contrast-[#907]"></path>
12+
</g>
13+
</g>
14+
</g>
15+
</svg>
16+
);
17+
}
18+
19+
export default Half;

content/src/scripts/containers/TreeList/styles.css

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@
1313
}
1414

1515
.tree-list::-webkit-scrollbar-track {
16-
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.25);
17-
border-radius: 10px;
18-
background-color: #f5f5f5;
16+
background-color: #c9c9c9;
17+
}
18+
19+
.tree-list::-webkit-scrollbar-corner {
20+
background-color: #c9c9c9;
1921
}
2022

2123
.tree-list::-webkit-scrollbar {
2224
width: 8px;
2325
height: 8px;
24-
background-color: #f5f5f5;
2526
}
2627

2728
.tree-list::-webkit-scrollbar-thumb {
2829
border-radius: 10px;
2930
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
30-
background-color: rgba(0, 0, 0, 0.55);
31+
background-color: rgba(0, 0, 0, 0.50);
3132
}
3233

3334
.parent-list {

content/src/scripts/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const middleware = [thunkMiddleware];
1111
const storeWithMiddleware = applyMiddleware(proxyStore, ...middleware);
1212

1313
const anchor = document.createElement("div");
14-
1514
anchor.id = "rcr-anchor";
1615

1716
if (document.querySelector(".layout-page") !== null) {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// contentDark.js
2+
// As the main content.js is loaded on "document_idle", the dark theme needs to be loaded at the very beginning of
3+
// tab load to prevent a common phenomenon found in Chrome themes known as white flash. So this contentDark.js is
4+
// loaded on "document_start" and adds the darkGitlab.css to the <html> before the page starts loading.
5+
// Note: This file is not processed by webpack but is copied by gulp to the build/libs folder as is.
6+
7+
// themeList.js
8+
const isPresentInThemeList = () => {
9+
const domain = location.origin;
10+
let themeList = JSON.parse(localStorage.getItem("spantree-themelist")) || {};
11+
12+
return domain in themeList && themeList[domain];
13+
};
14+
15+
// browser.js
16+
const isWindowObject = (value) => {
17+
return value != null && typeof value === "object" && "setInterval" in value;
18+
};
19+
const freeSelf = isWindowObject(typeof self == "object" && self) && self;
20+
const navigator = freeSelf && freeSelf.navigator;
21+
const userAgent = ((navigator && navigator.userAgent) || "").toLowerCase();
22+
const vendor = ((navigator && navigator.vendor) || "").toLowerCase();
23+
const browserKey = () => {
24+
if (isChrome()) return "chrome";
25+
if (isFirefox()) return "moz";
26+
return "chrome";
27+
};
28+
const isChrome = () => {
29+
const match = /google inc/.test(vendor)
30+
? userAgent.match(/(?:chrome|crios)\/(\d+)/)
31+
: null;
32+
return match !== null && !isOpera();
33+
};
34+
const isFirefox = () => {
35+
const match = userAgent.match(/(?:firefox|fxios)\/(\d+)/);
36+
return match !== null;
37+
};
38+
const isOpera = () => {
39+
const match = userAgent.match(/(?:^opera.+?version|opr)\/(\d+)/);
40+
return match !== null;
41+
};
42+
43+
function fireContentLoadedEvent () {
44+
// Remove event listener
45+
document.removeEventListener('DOMContentLoaded', fireContentLoadedEvent);
46+
47+
// Insert CSS into Body
48+
const darkGitlab = document.createElement("link");
49+
darkGitlab.id = "spantree-theme";
50+
darkGitlab.disabled = !isPresentInThemeList();
51+
darkGitlab.rel = "stylesheet";
52+
darkGitlab.type = "text/css";
53+
darkGitlab.href = `${browserKey()}-extension://${chrome.i18n.getMessage(
54+
"@@extension_id"
55+
)}/libs/gitlab-dark.css`;
56+
document
57+
.querySelector("body")
58+
.insertBefore(darkGitlab, document.querySelector("body").childNodes[0]);
59+
60+
// Remove CSS from Head
61+
document.body.onload = () => {
62+
document.querySelector("#spantree-theme-temp").remove();
63+
};
64+
}
65+
66+
// Insert CSS into Head
67+
const darkGitlabTemp = document.createElement("link");
68+
darkGitlabTemp.id = "spantree-theme-temp";
69+
darkGitlabTemp.disabled = !isPresentInThemeList();
70+
darkGitlabTemp.rel = "stylesheet";
71+
darkGitlabTemp.type = "text/css";
72+
darkGitlabTemp.href = `${browserKey()}-extension://${chrome.i18n.getMessage(
73+
"@@extension_id"
74+
)}/libs/gitlab-dark.css`;
75+
document
76+
.querySelector("html")
77+
.insertBefore(darkGitlabTemp, document.querySelector("html").childNodes[0]);
78+
document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false);

0 commit comments

Comments
 (0)