Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions extension/public/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ <h2 id="account-heading" class="visually-hidden">Account</h2>
</svg>
</div>
</div>

<!-- Display Mode Section -->
<div class="popup__setting">
<label class="popup__setting-label" for="displayMode"
>Display Mode</label
>
<select
id="displayMode"
class="popup__setting-select"
aria-label="Choose badge display mode"
>
<option value="full">Default</option>
<option value="compact">Compact</option>
</select>
</div>

<button
id="logoutBtn"
class="popup__btn popup__btn--danger"
Expand Down
80 changes: 72 additions & 8 deletions extension/public/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
:root {
--badge-dark-bg: rgba(110, 118, 129, 0.15);
--badge-dark-color: #e6edf3;
--badge-dark-border: rgba(110, 118, 129, 0.3);
--badge-dark-dot-shadow: 0 0 0 1px rgba(13, 17, 23, 0.4);
--badge-dark-compact-border: rgba(13, 17, 23, 0.8);
--badge-dark-compact-shadow: 0 0 0 1px rgba(205, 217, 229, 0.1),
0 1px 2px rgba(1, 4, 9, 0.3);
--badge-dark-compact-hover-shadow: 0 0 0 2px rgba(13, 17, 23, 0.8),
0 0 0 3px rgba(205, 217, 229, 0.15), 0 2px 8px rgba(1, 4, 9, 0.4);
}

.Title-module__container--XD9YG {
display: flex !important;
align-items: center !important;
Expand Down Expand Up @@ -30,6 +42,7 @@
border: 1px solid rgba(208, 215, 222, 0.8);
box-sizing: border-box;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
cursor: default;
}

.project-status-badge::before {
Expand All @@ -45,30 +58,81 @@
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
}

.project-status-badge--compact {
width: 10px;
height: 10px;
padding: 0;
border-radius: 50%;
background-color: var(--status-color);
border: 2px solid #ffffff;
box-shadow: 0 0 0 1px rgba(31, 35, 40, 0.15), 0 1px 2px rgba(31, 35, 40, 0.12);
cursor: help;
min-width: auto !important;
font-size: 0;
line-height: 0;
transition: transform 0.15s cubic-bezier(0.2, 0, 0.38, 0.9),
box-shadow 0.15s cubic-bezier(0.2, 0, 0.38, 0.9);
}

.project-status-badge--compact::before {
display: none;
}

.project-status-badge--compact:hover {
transform: scale(1.3);
box-shadow: 0 0 0 2px #ffffff, 0 0 0 3px rgba(31, 35, 40, 0.2),
0 2px 8px rgba(31, 35, 40, 0.18);
z-index: 1;
}

.project-status-badge--compact:focus-visible {
outline: 2px solid #0969da;
outline-offset: 2px;
transform: scale(1.3);
}

/* Dark mode styles - supports both system preference and GitHub's manual theme selection */
@media (prefers-color-scheme: dark) {
.project-status-badge {
background-color: rgba(110, 118, 129, 0.15);
color: #e6edf3;
border: 1px solid rgba(110, 118, 129, 0.3);
background-color: var(--badge-dark-bg);
color: var(--badge-dark-color);
border: 1px solid var(--badge-dark-border);
box-shadow: none;
}

.project-status-badge::before {
opacity: 0.85;
box-shadow: 0 0 0 1px rgba(13, 17, 23, 0.4);
box-shadow: var(--badge-dark-dot-shadow);
}

.project-status-badge--compact {
border-color: var(--badge-dark-compact-border);
box-shadow: var(--badge-dark-compact-shadow);
}

.project-status-badge--compact:hover {
box-shadow: var(--badge-dark-compact-hover-shadow);
}
}

/* GitHub manual dark theme selection (data-color-mode="dark") */
[data-color-mode="dark"] .project-status-badge {
background-color: rgba(110, 118, 129, 0.15);
color: #e6edf3;
border: 1px solid rgba(110, 118, 129, 0.3);
background-color: var(--badge-dark-bg);
color: var(--badge-dark-color);
border: 1px solid var(--badge-dark-border);
box-shadow: none;
}

[data-color-mode="dark"] .project-status-badge::before {
opacity: 0.85;
box-shadow: 0 0 0 1px rgba(13, 17, 23, 0.4);
box-shadow: var(--badge-dark-dot-shadow);
}

