فهرست منبع

Initial commit: Clear My Cookies Chrome Extension

Johnathon Frederick 8 ماه پیش
کامیت
599e4643c3
10فایلهای تغییر یافته به همراه171 افزوده شده و 0 حذف شده
  1. 1 0
      .gitignore
  2. 34 0
      background.js
  3. BIN
      icons/cookie.png
  4. BIN
      icons/icon128.png
  5. BIN
      icons/icon16.png
  6. BIN
      icons/icon48.png
  7. 25 0
      manifest.json
  8. 46 0
      popup/popup.css
  9. 17 0
      popup/popup.html
  10. 48 0
      popup/popup.js

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pem

+ 34 - 0
background.js

@@ -0,0 +1,34 @@
+chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
+  if (request.action === "clearCookies") {
+    const url = request.url;
+    
+    chrome.cookies.getAll({ url }, (cookies) => {
+      if (cookies.length === 0) {
+        sendResponse({ success: true, message: "No cookies found for this site" });
+        return;
+      }
+
+      let clearedCount = 0;
+      cookies.forEach((cookie) => {
+        chrome.cookies.remove({
+          url,
+          name: cookie.name
+        }, () => {
+          clearedCount++;
+          if (clearedCount === cookies.length) {
+            sendResponse({ 
+              success: true, 
+              message: `Cleared ${cookies.length} cookies`
+            });
+          }
+        });
+      });
+      
+      // Handle case where we need to wait for async operations
+      return true;
+    });
+    
+    // Indicate we want to send response asynchronously
+    return true;
+  }
+});

BIN
icons/cookie.png


BIN
icons/icon128.png


BIN
icons/icon16.png


BIN
icons/icon48.png


+ 25 - 0
manifest.json

@@ -0,0 +1,25 @@
+{
+  "manifest_version": 3,
+  "name": "Website Cookie Clearer",
+  "version": "1.0",
+  "description": "Clear cookies for the current website with one click",
+  "permissions": ["cookies", "activeTab"],
+  "host_permissions": ["<all_urls>"],
+  "background": {
+    "service_worker": "background.js",
+    "type": "module"
+  },
+  "action": {
+    "default_popup": "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"
+  }
+}

+ 46 - 0
popup/popup.css

@@ -0,0 +1,46 @@
+body {
+  width: 300px;
+  padding: 15px;
+  font-family: Arial, sans-serif;
+  background-color: #f5f5f5;
+}
+
+.container {
+  text-align: center;
+}
+
+h1 {
+  font-size: 16px;
+  color: #333;
+  margin-bottom: 15px;
+}
+
+p {
+  font-size: 13px;
+  color: #666;
+  margin: 10px 0;
+}
+
+button {
+  background-color: #4285f4;
+  color: white;
+  border: none;
+  padding: 10px 15px;
+  text-align: center;
+  text-decoration: none;
+  display: inline-block;
+  font-size: 14px;
+  margin: 10px 0;
+  cursor: pointer;
+  border-radius: 4px;
+  transition: background-color 0.3s;
+}
+
+button:hover {
+  background-color: #3367d6;
+}
+
+#status {
+  font-style: italic;
+  min-height: 20px;
+}

+ 17 - 0
popup/popup.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>Cookie Clearer</title>
+  <link rel="stylesheet" href="popup.css">
+</head>
+<body>
+  <div class="container">
+    <h1>Cookie Clearer</h1>
+    <p id="site-info">Loading current site...</p>
+    <button id="clear-cookies">Clear Cookies for This Site</button>
+    <p id="status"></p>
+  </div>
+  <script src="popup.js"></script>
+</body>
+</html>

+ 48 - 0
popup/popup.js

@@ -0,0 +1,48 @@
+document.addEventListener('DOMContentLoaded', () => {
+  const clearButton = document.getElementById('clear-cookies');
+  const siteInfo = document.getElementById('site-info');
+  const status = document.getElementById('status');
+  
+  // Get current active tab
+  chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
+    if (tabs[0]) {
+      const url = new URL(tabs[0].url);
+      const hostname = url.hostname;
+      siteInfo.textContent = `Current site: ${hostname}`;
+      
+      // Store the URL for cookie clearing
+      clearButton.dataset.url = tabs[0].url;
+    } else {
+      siteInfo.textContent = "No active tab found";
+      clearButton.disabled = true;
+    }
+  });
+  
+  // Handle clear cookies button
+  clearButton.addEventListener('click', () => {
+    const url = clearButton.dataset.url;
+    
+    if (!url) {
+      status.textContent = "Error: No URL found";
+      status.style.color = "red";
+      return;
+    }
+    
+    status.textContent = "Clearing cookies...";
+    status.style.color = "black";
+    
+    // Send message to background to clear cookies
+    chrome.runtime.sendMessage({
+      action: "clearCookies",
+      url: url
+    }, (response) => {
+      if (response && response.success) {
+        status.textContent = response.message;
+        status.style.color = "green";
+      } else {
+        status.textContent = "Error clearing cookies";
+        status.style.color = "red";
+      }
+    });
+  });
+});