chd před 1 měsícem
rodič
revize
e1fc20a262

+ 155 - 156
src/entrypoints/background/index.ts

@@ -1,4 +1,3 @@
-import { onMessage, sendMessage } from 'webext-bridge/background'
 import { navigator } from '@/utils/navigator.js'
 import { plan, messageList } from './plan'
 
@@ -16,163 +15,163 @@ export default defineBackground(() => {
     .setPanelBehavior({ openPanelOnActionClick: true })
     .catch((error) => console.error(error))
 
-  chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
-    if (message.type === 'CLICK_EVENT') {
-      if (token) {
-        arr.push({
-          ...message.data,
-          userId: token
-        })
-        if (arr.length > 10) {
-          fetch(url, {
-            method: 'POST',
-            headers: {
-              'Content-Type': 'application/json',
-              'Authorization': 'Bearer ' + token
-            },
-            body: JSON.stringify(arr.map(_ => ({ ..._, userId })))
-          }).then(res => 1)
-          arr = []
-        }
-      }
-    }
-    if (message.type === 'PAGE_INFO') {
-      // 转发到侧边栏
-      chrome.runtime.sendMessage({
-        type: 'TO_SIDE_PANEL_PAGE_INFO',
-        data: message.data
-      })
-    }
-    if (message.type === 'FROM_CONTENT_TO_SEND_PAGE_FORM') {
-      chrome.runtime.sendMessage({
-        type: 'TO_SIDE_PANEL_FORM_INFO',
-        data: message.data
-      })
-    }
-    if (message.type === 'SET_SELECT') {
-      chrome.tabs.query({}, (tabs) => {
-        tabs.forEach(tab => {
-          if (tab.id) {
-            chrome.tabs.sendMessage(tab.id, {
-              type: 'SET_SELECT_TO_CENTENT',
-              data: 1
-            }, (response) => {
-              if (chrome.runtime.lastError) {
-                console.error(`Tab ${tab.id} 错误: ${chrome.runtime.lastError.message}`)
-              } else {
-                console.log(`Tab ${tab.id} 响应:`, response)
-              }
-            })
-          }
-        })
-      })
-      chrome.runtime.sendMessage({
-        type: 'SET_SELECT_TO_CENTENT',
-        data: 1
-      })
-    }
-    if (message.type === 'GET_SETTING_INFO') {
-      console.log(message)
+  // chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
+  //   if (message.type === 'CLICK_EVENT') {
+  //     if (token) {
+  //       arr.push({
+  //         ...message.data,
+  //         userId: token
+  //       })
+  //       if (arr.length > 10) {
+  //         fetch(url, {
+  //           method: 'POST',
+  //           headers: {
+  //             'Content-Type': 'application/json',
+  //             'Authorization': 'Bearer ' + token
+  //           },
+  //           body: JSON.stringify(arr.map(_ => ({ ..._, userId })))
+  //         }).then(res => 1)
+  //         arr = []
+  //       }
+  //     }
+  //   }
+  //   // if (message.type === 'PAGE_INFO') {
+  //   //   // 转发到侧边栏
+  //   //   chrome.runtime.sendMessage({
+  //   //     type: 'TO_SIDE_PANEL_PAGE_INFO',
+  //   //     data: message.data
+  //   //   })
+  //   // }
+  //   if (message.type === 'FROM_CONTENT_TO_SEND_PAGE_FORM') {
+  //     chrome.runtime.sendMessage({
+  //       type: 'TO_SIDE_PANEL_FORM_INFO',
+  //       data: message.data
+  //     })
+  //   }
+  //   if (message.type === 'SET_SELECT') {
+  //     chrome.tabs.query({}, (tabs) => {
+  //       tabs.forEach(tab => {
+  //         if (tab.id) {
+  //           chrome.tabs.sendMessage(tab.id, {
+  //             type: 'SET_SELECT_TO_CENTENT',
+  //             data: 1
+  //           }, (response) => {
+  //             if (chrome.runtime.lastError) {
+  //               console.error(`Tab ${tab.id} 错误: ${chrome.runtime.lastError.message}`)
+  //             } else {
+  //               console.log(`Tab ${tab.id} 响应:`, response)
+  //             }
+  //           })
+  //         }
+  //       })
+  //     })
+  //     chrome.runtime.sendMessage({
+  //       type: 'SET_SELECT_TO_CENTENT',
+  //       data: 1
+  //     })
+  //   }
+  //   if (message.type === 'GET_SETTING_INFO') {
+  //     console.log(message)
 
-      chrome.storage.local.get('token', (result) => {
-        sendResponse(result.token || '')
-      })
-    }
+  //     chrome.storage.local.get('token', (result) => {
+  //       sendResponse(result.token || '')
+  //     })
+  //   }
 
-    if (message.type === 'FROM_SIDE_PANEL_TO_ACTION') {
-      chrome.tabs.query({ active: true }, (tabs) => {
-        if (tabs.length === 0) return // 确保有活动标签页
-        const tabId = tabs[0].id // 获取当前活动的 tabId
-        chrome.tabs.sendMessage(
-          tabId,
-          { type: 'GET_TAG_ACTION', data: message.data },
-          (response) => {
-            if (chrome.runtime.lastError) {
-              console.error('消息发送失败:', chrome.runtime.lastError.message)
-            } else {
-              console.log('收到 content script 响应:', response)
-              console.log(response, 998)
-              sendResponse(response)
-            }
-          }
-        )
-      })
-      return true
-    }
-    if (message.type === 'FROM_SIDE_PANEL_TO_GET_PAGE_FORM') {
-      chrome.tabs.query({ active: true }, (tabs) => {
-        if (tabs.length === 0) return // 确保有活动标签页
-        const tabId = tabs[0].id // 获取当前活动的 tabId
-        chrome.tabs.sendMessage(
-          tabId,
-          { type: 'GET_PAGE_FORM', data: 'Hello from background!' },
-          (response) => {
-            if (chrome.runtime.lastError) {
-              console.error('消息发送失败:', chrome.runtime.lastError.message)
-            } else {
-              console.log('收到 content script 响应:', response)
-              sendResponse(response)
-            }
-            return true
-          }
-        )
-      })
-      return true
-    }
-    if (message.type === 'FROM_SIDE_PANEL_TO_INPUT_FORM') {
-      chrome.tabs.query({ active: true }, (tabs) => {
-        if (tabs.length === 0) return // 确保有活动标签页
-        const tabId = tabs[1].id // 获取当前活动的 tabId
-        chrome.tabs.sendMessage(
-          tabId,
-          { type: 'INPUT_FORM' },
-          (response) => {
-            if (chrome.runtime.lastError) {
-              console.error('消息发送失败:', chrome.runtime.lastError.message)
-            } else {
-              console.log('收到 content script 响应:', response)
-              sendResponse(response.data)
-            }
-          }
-        )
-      })
-      return true
-    }
-    if (message.type === 'FROM_SIDE_PANEL_TO_GET_PAGE_INFO') {
-      chrome.tabs.query({ active: true }, (tabs) => {
-        if (tabs.length === 0) return // 确保有活动标签页
-        const tabId = tabs[0].id // 获取当前活动的 tabId
-        chrome.tabs.sendMessage(
-          tabId,
-          { type: 'GET_PAGE_INFO', data: 'Hello from background!' },
-          (response) => {
-            if (chrome.runtime.lastError) {
-              console.error('消息发送失败:', chrome.runtime.lastError.message)
-            } else {
-              console.log('收到 content script 响应:', response)
-              sendResponse(response.data)
-            }
-          })
-      })
-      return true
-    }
-    // 截图
-    if (message.type === 'SCREENSHOT') {
-      chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
-        if (tabs.length === 0) return // 确保有活动标签页
-        const tabId = tabs[0].id // 获取当前活动的 tabId
-        chrome.tabs.sendMessage(tabId, message, (response) => {
-          if (chrome.runtime.lastError) {
-            sendResponse(chrome.runtime.lastError.message)
-          } else {
-            sendResponse(response)
-          }
-        })
-      })
-      return true
-    }
-    return true
-  })
+  //   if (message.type === 'FROM_SIDE_PANEL_TO_ACTION') {
+  //     chrome.tabs.query({ active: true }, (tabs) => {
+  //       if (tabs.length === 0) return // 确保有活动标签页
+  //       const tabId = tabs[0].id // 获取当前活动的 tabId
+  //       chrome.tabs.sendMessage(
+  //         tabId,
+  //         { type: 'GET_TAG_ACTION', data: message.data },
+  //         (response) => {
+  //           if (chrome.runtime.lastError) {
+  //             console.error('消息发送失败:', chrome.runtime.lastError.message)
+  //           } else {
+  //             console.log('收到 content script 响应:', response)
+  //             console.log(response, 998)
+  //             sendResponse(response)
+  //           }
+  //         }
+  //       )
+  //     })
+  //     return true
+  //   }
+  //   if (message.type === 'FROM_SIDE_PANEL_TO_GET_PAGE_FORM') {
+  //     chrome.tabs.query({ active: true }, (tabs) => {
+  //       if (tabs.length === 0) return // 确保有活动标签页
+  //       const tabId = tabs[0].id // 获取当前活动的 tabId
+  //       chrome.tabs.sendMessage(
+  //         tabId,
+  //         { type: 'GET_PAGE_FORM', data: 'Hello from background!' },
+  //         (response) => {
+  //           if (chrome.runtime.lastError) {
+  //             console.error('消息发送失败:', chrome.runtime.lastError.message)
+  //           } else {
+  //             console.log('收到 content script 响应:', response)
+  //             sendResponse(response)
+  //           }
+  //           return true
+  //         }
+  //       )
+  //     })
+  //     return true
+  //   }
+  //   if (message.type === 'FROM_SIDE_PANEL_TO_INPUT_FORM') {
+  //     chrome.tabs.query({ active: true }, (tabs) => {
+  //       if (tabs.length === 0) return // 确保有活动标签页
+  //       const tabId = tabs[1].id // 获取当前活动的 tabId
+  //       chrome.tabs.sendMessage(
+  //         tabId,
+  //         { type: 'INPUT_FORM' },
+  //         (response) => {
+  //           if (chrome.runtime.lastError) {
+  //             console.error('消息发送失败:', chrome.runtime.lastError.message)
+  //           } else {
+  //             console.log('收到 content script 响应:', response)
+  //             sendResponse(response.data)
+  //           }
+  //         }
+  //       )
+  //     })
+  //     return true
+  //   }
+  //   if (message.type === 'FROM_SIDE_PANEL_TO_GET_PAGE_INFO') {
+  //     chrome.tabs.query({ active: true }, (tabs) => {
+  //       if (tabs.length === 0) return // 确保有活动标签页
+  //       const tabId = tabs[0].id // 获取当前活动的 tabId
+  //       chrome.tabs.sendMessage(
+  //         tabId,
+  //         { type: 'GET_PAGE_INFO', data: 'Hello from background!' },
+  //         (response) => {
+  //           if (chrome.runtime.lastError) {
+  //             console.error('消息发送失败:', chrome.runtime.lastError.message)
+  //           } else {
+  //             console.log('收到 content script 响应:', response)
+  //             sendResponse(response.data)
+  //           }
+  //         })
+  //     })
+  //     return true
+  //   }
+  //   // 截图
+  //   if (message.type === 'SCREENSHOT') {
+  //     chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
+  //       if (tabs.length === 0) return // 确保有活动标签页
+  //       const tabId = tabs[0].id // 获取当前活动的 tabId
+  //       chrome.tabs.sendMessage(tabId, message, (response) => {
+  //         if (chrome.runtime.lastError) {
+  //           sendResponse(chrome.runtime.lastError.message)
+  //         } else {
+  //           sendResponse(response)
+  //         }
+  //       })
+  //     })
+  //     return true
+  //   }
+  //   return true
+  // })
   let timer
   // chrome.tabs.onRemoved.addListener(function (...a) {
   //   clearTimeout(timer)

