File size: 1,941 Bytes
6a9dc3a
2319518
 
3cac10f
6a9dc3a
3cac10f
 
aa4486a
3cac10f
 
 
 
 
 
 
 
 
 
 
 
2319518
 
 
 
 
 
 
 
 
 
 
6bca16b
2319518
6bca16b
2319518
 
 
 
 
 
 
f973cc6
2319518
6bca16b
2319518
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var database_url;

function send_data(msg){
    chrome.storage.local.get(['access_token'], function(result) {
        console.log(result)
        if (result.access_token) {
            console.log('access_token currently is ' + result.access_token);
            database_url = "https://llmbb-llmbb-agent.hf.space/endpoint";
            fetch(database_url, {
                method: "POST",
                headers: {
                  "Content-Type": "application/json",
                  "Authorization": result.access_token
                },
                body: JSON.stringify(msg),
            })
              .then((response) => response.json())
              .then((data) => {
                console.log(data.result);
              });
        }
     });
}

chrome.runtime.onMessage.addListener(async (msg, sender) => {
  if (msg.flag == "open_tab_and_cache_from_content"){
    var url = "";
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
      url = tabs[0].url;
      console.log(url);
      if (msg.data) {
        chrome.storage.sync.get(['data'], function(result) {
          chrome.storage.sync.set({ data: result.data }, function() {
            send_data({ 'content' : msg.data, 'query': '', 'url': url, 'task':'cache', 'type':msg.type});
          });
        });
      }
    });
  }
  if (msg.flag == "open_popup_and_send_url_from_popup"){
    if (msg.data) {
      chrome.storage.sync.get(['data','access_token'], function(result) {
        chrome.storage.sync.set({ data: result.data }, function() {
            send_data({ 'url' : msg.data, 'task':'pop_url'});
        });
      });
    }
  }
//  if (msg.flag == "set_addr"){
//    if (msg.data) {
//      chrome.storage.sync.get(['data'], function(result) {
//        chrome.storage.sync.set({ data: result.data }, function() {
//            send_data({ 'addr' : msg.data, 'task':'set_addr'});
//        });
//      });
//    }
//  }
});