background.js 706 B

123456789101112131415161718192021222324252627
  1. // 监听扩展图标点击事件
  2. chrome.action.onClicked.addListener(async (tab) => {
  3. try {
  4. // 确保tab存在且有效
  5. if (!tab || !tab.id) {
  6. console.error('无效的标签页');
  7. return;
  8. }
  9. await chrome.tabs.sendMessage(tab.id, { action: "toggleSidebar" });
  10. } catch (error) {
  11. // 处理可能的错误,比如content script未加载等情况
  12. console.error('发送消息失败:', error);
  13. }
  14. });
  15. fetch('http://180.76.147.97:11435/api/chat', {
  16. method: 'post',
  17. body: JSON.stringify({
  18. model: "deepseek-r1:latest",
  19. messages: {
  20. "role": "user",
  21. "content": "why is the sky blue?"
  22. },
  23. stream: false
  24. })
  25. }).then(res => { console.log(res) })