Skip to content

Commit

Permalink
Add and updat ethe projec with description
Browse files Browse the repository at this point in the history
  • Loading branch information
tajulafreen committed Dec 28, 2024
1 parent 8bf1afc commit 351e3a2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 52 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,17 @@ In order to run this project you need:
</details>
</li>

<li>
<details>
<summary>Ads Blocker Extension</summary>
<p>This is a simple Ad Blocker Extension. AdBlocker is a lightweight browser extension designed to block intrusive advertisements and enhance your browsing experience.</p>
<ul>
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/AdsBlockerExtension/">Live Demo</a></li>
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/AdsBlockerExtension">Source</a></li>
</ul>
</details>
</li>

</ol>

<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand Down
11 changes: 6 additions & 5 deletions Source-Code/AdsBlockerExtension/content.js
Original file line number Diff line number Diff line change
@@ -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: [] },
Expand Down Expand Up @@ -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 });
}
},
);
67 changes: 33 additions & 34 deletions Source-Code/AdsBlockerExtension/popup.css
Original file line number Diff line number Diff line change
@@ -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;
}

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;
}
26 changes: 13 additions & 13 deletions Source-Code/AdsBlockerExtension/popup.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
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);
whitelist.appendChild(li);
});
}

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();
}
});
Expand Down

0 comments on commit 351e3a2

Please sign in to comment.