Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Chrome extension (and others, Safari, Firefox). #159

Open
ns-mglaske opened this issue Nov 30, 2024 · 0 comments
Open

FEATURE: Chrome extension (and others, Safari, Firefox). #159

ns-mglaske opened this issue Nov 30, 2024 · 0 comments

Comments

@ns-mglaske
Copy link

ns-mglaske commented Nov 30, 2024

It would make the add to list option much easier, by just clicking an extension button on your browser :). Should be pretty simple to just take the current URL of the page and send it to Christmas-Community. eg:

background.js

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.action === "sendUrl") {
    fetch("https://your-api-endpoint.com/submit-url", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({ url: request.url })
    })
    .then(response => response.json())
    .then(data => {
      console.log("URL sent successfully:", data);
      sendResponse({ success: true });
    })
    .catch(error => {
      console.error("Error sending URL:", error);
      sendResponse({ success: false, error: error.message });
    });
    return true; // Keep the message channel open for async response
  }
});

popup.html

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Send URL</title>
  <style>
    body { width: 150px; text-align: center; font-family: Arial, sans-serif; }
    button { padding: 10px; margin-top: 10px; }
  </style>
</head>
<body>
  <h3>Send URL</h3>
  <button id="sendButton">Send Current URL</button>
  <script src="popup.js"></script>
</body>
</html>

popup.js

document.getElementById("sendButton").addEventListener("click", () => {
  chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
    const currentUrl = tabs[0].url;
    
    // Send message to background script
    chrome.runtime.sendMessage({ action: "sendUrl", url: currentUrl }, (response) => {
      if (response.success) {
        alert("URL sent successfully!");
      } else {
        alert("Failed to send URL: " + response.error);
      }
    });
  });
});

manifest.json

{
  "manifest_version": 3,
  "name": "Send to Christmas-Community",
  "version": "1.0",
  "description": "Sends currentl URL to Christmas-Community",
  "permissions": ["tabs"],
  "host_permissions": ["https://your-api-endpoint.com/*"],
  "background": {
    "service_worker": "background.js"
  },
  "action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "icon.png",
      "48": "icon.png",
      "128": "icon.png"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant