Skip to content

Commit

Permalink
Merge pull request #2613 from Meetjain1/mj
Browse files Browse the repository at this point in the history
Feat : Added popup blocker extension
  • Loading branch information
Sulagna-Dutta-Roy authored Aug 8, 2024
2 parents 406b507 + 70c72e3 commit fdbe001
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Popup Blocker/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
let blocking = true;

chrome.storage.local.get(['blocking'], function(result) {
blocking = result.blocking !== undefined ? result.blocking : true;
});

chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (blocking) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icons/icon48.png',
title: 'Popup Blocker',
message: 'Popup blocked!'
});
}
return { cancel: blocking };
},
{ urls: ["*://*/*"], types: ["popup"] },
["blocking"]
);

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === "toggleBlocking") {
blocking = request.blocking;
chrome.storage.local.set({ blocking: blocking });
sendResponse({ blocking: blocking });
} else if (request.action === "getBlockingStatus") {
sendResponse({ blocking: blocking });
}
});
Binary file added Popup Blocker/icons/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Popup Blocker/icons/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Popup Blocker/icons/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions Popup Blocker/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"manifest_version": 3,
"name": "Best Popup Blocker",
"version": "1.0",
"description": "A popup blocker extension with modern UI and animations",
"permissions": [
"webRequest",
"webRequestBlocking",
"notifications",
"storage",
"https://*/*",
"http://*/*"
],
"background": {
"service_worker": "background.js"
},
"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"
}
}

44 changes: 44 additions & 0 deletions Popup Blocker/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 200px;
margin: 0;
background: #f0f0f0;
}

#container {
text-align: center;
}

h1 {
font-size: 1.5em;
margin-bottom: 10px;
}

p {
margin: 0;
font-size: 1em;
color: #333;
}

button {
padding: 10px 20px;
font-size: 1em;
cursor: pointer;
border: none;
background: #007bff;
color: white;
transition: background 0.3s ease;
}

button:hover {
background: #0056b3;
}

#status {
font-weight: bold;
color: green;
}

17 changes: 17 additions & 0 deletions Popup Blocker/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Popup Blocker</title>
<link rel="stylesheet" href="popup.css">
</head>
<body>
<div id="container">
<h1>Popup Blocker</h1>
<p>Status: <span id="status">Active</span></p>
<button id="toggle">Toggle Blocking</button>
</div>
<script src="popup.js"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions Popup Blocker/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
document.getElementById('toggle').addEventListener('click', function() {
chrome.runtime.sendMessage({ action: "toggleBlocking", blocking: !blocking }, function(response) {
updateStatus(response.blocking);
});
});

document.addEventListener('DOMContentLoaded', function() {
chrome.runtime.sendMessage({ action: "getBlockingStatus" }, function(response) {
updateStatus(response.blocking);
});
});

function updateStatus(blocking) {
document.getElementById('status').textContent = blocking ? 'Active' : 'Inactive';
document.getElementById('status').style.color = blocking ? 'green' : 'red';
}

0 comments on commit fdbe001

Please sign in to comment.