vlff李飞飞
update logo
aa4486a
raw
history blame
2.18 kB
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(['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"+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.runtime.sendMessage({ data: access_token , close: true , flag: 'set_access_token'});
document.getElementById('access_token').value = '';
});
})