From 351e3a2289eef7f5287977e12750488dac1bca85 Mon Sep 17 00:00:00 2001 From: afreen shaik Date: Sat, 28 Dec 2024 15:36:13 +0530 Subject: [PATCH] Add and updat ethe projec with description --- README.md | 11 ++++ Source-Code/AdsBlockerExtension/content.js | 11 ++-- Source-Code/AdsBlockerExtension/popup.css | 67 +++++++++++----------- Source-Code/AdsBlockerExtension/popup.js | 26 ++++----- 4 files changed, 63 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index b0eaa79..8927f99 100644 --- a/README.md +++ b/README.md @@ -584,6 +584,17 @@ In order to run this project you need: +
  • +
    +Ads Blocker Extension +

    This is a simple Ad Blocker Extension. AdBlocker is a lightweight browser extension designed to block intrusive advertisements and enhance your browsing experience.

    + +
    +
  • +

    (back to top)

    diff --git a/Source-Code/AdsBlockerExtension/content.js b/Source-Code/AdsBlockerExtension/content.js index a40a9fd..7e719d8 100644 --- a/Source-Code/AdsBlockerExtension/content.js +++ b/Source-Code/AdsBlockerExtension/content.js @@ -1,14 +1,15 @@ +/* eslint-disable no-undef */ const adSelectors = [ 'iframe[src*="ads"]', 'div[class*="ad"]', 'div[id*="ad"]', - "ins.adsbygoogle", - "[data-ad]", - ".ad-banner", + 'ins.adsbygoogle', + '[data-ad]', + '.ad-banner', ]; // Normalize domain -const normalizeDomain = (domain) => domain.replace(/^www\./, ""); +const normalizeDomain = (domain) => domain.replace(/^www\./, ''); chrome.storage.local.get( { adBlockerEnabled: true, whitelist: [] }, @@ -37,5 +38,5 @@ chrome.storage.local.get( // Observe dynamically loaded ads const observer = new MutationObserver(blockAds); observer.observe(document.body, { childList: true, subtree: true }); - } + }, ); diff --git a/Source-Code/AdsBlockerExtension/popup.css b/Source-Code/AdsBlockerExtension/popup.css index fb2d8d6..5ba01a8 100644 --- a/Source-Code/AdsBlockerExtension/popup.css +++ b/Source-Code/AdsBlockerExtension/popup.css @@ -1,35 +1,34 @@ body { - font-family: Arial, sans-serif; - margin: 10px; - width: 250px; - } - - h1 { - font-size: 1.5em; - margin-bottom: 10px; - } - - label { - display: block; - margin-bottom: 20px; - } - - input { - margin-right: 10px; - } - - ul { - list-style-type: none; - padding: 0; - } - - li { - margin: 5px 0; - display: flex; - justify-content: space-between; - } - - button { - cursor: pointer; - } - \ No newline at end of file + font-family: Arial, sans-serif; + margin: 10px; + width: 250px; +} + +h1 { + font-size: 1.5em; + margin-bottom: 10px; +} + +label { + display: block; + margin-bottom: 20px; +} + +input { + margin-right: 10px; +} + +ul { + list-style-type: none; + padding: 0; +} + +li { + margin: 5px 0; + display: flex; + justify-content: space-between; +} + +button { + cursor: pointer; +} diff --git a/Source-Code/AdsBlockerExtension/popup.js b/Source-Code/AdsBlockerExtension/popup.js index ce29ed3..2a544a6 100644 --- a/Source-Code/AdsBlockerExtension/popup.js +++ b/Source-Code/AdsBlockerExtension/popup.js @@ -1,19 +1,19 @@ -const whitelistInput = document.getElementById("whitelist-input"); -const addToWhitelist = document.getElementById("add-to-whitelist"); -const whitelist = document.getElementById("whitelist"); -let whitelistData = JSON.parse(localStorage.getItem("whitelist")) || []; +const whitelistInput = document.getElementById('whitelist-input'); +const addToWhitelist = document.getElementById('add-to-whitelist'); +const whitelist = document.getElementById('whitelist'); +let whitelistData = JSON.parse(localStorage.getItem('whitelist')) || []; // Load whitelist function loadWhitelist() { - whitelist.innerHTML = ""; + whitelist.innerHTML = ''; whitelistData.forEach((site) => { - const li = document.createElement("li"); + const li = document.createElement('li'); li.textContent = site; - const removeBtn = document.createElement("button"); - removeBtn.textContent = "Remove"; - removeBtn.addEventListener("click", () => { + const removeBtn = document.createElement('button'); + removeBtn.textContent = 'Remove'; + removeBtn.addEventListener('click', () => { whitelistData = whitelistData.filter((item) => item !== site); - localStorage.setItem("whitelist", JSON.stringify(whitelistData)); + localStorage.setItem('whitelist', JSON.stringify(whitelistData)); loadWhitelist(); }); li.appendChild(removeBtn); @@ -21,12 +21,12 @@ function loadWhitelist() { }); } -addToWhitelist.addEventListener("click", () => { +addToWhitelist.addEventListener('click', () => { const site = whitelistInput.value.trim(); if (site && !whitelistData.includes(site)) { whitelistData.push(site); - localStorage.setItem("whitelist", JSON.stringify(whitelistData)); - whitelistInput.value = ""; + localStorage.setItem('whitelist', JSON.stringify(whitelistData)); + whitelistInput.value = ''; loadWhitelist(); } });