File size: 2,477 Bytes
2319518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e62994
2319518
f001d2a
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
60
61
62
63
64
65
66


chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
    // if (msg.flag == 'from_content'){
    //   console.log(msg.rsp);
    //   var sessionContainer = document.getElementById('session');
    //   sessionContainer.innerText = msg.rsp;
    //   sendResponse({ msg: 'Get!' });
    // }
    if (msg.flag === 'from_llm'){
      // var sessionContainer = document.getElementById('session');
      // // sessionContainer.innerHTML = msg.rsp;
      // sessionContainer.innerText = msg.rsp;
      sendResponse({ message: 'Get Response!' });
    }
});


document.addEventListener('DOMContentLoaded', function() {
    chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
      var currentUrl = tabs[0].url;

      chrome.runtime.sendMessage({ data: currentUrl , close: true , flag: 'open_popup_and_send_url_from_popup'});

    });
    setTimeout(function() {
//        console.log('This message will be logged after 0.5 second');
        var popup_url='';
        chrome.storage.local.get(['database_host'], function(result) {
            if (result.database_host) {
                console.log('database_host currently is ' + result.database_host);
                popup_url = "https://taohongxiu-qwen-agent.hf.space/";
            } else {
                popup_url = "https://taohongxiu-qwen-agent.hf.space/";
            }
            var iframe = document.createElement('iframe');
            iframe.src = popup_url;
            iframe.height = '570px';
//            iframe.sandbox = 'allow-same-origin allow-scripts';
//            iframe.allow = "geolocation *;";
            var iframe_area = document.getElementById('iframe_area')
            iframe_area.appendChild(iframe);

        });
    }, 500);

//    fetch('../config_host.json')
//      .then(response => response.json())
//      .then(data => {
//        console.log(data);
//        popup_url = "http://"+data.database_host+":"+data.app_in_browser_port+"/";
//        console.log(popup_url);
//    })
//    .catch(error => console.error('Error:', error));
})

document.getElementById('set_addr').addEventListener('click', function() {
    var addr = document.getElementById('addr').value;
    // save config
    chrome.storage.local.set({database_host: addr}, function() {
      console.log('database_host is set to ' + addr);
//      chrome.runtime.sendMessage({ data: addr , close: true , flag: 'set_addr'});
      document.getElementById('addr').value = '';
    });
})