uptown034

Make an extension that blocks websites and blacklist words and you can blacklist websites and words into use it you can assign the icon to show and what they should say like you upload your company logo. It says this website is banned more like something and you need a password to unbanned and ban websites.

Kodari AI
KodariMar 26 at 10:06 am 11,307 (v2)

I’ll create a website and word blocking extension with password protection and customizable block page.

ContentGuardian
A comprehensive content filtering extension that blocks websites and blacklisted words with password protection. Features include customizable block pages with logo upload, custom messages, website and word blacklists, and password-protected access controls. Perfect for workplace productivity, parental controls, or personal focus management. Includes temporary unblock capabilities and real-time content scanning.

ContentGuardian extension created! This powerful blocking extension includes:

✅ Website Blacklist - Block entire domains
✅ Word Blacklist - Block pages containing specific words/phrases
✅ Password Protection - Secure access to settings and unblocking
✅ Custom Logo Upload - Add your company/organization logo
✅ Custom Block Message - Personalize the blocked page text
✅ Temporary Unblock - 5-minute password-authenticated access
✅ Real-time Scanning - Detects blocked content as pages load
✅ Session Management - Stay logged in until manual logout

The extension shows a professional block page with your custom branding when blocked content is detected. Perfect for productivity, parental controls, or workplace content filtering!

Kodari can make mistakes. Review important code before using.
Files
background.js
blocked.css
blocked.html
blocked.js
content.css
content.js
manifest.json
popup.css
popup.html
popup.js
Code
10 1,101
popup.js
let isLoggedIn = false;

document.addEventListener('DOMContentLoaded', async () => {
  await checkAuthStatus();
  setupEventListeners();
});

async function checkAuthStatus() {
  const data = await chrome.storage.local.get(['password', 'sessionActive']);
  
  if (!data.password) {
    showSection('setup');
  } else if (data.sessionActive) {
    isLoggedIn = true;
    await loadData();
    showSection('main');
  } else {
    showSection('login');
  }
}

function showSection(section) {
  document.getElementById('loginSection').classList.add('hidden');
  document.getElementById('setupSection').classList.add('hidden');
  document.getElementById('mainSection').classList.add('hidden');
  
  if (section === 'login') {
    document.getElementById('loginSection').classList.remove('hidden');
  } else if (section === 'setup') {
    document.getElementById('setupSection').classList.remove('hidden');
  } else if (section === 'main') {
    document.getElementById('mainSection').classList.remove('hidden');
  }
}

function setupEventListeners() {
  document.getElementById('setupBtn').addEventListener('click', handleSetup);
  document.getElementById('loginBtn').addEventListener('click', handleLogin);
  document.getElementById('addWebsiteBtn').addEventListener('click', addWebsite);
  document.getElementById('addWordBtn').addEventListener('click', addWord);
  document.getElementById('logoInput').addEventListener('change', handleLogoUpload);
  document.getElementById('blockMessage').addEventListener('input', saveBlockMessage);
  document.getElementById('changePasswordBtn').addEventListener('click', changePassword);
  document.getElementById('logoutBtn').addEventListener('click', logout);

  document.querySelectorAll('.tab').forEach(tab => {
    tab.addEventListener('click', () => switchTab(tab.dataset.tab));
  });

  document.getElementById('passwordInput').addEventListener('keypress', (e) => {
    if (e.key === 'Enter') handleLogin();
  });

  document.getElementById('websiteInput').addEventListener('keypress', (e) => {
    if (e.key === 'Enter') addWebsite();
  });

  document.getElementById('wordInput').addEventListener('keypress', (e) => {
    if (e.key === 'Enter') addWord();
  });
}

async function handleSetup() {
  const newPassword = document.getElementById('newPassword').value;
  const confirmPassword = document.getElementById('confirmPassword').value;
  const errorEl = document.getElementById('setupError');

  if (!newPassword || newPassword.length < 4) {
    errorEl.textContent = 'Password must be at least 4 characters';
    return;
  }

  if (newPassword !== confirmPassword) {
    errorEl.textContent = 'Passwords do not match';
    return;
  }

  const hashedPassword = await hashPassword(newPassword);
  await chrome.storage.local.set({
    password: hashedPassword,
    sessionActive: true,
    blockedWebsites: [],
    blockedWords: [],
    blockMessage: 'This website has been blocked by your administrator',
    customLogo: null
  });

  isLoggedIn = true;
  await loadData();
  showSection('main');
}

async function handleLogin() {
  const password = document.getElementById('passwordInput').value;
  const errorEl = document.getElementById('loginError');

  const data = await chrome.storage.local.get(['password']);
  const hashedPassword = await hashPassword(password);

  if (hashedPassword === data.password) {
    await chrome.storage.local.set({ sessionActive: true });
    isLoggedIn = true;
    await loadData();
    showSection('main');
  } else {
    errorEl.textContent = 'Incorrect password';
    document.getElementById('passwordInput').value = '';
  }
}

async function loadData() {
  const data = await chrome.storage.local.get([
    'blockedWebsites',
    'blockedWords',
    'blockMessage',
    'customLogo'
  ]);

  renderWebsites(data.blockedWebsites || []);
  renderWords(data.blockedWords || []);
  
  document.getElementById('blockMessage').value = data.blockMessage || 'This website has been blocked by your administrator';
  
  if (data.customLogo) {
    const preview = document.getElementById('logoPreview');
    preview.innerHTML = `<img src="${data.customLogo}" alt="Logo">`;
  }
}

function switchTab(tabName) {
  document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
  
  document.querySelector(`[data-tab="${tabName}"]`).classList.add('active');
  document.getElementById(`${tabName}Tab`).classList.add('active');
}

async function addWebsite() {
  const input = document.getElementById('websiteInput');
  let website = input.value.trim().toLowerCase();

  if (!website) return;

  website = website.replace(/^https?:\/\//, '').replace(/^www\./, '').split('/')[0];

  const data = await chrome.storage.local.get(['blockedWebsites']);
  const websites = data.blockedWebsites || [];

  if (websites.includes(website)) {
    alert('Website already in blacklist');
    return;
  }

  websites.push(website);
  await chrome.storage.local.set({ blockedWebsites: websites });

  renderWebsites(websites);
  input.value = '';

  chrome.runtime.sendMessage({ action: 'reloadBlacklist' });
}

async function removeWebsite(website) {
  const data = await chrome.storage.local.get(['blockedWebsites']);
  const websites = data.blockedWebsites || [];
  const filtered = websites.filter(w => w !== website);

  await chrome.storage.local.set({ blockedWebsites: filtered });
  renderWebsites(filtered);

  chrome.runtime.sendMessage({ action: 'reloadBlacklist' });
}

function renderWebsites(websites) {
  const list = document.getElementById('websiteList');
  
  if (websites.length === 0) {
    list.innerHTML = '<li style="border-left: none; background: #fff; color: #999;">No blocked websites yet</li>';
    return;
  }

  list.innerHTML = websites.map(website => `
    <li>
      <span>${website}</span>
      <button onclick="removeWebsite('${website}')">Remove</button>
    </li>
  `).join('');
}

async function addWord() {
  const input = document.getElementById('wordInput');
  const word = input.value.trim().toLowerCase();

  if (!word) return;

  const data = await chrome.storage.local.get(['blockedWords']);
  const words = data.blockedWords || [];

  if (words.includes(word)) {
    alert('Word already in blacklist');