Skip to content

refactor: simplify LinkedIn panel hiding#15

Merged
ArsalaBangash merged 2 commits intomainfrom
ArsalaBangash/simplify-linkedin
Mar 1, 2026
Merged

refactor: simplify LinkedIn panel hiding#15
ArsalaBangash merged 2 commits intomainfrom
ArsalaBangash/simplify-linkedin

Conversation

@ArsalaBangash
Copy link
Member

@ArsalaBangash ArsalaBangash commented Mar 1, 2026

Summary

  • Replaced DOM-walking algorithm for LinkedIn panel hiding with simple CSS selector queries via PANEL_SELECTORS, matching the same pattern YouTube uses for all its regions
  • Removed ~90 lines of dead code from linkedin-utils.ts (11 unused functions/constants from an older implementation)
  • Simplified isHomePage from 8 overlapping string/regex checks to a single regex

Test plan

  • Load extension in Chrome, navigate to linkedin.com/feed
  • Verify full focus mode hides both feed and side panels
  • Verify custom focus mode hides only side panels, keeps feed visible
  • Verify unfocus restores everything
  • All 32 existing tests pass (npm test)
  • Selector health tests pass (selector-contract.test.ts)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Streamlined LinkedIn panel detection and hiding with a selector-based approach for more consistent removal of sidebar/content panels.
    • Replaced older DOM-walking heuristics with consolidated utilities for panel discovery and hidden-state checks.
  • Bug Fixes

    • More reliable detection of page/home state and panel visibility to reduce missed or duplicate panels.

… of DOM walking

LinkedIn panel hiding now follows the same pattern as YouTube: query PANEL_SELECTORS
directly instead of walking the DOM tree to find sibling columns. Also removes ~90 lines
of dead code from linkedin-utils and simplifies isHomePage from 8 overlapping checks to
a single regex.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97a151a and 7170fb0.

📒 Files selected for processing (1)
  • src/ts/websites/linkedin/linkedin-controller.ts

📝 Walkthrough

Walkthrough

Refactors LinkedIn panel detection/hiding: utilities now return multiple panels via getLinkedInPanels() and expose arePanelsHidden(). Controller replaces DOM-walking helpers with a new hidePanels() method and updates observer config to use the consolidated utility APIs; several ad-related helpers/exports removed.

Changes

Cohort / File(s) Summary
Panel Hiding Refactor
src/ts/websites/linkedin/linkedin-controller.ts
Added private hidePanels() and replaced calls to DOM-walking helpers (hidePanelCandidates, findFeedRowContainer, getRightPanelCandidates) with hidePanels(). Updated distraction observer to use LinkedInUtils.getLinkedInPanels() for load detection, LinkedInUtils.arePanelsHidden for visibility checks, and hidePanels() to hide elements. Removed three private helper methods.
Utility API Consolidation
src/ts/websites/linkedin/linkedin-utils.ts
Replaced getLinkedInPanel() with getLinkedInPanels(): HTMLElement[]. Renamed isPanelHidden()arePanelsHidden() and updated logic to evaluate all panels. Removed ad-related selectors/exports and multi-container/observer helpers (AD_SELECTORS, FEED_AD_SELECTORS, getAdHeader, getFeedAdElements, getAllObservableContainers, isLinkedInContentLoaded). Simplified isHomePage() to a URL regex check. Export surface updated accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 I hopped through selectors, one by one,
Collected panels until the job was done.
I swapped the old tricks for a tidy new sweep,
Quiet feeds now settle, and code can sleep.
🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: simplify LinkedIn panel hiding' is directly related to the main change in the changeset, which involves replacing DOM-walking panel hiding with a CSS-selector-based approach and removing dead code.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ArsalaBangash/simplify-linkedin

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/ts/websites/linkedin/linkedin-utils.ts (1)

27-35: Collect all matching elements to match the function contract.

document.querySelector only returns the first match per selector, but getLinkedInPanels() is documented/typed as returning all panel elements. Using querySelectorAll + dedupe is safer.

♻️ Proposed refactor
 /** Returns all panel elements matching PANEL_SELECTORS. */
 function getLinkedInPanels(): HTMLElement[] {
-  const panels: HTMLElement[] = []
+  const panels = new Set<HTMLElement>()
   for (const selector of PANEL_SELECTORS) {
-    const el = document.querySelector(selector) as HTMLElement | null
-    if (el) panels.push(el)
+    document.querySelectorAll<HTMLElement>(selector).forEach((el) => {
+      panels.add(el)
+    })
   }
-  return panels
+  return Array.from(panels)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ts/websites/linkedin/linkedin-utils.ts` around lines 27 - 35,
getLinkedInPanels currently uses document.querySelector which returns only the
first match for each selector but the function is typed/documented to return all
matching panels; change implementation of getLinkedInPanels to use
document.querySelectorAll for each selector, convert each NodeList to an array,
push all matches into a single collection and dedupe (e.g., via a Set or
filtering by identity) before returning so the result is an array of unique
HTMLElement instances; keep references to PANEL_SELECTORS and the function name
getLinkedInPanels to locate and update the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/ts/websites/linkedin/linkedin-controller.ts`:
- Around line 101-104: The callback passed to forEach in hidePanels is using an
expression-bodied arrow which triggers Biome's useIterableCallbackReturn rule;
change the callback to a block-bodied form so it does not implicitly return a
value—for example, in LinkedInController.hidePanels(), replace
LinkedInUtils.getLinkedInPanels().forEach((panel) => this.hideElement(panel))
with a block-bodied callback that calls this.hideElement(panel) inside braces
(no return), referencing LinkedInUtils.getLinkedInPanels, hidePanels, and
hideElement to locate the change.

---

Nitpick comments:
In `@src/ts/websites/linkedin/linkedin-utils.ts`:
- Around line 27-35: getLinkedInPanels currently uses document.querySelector
which returns only the first match for each selector but the function is
typed/documented to return all matching panels; change implementation of
getLinkedInPanels to use document.querySelectorAll for each selector, convert
each NodeList to an array, push all matches into a single collection and dedupe
(e.g., via a Set or filtering by identity) before returning so the result is an
array of unique HTMLElement instances; keep references to PANEL_SELECTORS and
the function name getLinkedInPanels to locate and update the code.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7eea1c4 and 97a151a.

📒 Files selected for processing (2)
  • src/ts/websites/linkedin/linkedin-controller.ts
  • src/ts/websites/linkedin/linkedin-utils.ts

… lint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ArsalaBangash ArsalaBangash merged commit a8a3aee into main Mar 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant