From b1b3925bcbe1a9bdd4627bfae52278b455be2136 Mon Sep 17 00:00:00 2001 From: afreen shaik Date: Fri, 27 Dec 2024 01:50:17 +0530 Subject: [PATCH 1/3] create a empty file for the project --- Source-Code/AdsBlockerExtension/background.js | 0 Source-Code/AdsBlockerExtension/manifest.json | 0 Source-Code/AdsBlockerExtension/popup.html | 0 Source-Code/AdsBlockerExtension/style.css | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Source-Code/AdsBlockerExtension/background.js create mode 100644 Source-Code/AdsBlockerExtension/manifest.json create mode 100644 Source-Code/AdsBlockerExtension/popup.html create mode 100644 Source-Code/AdsBlockerExtension/style.css diff --git a/Source-Code/AdsBlockerExtension/background.js b/Source-Code/AdsBlockerExtension/background.js new file mode 100644 index 0000000..e69de29 diff --git a/Source-Code/AdsBlockerExtension/manifest.json b/Source-Code/AdsBlockerExtension/manifest.json new file mode 100644 index 0000000..e69de29 diff --git a/Source-Code/AdsBlockerExtension/popup.html b/Source-Code/AdsBlockerExtension/popup.html new file mode 100644 index 0000000..e69de29 diff --git a/Source-Code/AdsBlockerExtension/style.css b/Source-Code/AdsBlockerExtension/style.css new file mode 100644 index 0000000..e69de29 From 8bf1afcade09ec382e68631d824fa4c10b557f18 Mon Sep 17 00:00:00 2001 From: afreen shaik Date: Sat, 28 Dec 2024 02:17:55 +0530 Subject: [PATCH 2/3] add the feature block the ads --- Source-Code/AdsBlockerExtension/background.js | 0 Source-Code/AdsBlockerExtension/content.js | 41 ++++++++++++++++++ .../AdsBlockerExtension/icons/icon128.png | Bin 0 -> 2101 bytes .../AdsBlockerExtension/icons/icon16.png | Bin 0 -> 1066 bytes .../AdsBlockerExtension/icons/icon48.png | Bin 0 -> 1560 bytes Source-Code/AdsBlockerExtension/manifest.json | 27 ++++++++++++ Source-Code/AdsBlockerExtension/popup.css | 35 +++++++++++++++ Source-Code/AdsBlockerExtension/popup.html | 24 ++++++++++ Source-Code/AdsBlockerExtension/popup.js | 34 +++++++++++++++ Source-Code/AdsBlockerExtension/style.css | 0 10 files changed, 161 insertions(+) delete mode 100644 Source-Code/AdsBlockerExtension/background.js create mode 100644 Source-Code/AdsBlockerExtension/content.js create mode 100644 Source-Code/AdsBlockerExtension/icons/icon128.png create mode 100644 Source-Code/AdsBlockerExtension/icons/icon16.png create mode 100644 Source-Code/AdsBlockerExtension/icons/icon48.png create mode 100644 Source-Code/AdsBlockerExtension/popup.css create mode 100644 Source-Code/AdsBlockerExtension/popup.js delete mode 100644 Source-Code/AdsBlockerExtension/style.css diff --git a/Source-Code/AdsBlockerExtension/background.js b/Source-Code/AdsBlockerExtension/background.js deleted file mode 100644 index e69de29..0000000 diff --git a/Source-Code/AdsBlockerExtension/content.js b/Source-Code/AdsBlockerExtension/content.js new file mode 100644 index 0000000..a40a9fd --- /dev/null +++ b/Source-Code/AdsBlockerExtension/content.js @@ -0,0 +1,41 @@ +const adSelectors = [ + 'iframe[src*="ads"]', + 'div[class*="ad"]', + 'div[id*="ad"]', + "ins.adsbygoogle", + "[data-ad]", + ".ad-banner", +]; + +// Normalize domain +const normalizeDomain = (domain) => domain.replace(/^www\./, ""); + +chrome.storage.local.get( + { adBlockerEnabled: true, whitelist: [] }, + ({ adBlockerEnabled, whitelist }) => { + if (!adBlockerEnabled) return; + + const currentSite = normalizeDomain(window.location.hostname); + const normalizedWhitelist = whitelist.map(normalizeDomain); + + if (normalizedWhitelist.includes(currentSite)) { + console.log(`Whitelist active: Ads are allowed on ${currentSite}`); + return; // Skip ad blocking + } + + // Ad blocking logic + const blockAds = () => { + adSelectors.forEach((selector) => { + const ads = document.querySelectorAll(selector); + console.log(`Found ${ads.length} ads for selector: ${selector}`); + ads.forEach((ad) => ad.remove()); + }); + }; + + blockAds(); // Initial blocking + + // Observe dynamically loaded ads + const observer = new MutationObserver(blockAds); + observer.observe(document.body, { childList: true, subtree: true }); + } +); diff --git a/Source-Code/AdsBlockerExtension/icons/icon128.png b/Source-Code/AdsBlockerExtension/icons/icon128.png new file mode 100644 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`1kd zZ17ntlrU3;E$eJ-h_bSq6U#}lg-TYc7Uh(cfh)@L?@J}{)iNoDnzLI#;3=4cc_`^t zk?2a11fJDJJqMRd6v^qUON4rl%>ikcBTQ0&8DQjeBD_no%>-P4nm8=sBu?KWunJd* zTH)q@gr%%#Zma$5H)b^+IzTbCS7JgE8!_~(tcF1*W8hjAh$A5j^p6^~yq);}lw9;C ztJz(33lk_S+8@DKyKQAPCCj;R6iCklye$bO0jf~lf(tUw#UkAx8+mS^M@ry^232lX zq${nZ43XYB7^3c`xaYOYk)R2HW&u^57)Yqj9ORKBR5VfI^Bcdzu$qSxu}I21dUI;4 z^St~1@%jBlpL6n5tn=p1J(=}6qx??{ln^p@rL7cjpxx9FVxLVVa@A0_}Xj_cCey+=i?9Z9~CyT-A$LrSniL% zcEoNq*DD(~T^>`fys)ox;lZWz@|EKCFAlwN?evGP*DfSK`R1|I$=RVZpTQZ=L@9J? zv13cqSkUKZW@0@{^T*b=KJcyoM%&(*x_6(wHTZK|gS7c;(D&3MZ-*B>CtD|n{MQ2{ zIoVH*ZhHC9#nLO@xvRd{e_uOIOnPnv vvqSOHo#>BeKlhxz=G^z>i5;GGbKf^k)gE|t=_+&1n%#-6zSx=0J^TL#U8fT1 literal 0 HcmV?d00001 diff --git a/Source-Code/AdsBlockerExtension/manifest.json b/Source-Code/AdsBlockerExtension/manifest.json index e69de29..3982ced 100644 --- a/Source-Code/AdsBlockerExtension/manifest.json +++ b/Source-Code/AdsBlockerExtension/manifest.json @@ -0,0 +1,27 @@ +{ + "manifest_version": 2, + "name": "Ad Blocker", + "version": "1.0", + "description": "A simple ad blocker to remove advertisements from websites.", + "permissions": ["activeTab", "storage"], + "content_scripts": [ + { + "matches": [""], + "js": ["content.js"] + } + ], + "browser_action": { + "default_popup": "popup.html", + "default_icon": { + "16": "./icons/icon16.png", + "48": "./icons/icon48.png", + "128": "./icons/icon128.png" + } + }, + "icons": { + "16": "./icons/icon16.png", + "48": "./icons/icon48.png", + "128": "./icons/icon128.png" + } + } + \ No newline at end of file diff --git a/Source-Code/AdsBlockerExtension/popup.css b/Source-Code/AdsBlockerExtension/popup.css new file mode 100644 index 0000000..fb2d8d6 --- /dev/null +++ b/Source-Code/AdsBlockerExtension/popup.css @@ -0,0 +1,35 @@ +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 diff --git a/Source-Code/AdsBlockerExtension/popup.html b/Source-Code/AdsBlockerExtension/popup.html index e69de29..de88f92 100644 --- a/Source-Code/AdsBlockerExtension/popup.html +++ b/Source-Code/AdsBlockerExtension/popup.html @@ -0,0 +1,24 @@ + + + + + + Ad Blocker + + + +

Ad Blocker

+ +
+

Whitelist

+ + +
    +
    +

    + + + diff --git a/Source-Code/AdsBlockerExtension/popup.js b/Source-Code/AdsBlockerExtension/popup.js new file mode 100644 index 0000000..ce29ed3 --- /dev/null +++ b/Source-Code/AdsBlockerExtension/popup.js @@ -0,0 +1,34 @@ +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 = ""; + whitelistData.forEach((site) => { + const li = document.createElement("li"); + li.textContent = site; + const removeBtn = document.createElement("button"); + removeBtn.textContent = "Remove"; + removeBtn.addEventListener("click", () => { + whitelistData = whitelistData.filter((item) => item !== site); + localStorage.setItem("whitelist", JSON.stringify(whitelistData)); + loadWhitelist(); + }); + li.appendChild(removeBtn); + whitelist.appendChild(li); + }); +} + +addToWhitelist.addEventListener("click", () => { + const site = whitelistInput.value.trim(); + if (site && !whitelistData.includes(site)) { + whitelistData.push(site); + localStorage.setItem("whitelist", JSON.stringify(whitelistData)); + whitelistInput.value = ""; + loadWhitelist(); + } +}); + +loadWhitelist(); diff --git a/Source-Code/AdsBlockerExtension/style.css b/Source-Code/AdsBlockerExtension/style.css deleted file mode 100644 index e69de29..0000000 From 351e3a2289eef7f5287977e12750488dac1bca85 Mon Sep 17 00:00:00 2001 From: afreen shaik Date: Sat, 28 Dec 2024 15:36:13 +0530 Subject: [PATCH 3/3] 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(); } });