File size: 2,994 Bytes
b53a832
 
2319518
 
b53a832
3cac10f
 
 
 
b53a832
3cac10f
b53a832
 
3cac10f
 
b53a832
 
 
 
 
 
 
2319518
 
b53a832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa4486a
2319518
3cac10f
 
 
 
 
83f4493
 
 
 
 
 
3cac10f
 
 
aa4486a
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
//var assistant_url="http://127.0.0.1:7860/assistant/";
var assistant_url="https://llmbb-llmbb-agent.hf.space/assistant";
document.addEventListener('DOMContentLoaded', function() {
    chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
        var currentUrl = tabs[0].url;
        chrome.storage.local.get(['access_token'], function(result) {
            if (result.access_token) {
                console.log('access_token currently is ' + result.access_token);
                var iframe = document.createElement('iframe');
                iframe.src = assistant_url + "?access_token="+result.access_token+"&url=" + currentUrl;
                iframe.height = '570px';
        //            iframe.sandbox = 'allow-same-origin allow-scripts';
        //            iframe.allow = "geolocation *;";
                var iframe_area = document.getElementById('iframe_area')
                iframe_area.appendChild(iframe);
            }else{
                chrome.notifications.create("access_token", {
                         type: 'basic',
                         iconUrl: 'img/popup.png',
                         title: 'access token',
                         message: 'access token is not valid!'
                });
            }
        });
//      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(['access_token'], function(result) {
//            if (result.access_token) {
//                console.log('access_token currently is ' + result.access_token);
//                popup_url = "https://llmbb-llmbb-agent.hf.space/?access_token="+result.access_token;
//                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);
})

document.getElementById('set_access_token').addEventListener('click', function() {
    var access_token = document.getElementById('access_token').value;
    // save config
    chrome.storage.local.set({access_token: access_token}, function() {
      console.log('access_token is set to ' + access_token);
      chrome.notifications.create("set_access_token", {
         type: 'basic',
         iconUrl: 'img/popup.png',
         title: 'set access token',
         message: 'set access token success, please reopen this extension!'
       });
//      chrome.runtime.sendMessage({ data: access_token , close: true , flag: 'set_access_token'});
      document.getElementById('access_token').value = '';
    });
})