M

Develop a Chrome extension that blocks all advertisements across websites, including YouTube, while ensuring optimal performance on low-end computers with minimal resource usage. The extension should feature a customizable user interface that allows users to change the background color and image, as well as a 3D text display reading "Cosmetic Browser." Additionally, incorporate features such as a one-click browsing mode that enhances privacy and a toggle for light and dark themes to improve user experience.

Kodari AI
KodariApr 11 at 5:12 pm 269 (v2)
CosmeticAdBlocker
A lightweight Chrome extension designed to block advertisements across all websites, including YouTube, while maintaining optimal performance on low-end devices with minimal CPU and memory usage. Includes a customizable popup interface for setting background colors and images, displaying 3D-styled "Cosmetic Browser" text, toggling light and dark themes, and enabling a one-click privacy browsing mode that opens new tabs in incognito for enhanced privacy.
Kodari can make mistakes. Review important code before using.
Files
background.js
content.css
content.js
manifest.json
popup.css
popup.html
popup.js
Code
7 233
popup.js
document.addEventListener('DOMContentLoaded', () => {
  const bgColorInput = document.getElementById('bg-color');
  const bgImageInput = document.getElementById('bg-image');
  const themeToggle = document.getElementById('theme-toggle');
  const privacyModeBtn = document.getElementById('privacy-mode');
  const saveBtn = document.getElementById('save-settings');
  const body = document.body;

  chrome.storage.local.get(['bgColor', 'bgImage', 'theme'], (result) => {
    if (result.bgColor) {
      bgColorInput.value = result.bgColor;
      body.style.backgroundColor = result.bgColor;
    }
    if (result.bgImage) {
      bgImageInput.value = result.bgImage;
      body.style.backgroundImage = `url(${result.bgImage})`;
    }
    if (result.theme) {
      themeToggle.value = result.theme;
      body.className = result.theme + '-theme';
    } else {
      body.className = 'light-theme';
    }
  });

  bgColorInput.addEventListener('input', () => {
    body.style.backgroundColor = bgColorInput.value;
  });

  bgImageInput.addEventListener('input', () => {
    body.style.backgroundImage = `url(${bgImageInput.value})`;
  });

  themeToggle.addEventListener('change', () => {
    body.className = themeToggle.value + '-theme';
  });

  privacyModeBtn.addEventListener('click', () => {
    chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
      const currentTab = tabs[0];
      chrome.tabs.create({ url: currentTab.url, incognito: true });
    });
  });

  saveBtn.addEventListener('click', () => {
    const settings = {
      bgColor: bgColorInput.value,
      bgImage: bgImageInput.value,
      theme: themeToggle.value
    };
    chrome.storage.local.set(settings, () => {
      console.log('Settings saved');
    });
  });
});