[data-color-mode="dark"] .project-status-badge--compact {
border-color: var(--badge-dark-compact-border);
box-shadow: var(--badge-dark-compact-shadow);
}

[data-color-mode="dark"] .project-status-badge--compact:hover {
box-shadow: var(--badge-dark-compact-hover-shadow);
}
Comment on lines 118 to 138

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The style rules for [data-color-mode="dark"] from line 119 to 138 are duplicates of the rules within the @media (prefers-color-scheme: dark) block (lines 95-116). This introduces code duplication, which goes against the repository's style guide (L15: 'when you see signs of reuse, modularize it to avoid code duplication').

For better maintainability, it's recommended to avoid repeating these blocks of CSS. While handling both system preference and manual theme selection in pure CSS can be tricky, this duplication can make future updates error-prone and harder to maintain.

Style Guide References

59 changes: 53 additions & 6 deletions extension/public/styles/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
--btn-primary-hover: #1f2328;
--btn-primary-active: #1c2128;
--btn-primary-shadow: 0 1px 0 rgba(31, 35, 40, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.03);
inset 0 1px 0 rgba(255, 255, 255, 0.03);

--btn-danger-bg: #cf222e;
--btn-danger-hover: #a40e26;
Expand All @@ -63,7 +63,7 @@

/* Typography */
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans",
Helvetica, Arial, sans-serif;
Helvetica, Arial, sans-serif;
--font-size-xs: 12px;
--font-size-sm: 13px;
--font-size-base: 14px;
Expand Down Expand Up @@ -217,8 +217,7 @@ body {
.popup__btn--primary:hover:not(:disabled) {
background-color: var(--btn-github-hover);
border-color: rgba(31, 35, 40, 0.25);
box-shadow: 0 1px 0 rgba(31, 35, 40, 0.1),
0 0 0 3px rgba(36, 41, 47, 0.1);
box-shadow: 0 1px 0 rgba(31, 35, 40, 0.1), 0 0 0 3px rgba(36, 41, 47, 0.1);
}

.popup__btn--primary:active:not(:disabled) {
Expand Down Expand Up @@ -309,7 +308,11 @@ body {
width: 40px;
height: 40px;
border-radius: var(--radius-full);
background: linear-gradient(135deg, var(--color-success-emphasis) 0%, var(--color-accent-emphasis) 100%);
background: linear-gradient(
135deg,
var(--color-success-emphasis) 0%,
var(--color-accent-emphasis) 100%
);
display: flex;
align-items: center;
justify-content: center;
Expand Down Expand Up @@ -467,7 +470,8 @@ body {
}

@keyframes successPulse {
0%, 100% {
0%,
100% {
transform: scale(1);
}
50% {
Expand All @@ -479,6 +483,49 @@ body {
animation: successPulse 0.5s ease-out;
}

/* ============================================
Settings
============================================ */

.popup__setting {
margin-bottom: var(--space-4);
padding: var(--space-4);
background-color: var(--color-canvas-subtle);
border: 1px solid var(--color-border-muted);
border-radius: var(--radius-md);
}

.popup__setting-label {
display: block;
font-size: var(--font-size-sm);
font-weight: var(--font-weight-medium);
color: var(--color-fg-default);
margin-bottom: var(--space-2);
}

.popup__setting-select {
width: 100%;
padding: var(--space-2) var(--space-3);
font-family: inherit;
font-size: var(--font-size-sm);
color: var(--color-fg-default);
background-color: var(--color-canvas-default);
border: 1px solid var(--color-border-default);
border-radius: var(--radius-md);
cursor: pointer;
transition: all var(--transition-fast);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using transition: all can be inefficient as it causes the browser to watch for changes on all animatable properties, which can negatively impact performance. It's a best practice to specify only the properties you intend to transition. In this case, you are transitioning border-color and box-shadow.1

Suggested change
transition: all var(--transition-fast);
transition: border-color var(--transition-fast), box-shadow var(--transition-fast);

Style Guide References

Footnotes

  1. Prioritize code readability over code efficiency, but also optimize for efficiency when possible.

}

.popup__setting-select:hover {
border-color: var(--color-accent-emphasis);
}

.popup__setting-select:focus {
outline: none;
border-color: var(--color-accent-emphasis);
box-shadow: 0 0 0 3px var(--color-accent-bg);
}

/* ============================================
Utilities
============================================ */
Expand Down
84 changes: 73 additions & 11 deletions extension/src/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(() => {
type DisplayMode = "compact" | "full";

type IssueStatus = {
color: string | null;
number: number;
Expand All @@ -18,8 +20,10 @@
};

const BADGE_CLASS = "project-status-badge";
const BADGE_COMPACT_CLASS = "project-status-badge--compact";
const DEBOUNCE_DELAY_MS = 500;
const DEFAULT_BADGE_COLOR = "#6e7781";
const DISPLAY_MODE_KEY = "displayMode";
const GITHUB_ISSUES_URL_PATTERN =
/https:\/\/github\.com\/[^/]+\/[^/]+\/issues/;
const ISSUE_LINK_SELECTOR = '[data-testid="issue-pr-title-link"]';
Expand Down Expand Up @@ -66,21 +70,74 @@
return maxWidth;
};

const updateBadgeWidths = () => {
const updateBadgeWidths = async () => {
const displayMode = await getDisplayMode();
if (displayMode === "compact") return;

const maxWidth = calculateMaxBadgeWidth();
if (maxWidth === 0) return;

const badges = document.querySelectorAll(`.${BADGE_CLASS}`);
const badges = document.querySelectorAll(
`.${BADGE_CLASS}:not(.${BADGE_COMPACT_CLASS})`
);
badges.forEach((badge) => {
(badge as HTMLElement).style.minWidth = `${maxWidth}px`;
});
};

const addStatusBadge = (
const updateBadgeDisplay = async (
badge: HTMLElement,
displayMode: DisplayMode,
status: string
) => {
if (displayMode === "compact") {
badge.classList.add(BADGE_COMPACT_CLASS);
badge.textContent = "";
badge.title = status;
badge.setAttribute("role", "img");
badge.setAttribute("aria-label", `Status: ${status}`);
badge.tabIndex = 0;
badge.style.minWidth = "";
} else {
badge.classList.remove(BADGE_COMPACT_CLASS);
badge.textContent = status;
badge.title = "";
badge.removeAttribute("role");
badge.removeAttribute("aria-label");
badge.tabIndex = -1;
}
};

const refreshAllBadges = async () => {
const displayMode = await getDisplayMode();
const badges = document.querySelectorAll(`.${BADGE_CLASS}`);

for (const badge of Array.from(badges)) {
const statusText = badge.getAttribute("data-status");
if (statusText) {
await updateBadgeDisplay(badge as HTMLElement, displayMode, statusText);
}
}

if (displayMode === "full") {
requestAnimationFrame(() => {
updateBadgeWidths();
});
}
};

const getDisplayMode = async (): Promise<DisplayMode> => {
const result = await chrome.storage.sync.get([DISPLAY_MODE_KEY]);
const value = result[DISPLAY_MODE_KEY];
return value === "compact" ? "compact" : "full";
};

const addStatusBadge = async (
issueNumber: number,
status: string,
color: string | null
) => {
const displayMode = await getDisplayMode();
const issueLinks = document.querySelectorAll(ISSUE_LINK_SELECTOR);

for (const link of Array.from(issueLinks)) {
Expand All @@ -97,9 +154,11 @@

const badge = document.createElement("span");
badge.className = BADGE_CLASS;
badge.textContent = status;
badge.setAttribute("data-status", status);
badge.style.setProperty("--status-color", color || DEFAULT_BADGE_COLOR);

await updateBadgeDisplay(badge, displayMode, status);

container.insertBefore(badge, h3Element);
return;
}
Expand Down Expand Up @@ -142,15 +201,13 @@

const statuses = response.statuses || [];

statuses.forEach(({ color, number, status }) => {
for (const { color, number, status } of statuses) {
if (status) {
addStatusBadge(number, status, color);
await addStatusBadge(number, status, color);
}
});
}

requestAnimationFrame(() => {
updateBadgeWidths();
});
await updateBadgeWidths();
} catch (error) {
// Silent fail
} finally {
Expand Down Expand Up @@ -235,7 +292,12 @@

chrome.runtime.onMessage.addListener((message) => {
if (message.type === "RELOAD_BADGES") {
updateIssueStatuses();
const badges = document.querySelectorAll(`.${BADGE_CLASS}`);
if (badges.length > 0) {
refreshAllBadges();
} else {
updateIssueStatuses();
}
}
});

Expand Down
Loading