Claude Skills Guide

AI distraction blocker Chrome extensions represent a powerful solution for developers and power users seeking to reclaim their attention in an increasingly noisy digital environment. Unlike traditional blockers that use static blocklists, AI-powered versions analyze page content in real-time, identifying contextually distracting elements and dynamically filtering them based on your work context.

Understanding the Core Architecture

The foundation of an effective AI distraction blocker lies in its ability to understand page content and user intent. These extensions typically operate through three interconnected layers: a content analysis engine, a rules engine, and a user interface for configuration.

The content analysis layer uses JavaScript to scan DOM elements, extract text content, and apply machine learning models or heuristic algorithms to determine distraction probability. The rules engine then applies user-defined policies, deciding what to block, hide, or modify. Finally, the configuration UI allows you to customize behavior without touching code.

Building a Basic Implementation

Here’s a minimal Manifest V3 structure for a distraction blocker:

// manifest.json
{
  "manifest_version": 3,
  "name": "AI Distraction Blocker",
  "version": "1.0",
  "permissions": ["activeTab", "storage", "scripting"],
  "host_permissions": ["<all_urls>"],
  "background": {
    "service_worker": "background.js"
  },
  "content_scripts": [{
    "matches": ["<all_urls>"],
    "js": ["content.js"],
    "run_at": "document_end"
  }]
}

The content script is where the actual blocking happens. A basic implementation scans for common distraction patterns:

// content.js
const distractionSelectors = [
  '[class*="social"]', '[class*="feed"]', '[class*="notification"]',
  '[id*="sidebar-promotion"]', '.recommendations', '[data-ad]'
];

function blockDistractions() {
  distractionSelectors.forEach(selector => {
    document.querySelectorAll(selector).forEach(el => {
      el.style.display = 'none';
    });
  });
}

// Run after page loads
document.addEventListener('DOMContentLoaded', blockDistractions);

Adding AI-Powered Analysis

Static selectors work for known platforms, but true AI-powered blocking requires content understanding. You can integrate with APIs or run lightweight models in the extension context:

// Analyze page content for distraction patterns
async function analyzePageContent() {
  const pageText = document.body.innerText.substring(0, 5000);
  
  // Simple heuristic scoring (replace with API call for production)
  const distractionKeywords = [
    'buy now', 'limited time', 'trending', 'viral',
    'breaking news', 'you won\'t believe'
  ];
  
  let score = 0;
  distractionKeywords.forEach(keyword => {
    if (pageText.toLowerCase().includes(keyword)) {
      score += 10;
    }
  });
  
  return score > 30; // Threshold for blocking
}

Context-Aware Blocking Strategies

Effective distraction blocking adapts to your current context. A developer working on code needs different protection than someone reading news. Implement context awareness through:

  1. Time-based rules: Stricter blocking during work hours
  2. Tab detection: Identify coding environments, documentation, or IDE-like pages
  3. Focus mode: Manual override for deep work sessions
  4. Domain whitelisting: Always allow essential tools
// context-aware-blocking.js
const focusDomains = ['github.com', 'stackoverflow.com', 'docs.rs'];

function shouldApplyStrictBlocking() {
  const hour = new Date().getHours();
  const isWorkHours = hour >= 9 && hour <= 17;
  const currentDomain = window.location.hostname;
  const isProductivitySite = focusDomains.some(d => currentDomain.includes(d));
  
  return isWorkHours || isProductivitySite;
}

Chrome Extension API Integration

For deeper integration, leverage Chrome’s Extension APIs to create sophisticated blocking rules:

// background.js - Using declarativeNetRequest for efficient blocking
chrome.runtime.onInstalled.addListener(() => {
  chrome.declarativeNetRequest.updateDynamicRules({
    addRules: [
      {
        id: 1,
        priority: 1,
        action: {
          type: 'block'
        },
        condition: {
          urlFilter: '.*tracking.*',
          resourceTypes: ['script', 'image']
        }
      }
    ],
    removeRuleIds: [1]
  });
});

Performance Considerations

Running AI analysis on every page requires careful performance management. Key optimizations include:

// Performance-optimized scanning
function debounce(func, wait) {
  let timeout;
  return function executedFunction(...args) {
    clearTimeout(timeout);
    timeout = setTimeout(() => func.apply(this, args), wait);
  };
}

const safeScan = debounce(() => {
  // Your analysis logic here
}, 1000);

Customization for Power Users

Beyond basic blocking, power users benefit from granular controls. Consider adding:

Advanced Features for Developer Workflows

Developers have unique needs when it comes to distraction blocking. IDE integrations, documentation browsing, and code research require careful handling to avoid accidentally blocking essential resources. Consider implementing developer-specific features:

// Developer-focused blocking rules
const developerExceptions = {
  allow: [
    '*.stackoverflow.com',
    '*.github.com',
    '*.readthedocs.io',
    '*.mozilla.org',
    'developer.mozilla.org',
    '*.npmjs.com'
  ],
  block: [
    '*://*.youtube.com/feed',
    '*://twitter.com/home',
    '*://www.reddit.com/'
  ]
};

function checkDeveloperExceptions(url) {
  return developerExceptions.allow.some(pattern => 
    new RegExp(pattern.replace('*', '.*')).test(url)
  );
}

Privacy and Data Handling

When building AI-powered blocking features, consider privacy implications. Local processing keeps all data on the user’s machine, while API-based analysis sends content externally. For maximum privacy, run lightweight models client-side using WebAssembly or TensorFlow.js:

// Local privacy-focused analysis example
class PrivacyAwareAnalyzer {
  constructor() {
    this.localPatterns = this.loadLocalPatterns();
  }

  loadLocalPatterns() {
    // Patterns defined locally - no external calls
    return [
      { pattern: /clickbait|you won't believe/i, weight: 5 },
      { pattern: /buy now|limited offer/i, weight: 3 },
      { pattern: /subscribe|newsletter/i, weight: 2 }
    ];
  }

  analyze(text) {
    let totalScore = 0;
    this.localPatterns.forEach(({ pattern, weight }) => {
      if (pattern.test(text)) totalScore += weight;
    });
    return totalScore;
  }
}

Testing Your Extension

Comprehensive testing ensures your blocker works across different scenarios. Use Chrome’s built-in testing capabilities:

// Example test case structure
const testCases = [
  {
    url: 'https://twitter.com/home',
    expected: 'blocked',
    description: 'Social media feed should be blocked'
  },
  {
    url: 'https://github.com/features',
    expected: 'allowed',
    description: 'Developer resources should be accessible'
  }
];

function runTests() {
  testCases.forEach(({ url, expected, description }) => {
    const result = shouldBlock(url);
    console.log(`${description}: ${result === expected ? 'PASS' : 'FAIL'}`);
  });
}

Conclusion

Building an AI distraction blocker Chrome extension combines web development skills with behavioral understanding. Start with simple selector-based blocking, then layer in AI analysis as you refine your understanding of what constitutes distraction in your workflow. The key is creating a system that disappears into the background while protecting your attention when you need it most.

Built by theluckystrike — More at zovo.one