Build Your Own Chrome Extension: Stackify Tabs – Organize Tabs by Domain (with Dark Mode!)

Stackify Your Tabs


πŸš€Do your browser tabs feel like a chaotic jungle? Ever wish you could sort them by domain and see what’s open at a glance? In this blog, I’ll walk you through building Stackify Tab – a lightweight Chrome extension that organizes tabs by website and even includes a dark mode toggle.


🧠 Why Build a Tab Organizer?

As developers (or just power users), we open dozens of tabs – docs, tools, dashboards, and cat memes. Over time, it becomes hard to track them. This extension solves that by grouping tabs based on their domain name.

πŸ›  What We’re Building

  • A popup that shows your open tabs, grouped by domain

  • Click to activate any tab directly

  • A Dark Mode switch to soothe your eyes during late-night coding

  • Super clean UI with rounded corners and smooth styling


πŸ”§ Step 1: Set Up the Extension

Create a folder named stackify-extension, and inside it, add these files:

πŸ“ Folder Structure

stackify-extension/ │ ├── manifest.json → Extension metadata and permissions ├── popup.html → The popup UI ├── styles.css → Styling for the popup (including dark mode) ├── popup.js → JavaScript logic for tab grouping and dark mode └── icon.png → Icon used in the Chrome toolbar

πŸ“„ manifest.json


{
  "manifest_version": 3,
  "name": "Stackify Tab",
  "version": "1.1",
  "description": "Organize tabs by domain with Dark Mode support",
  "permissions": [
    "tabs"
  ],
  "action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "icon.png",
      "48": "icon.png",
      "128": "icon.png"
    }
  },
  "icons": {
    "16": "icon.png",
    "48": "icon.png",
    "128": "icon.png"
  }
}

πŸ“„ popup.html

<!DOCTYPE html>
<html>
<head>
  <title>Tab Organizer</title>
  <link rel="stylesheet" href="styles.css?v=1.1">
</head>
<body>
  <h2>Organized Tabs</h2>
  <label class="toggle">
    <input type="checkbox" id="darkModeToggle">
    <span class="slider"></span> Dark Mode
  </label>
  <div id="tabList"></div>
  <script src="popup.js"></script>
</body>
</html>

🎨 styles.css

:root {
  --bg: #f9f9f9;
  --text: #333;
  --highlight: #1a73e8;
}

body {
  font-family: 'Segoe UI', sans-serif;
  background-color: var(--bg);
  color: var(--text);
  padding: 16px;
  width: 320px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.dark {
  --bg: #121212;
  --text: #eee;
  --highlight: #90caf9;
}

h2 {
  text-align: center;
  color: var(--highlight);
}

.domain {
  margin-top: 16px;
  font-weight: bold;
  border-bottom: 1px solid #ccc;
  color: var(--text);
}

.tab {
  margin-left: 10px;
  color: var(--highlight);
  cursor: pointer;
}

.tab:hover {
  text-decoration: underline;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 14px;
}

.toggle input {
  display: none;
}

.slider {
  width: 40px;
  height: 20px;
  background-color: #ccc;
  border-radius: 20px;
  position: relative;
  cursor: pointer;
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background-color: white;
  border-radius: 50%;
  top: 1px;
  left: 1px;
  transition: 0.3s;
}

input:checked + .slider::before {
  transform: translateX(20px);
}

input:checked + .slider {
  background-color: #1a73e8;
}

πŸ’‘ popup.js


const body = document.body;
const toggle = document.getElementById("darkModeToggle");

// Load saved preference
if (localStorage.getItem("theme") === "dark") {
  toggle.checked = true;
  body.classList.add("dark");
}

toggle.addEventListener("change", () => {
  if (toggle.checked) {
    body.classList.add("dark");
    localStorage.setItem("theme", "dark");
  } else {
    body.classList.remove("dark");
    localStorage.setItem("theme", "light");
  }
});

// Tab grouping logic
chrome.tabs.query({}, function(tabs) {
  const tabList = document.getElementById("tabList");
  const grouped = {};

  tabs.forEach(tab => {
    try {
      const url = new URL(tab.url);
      const domain = url.hostname;
      if (!grouped[domain]) grouped[domain] = [];
      grouped[domain].push(tab);
    } catch (e) {
      // skip invalid URLs (e.g., chrome://)
    }
  });

  for (const domain in grouped) {
    const domainElem = document.createElement("div");
    domainElem.className = "domain";
    domainElem.textContent = domain;
    tabList.appendChild(domainElem);

    grouped[domain].forEach(tab => {
      const tabElem = document.createElement("div");
      tabElem.className = "tab";
      tabElem.textContent = tab.title;
      tabElem.onclick = () => {
        chrome.tabs.update(tab.id, { active: true });
        chrome.windows.update(tab.windowId, { focused: true });
      };
      tabList.appendChild(tabElem);
    });
  }
});

πŸ” Before Using Stackify Tab

  • [Gmail] [YouTube] [StackOverflow] [Twitter] [Medium]
  • [Docs] [GitHub] [Gmail Again] – All tabs scattered
  • Hard to find what you’re working on

✅ After Using Stackify Tab


gmail.com
  • Gmail Inbox
  • Gmail - Drafts

youtube.com
  • Video: How to build Chrome extensions

stackoverflow.com
  • Tab grouping question

github.com
  • stackify-extension repo
🧠 Understanding the Code – How Stackify Tab Works

Let’s break down what’s happening inside your Chrome extension:


πŸ“¦ manifest.json

This file tells Chrome what your extension is and what permissions it needs:

  • "tabs" permission lets the extension read information about open browser tabs.
  • "default_popup" points to the UI (popup.html) users will see when they click the extension icon.
  • It also sets up the icon for the extension toolbar.

πŸ“„ popup.html

This is the mini web page that appears when you click the extension icon. It includes:

  • A header (<h2>) with the extension name.
  • A Dark Mode toggle using a checkbox + custom slider.
  • An empty div (#tabList) that gets populated dynamically with tab info from JavaScript.

🎨 styles.css

The stylesheet defines how the popup looks:

  • Light and dark theme colors using CSS variables.
  • Rounded corners, soft shadows, clean typography.
  • The toggle switch is custom styled with animation.
  • Responsive layout for grouped domain names and tabs.

🧠 popup.js

Here’s where the magic happens:

  • First, it checks the saved dark mode preference from local storage and applies the correct theme.
  • It uses chrome.tabs.query() to get all current tabs.
  • Tabs are grouped by domain, so you can see how many tabs are open from the same site.
  • Clicking a tab title brings it into focus in your browser!

πŸŒ™ Bonus: Dark Mode Feature

Users can toggle between light and dark mode. The setting is remembered even after the popup is closed, thanks to localStorage. It's a small touch that adds polish and modern UX!

Comments