+ 25 - 25
src/entrypoints/content.js

@@ -25,34 +25,34 @@ export default defineContentScript({
     let iframe = null
     let iframeDoc = null
     let select = false
-    window.onload = () => {
-      iframe = document.querySelector('iframe')
-      iframeDoc = iframe?.contentWindow?.document
-      // chrome.runtime.sendMessage({
-      //   type: 'GET_SETTING_INFO',
-      //   data: {
-      //     url:location.href
-      //   }
-      // }, function (response) {
-      //   console.log(response,88896);
+    // window.onload = () => {
+    //   iframe = document.querySelector('iframe')
+    //   iframeDoc = iframe?.contentWindow?.document
+    //   // chrome.runtime.sendMessage({
+    //   //   type: 'GET_SETTING_INFO',
+    //   //   data: {
+    //   //     url:location.href
+    //   //   }
+    //   // }, function (response) {
+    //   //   console.log(response,88896);
 
-      // });
-      chrome.storage.local.get(['domainList', 'collect'], (result) => {
-        const urls = result.domainList && Object.values(result.domainList)
-        select = result.collect && !!urls?.find(_ => location.href.includes(_))
-        console.log(select)
+    //   // });
+    //   chrome.storage.local.get(['domainList', 'collect'], (result) => {
+    //     const urls = result.domainList && Object.values(result.domainList)
+    //     select = result.collect && !!urls?.find(_ => location.href.includes(_))
+    //     console.log(select)
 
-        if (select) {
-          document.addEventListener('click', handleClick)
-          document.addEventListener('mouseover', handleMouseover)
-        } else {
-          console.log(2222)
+    //     if (select) {
+    //       document.addEventListener('click', handleClick)
+    //       document.addEventListener('mouseover', handleMouseover)
+    //     } else {
+    //       console.log(2222)
 
-          document.removeEventListener('click', handleClick)
-          document.removeEventListener('mouseover', handleMouseover)
-        }
-      })
-    }
+    //       document.removeEventListener('click', handleClick)
+    //       document.removeEventListener('mouseover', handleMouseover)
+    //     }
+    //   })
+    // }
     let form = null
     let formChildren = []
     let excelDataA = {}

+ 3 - 3
src/entrypoints/options/App.vue

@@ -31,9 +31,9 @@ async function openFile() {
 }
 
 onMounted(() => {
-  chrome.runtime.sendMessage({
-    type: 'GET_CONTENT_INFO'
-  })
+  // chrome.runtime.sendMessage({
+  //   type: 'GET_CONTENT_INFO'
+  // })
 })
 
 async function saveFile() {

+ 1 - 1
src/entrypoints/sidepanel/AdvancedMode.vue

@@ -18,7 +18,7 @@
                :class="['message-item', message.role === 'user'  ? 'self' : 'other']">
             <el-avatar :size="32" :src="message.role === 'user' ? userAvatar : avatar" />
             <div class="message-content">
-              <div class="content w-full" v-if="message.role ==='system'"
+              <div class="content w-full" v-if="message.role ==='system'" m,,, j                 
                 :class="{ 'loading-content': message.content === '' }">
                 <StepsDisplay 
                 v-if="message.type === 'plan'"

+ 3 - 3
src/entrypoints/sidepanel/App.vue

@@ -39,9 +39,9 @@ onMounted(async () => {
     }
   })
   // 初始化数据库连接(不包含任何Store)
-  chrome.runtime.sendMessage({
-    type: 'GET_CONTENT_INFO'
-  })
+  // chrome.runtime.sendMessage({
+  //   type: 'GET_CONTENT_INFO'
+  // })
 })
 </script>