View Single Post
Old 02-12-2025, 03:33 PM   #165
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,615
Karma: 7891011
Join Date: Sep 2020
Device: none
At the moment I'm trying to figure how a deepseek query could be made using just a url. Not sure it's possible. :\

This add-on works fine on browser context menu:

https://addons.mozilla.org/en-US/fir.../ask-deepseek/

Spoiler:

Code:
content.js:

function waitForElement(selector) {
  return new Promise(resolve => {
    const interval = setInterval(() => {
      const element = document.querySelector(selector);
      if (element) {
        clearInterval(interval);
        resolve(element);
      }
    }, 500);
  });
}

(async () => {
  try {
    const input = await waitForElement("textarea");
    const text = await navigator.clipboard.readText();
    
    input.value = text;
    input.dispatchEvent(new Event("input", { bubbles: true }));
    
    setTimeout(() => {
      input.dispatchEvent(new KeyboardEvent("keydown", {
        key: "Enter",
        code: "Enter",
        bubbles: true
      }));

      waitForElement(".assistant-message").then(response => {
        const memeBtn = document.createElement("button");
        memeBtn.textContent = " 🖼️ Meme";
        memeBtn.onclick = () => {
          window.open(`https://imgflip.com/memegenerator?text=${encodeURIComponent(response.innerText)}`);
        };
        
        const speakerBtn = document.createElement("button");
        speakerBtn.textContent = " 🔊 Read";
        speakerBtn.onclick = () => {
          const speech = new SpeechSynthesisUtterance(response.innerText);
          window.speechSynthesis.speak(speech);
        };
        
        response.prepend(memeBtn, speakerBtn);
        response.scrollIntoView({ behavior: "smooth" });
      });
    }, 1000);
    
  } catch (error) {
    console.error("Error:", error);
  }
})();

background.js:


// Parent menus
browser.contextMenus.create({
  id: "ask-menu",
  title: "Ask DeepSeek",
  contexts: ["selection"]
});

browser.contextMenus.create({
  id: "translate-menu",
  title: "Translate with DeepSeek",
  contexts: ["selection"]
});

browser.contextMenus.create({
  id: "support-menu",
  title: "☕ Buy Me a Coffee",
  contexts: ["all"] // Shows even without text selection
});

// Ask DeepSeek submenu
const askOptions = [
  { id: "ask-opinion", title: "🤔 What do you think of '%s'?" },
  { id: "ask-factcheck", title: "🔍 Fact check: '%s'" },
  { id: "ask-eli5", title: "🧒 ELI5: '%s'" },
  { id: "ask-debate", title: "⚖️ Debate: '%s'" },
  { id: "ask-tldr", title: "📌 TL;DR: '%s'" },
  { id: "ask-istrue", title: "✅ Is this true?: '%s'" },
  { id: "ask-questions", title: "❓ Question Me: '%s'" } // New feature
];

// Translate submenu
const languages = [
  { id: "en", title: "🇬🇧 English" },
  { id: "zh", title: "🇨🇳 Chinese" },
  { id: "hi", title: "🇮🇳 Hindi" },
  { id: "es", title: "🇪🇸 Spanish" },
  { id: "fr", title: "🇫🇷 French" },
  { id: "ar", title: "🇸🇦 Arabic" },
  { id: "bn", title: "🇧🇩 Bengali" },
  { id: "ru", title: "🇷🇺 Russian" },
  { id: "pt", title: "🇵🇹 Portuguese" },
  { id: "id", title: "🇮🇩 Indonesian" },
  { id: "ur", title: "🇵🇰 Urdu" },
  { id: "de", title: "🇩🇪 German" },
  { id: "ja", title: "🇯🇵 Japanese" },
  { id: "sw", title: "🇹🇿 Swahili" },
  { id: "mr", title: "🇮🇳 Marathi" },
  { id: "it", title: "🇮🇹 Italian" }
];

// Build menus
askOptions.forEach(option => {
  browser.contextMenus.create({
    id: option.id,
    title: option.title,
    contexts: ["selection"],
    parentId: "ask-menu"
  });
});

languages.forEach(lang => {
  browser.contextMenus.create({
    id: `translate-${lang.id}`,
    title: lang.title,
    contexts: ["selection"],
    parentId: "translate-menu"
  });
});

// Click handler
browser.contextMenus.onClicked.addListener(async (info, tab) => {
  // Handle "Buy Me a Coffee"
  if (info.menuItemId === "support-menu") {
    browser.tabs.create({ url: "https://buymeacoffee.com/technologicalpixel" });
    return;
  }

  const text = info.selectionText;
  let question;

  // Ask DeepSeek options
  if (info.menuItemId.startsWith("ask-")) {
    switch(info.menuItemId) {
      case "ask-opinion": question = `What do you think of "${text}"?`; break;
      case "ask-factcheck": question = `Fact-check this: "${text}". Provide sources.`; break;
      case "ask-eli5": question = `Explain this like I'm 5: "${text}". Use simple words.`; break;
      case "ask-debate": question = `Argue both FOR and AGAINST: "${text}".`; break;
      case "ask-tldr": question = `Summarize this in 3 bullet points: "${text}".`; break;
      case "ask-istrue": question = `Is this true? Explain why: "${text}".`; break;
      case "ask-questions": question = `Generate 10 thought-provoking questions about: "${text}".`; break;
    }
  }

  // Translate options
  if (info.menuItemId.startsWith("translate-")) {
    const lang = languages.find(l => `translate-${l.id}` === info.menuItemId);
    question = `Translate this to ${lang.title}: "${text}"`;
  }

  // Copy & open DeepSeek
  if (question) {
    await navigator.clipboard.writeText(question);
    const deepseekTab = await browser.tabs.create({
      url: "https://chat.deepseek.com/",
      active: true
    });

    setTimeout(() => {
      browser.tabs.executeScript(deepseekTab.id, { file: "content.js" });
    }, 1000);
  }
});

Last edited by Comfy.n; 02-12-2025 at 03:36 PM.
Comfy.n is offline   Reply With Quote