2024-01-05 02:29:39 +00:00
|
|
|
const https_url="https://";
|
|
|
|
const http_url="https://";
|
|
|
|
|
|
|
|
class HeartBeatConnector
|
|
|
|
{
|
2024-01-08 10:49:46 +00:00
|
|
|
constructor() {
|
|
|
|
this.crypto_decrypt = null;
|
|
|
|
}
|
2024-01-05 02:29:39 +00:00
|
|
|
|
|
|
|
start() {
|
|
|
|
//console.log("start heart beat connector");
|
|
|
|
//load_font.loadFont();
|
|
|
|
|
2024-01-05 08:10:13 +00:00
|
|
|
sync_status_from_parent();
|
|
|
|
|
2024-01-05 02:29:39 +00:00
|
|
|
// Query the active tab before injecting the content script
|
2024-01-05 08:10:13 +00:00
|
|
|
/*
|
2024-01-05 02:29:39 +00:00
|
|
|
chrome.tabs.query(
|
|
|
|
{
|
|
|
|
active: true,
|
|
|
|
status: "complete",
|
|
|
|
currentWindow: true
|
|
|
|
}, (tabs) =>
|
|
|
|
{
|
|
|
|
if(tabs && tabs.length) {
|
|
|
|
//console.log(tabs);
|
|
|
|
//console.log(tabs[0]);
|
|
|
|
if (tabs[0].url.startsWith(https_url) || tabs[0].url.startsWith(http_url)) {
|
|
|
|
// Use the Scripting API to execute a script
|
|
|
|
chrome.scripting.executeScript(
|
|
|
|
{
|
|
|
|
target:
|
|
|
|
{
|
|
|
|
tabId: tabs[0].id
|
|
|
|
},
|
|
|
|
func: ack
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2024-01-05 08:10:13 +00:00
|
|
|
*/
|
2024-01-05 02:29:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-06 17:44:06 +00:00
|
|
|
function set_status_to(flag)
|
|
|
|
{
|
|
|
|
let nextState = 'ON';
|
|
|
|
if(!flag) {
|
|
|
|
nextState = 'OFF';
|
|
|
|
}
|
|
|
|
|
|
|
|
//console.log(nextState);
|
|
|
|
chrome.action.setBadgeText({
|
|
|
|
text: nextState
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.storage.local.set(
|
|
|
|
{
|
|
|
|
status: nextState
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-05 08:10:13 +00:00
|
|
|
function sync_status_from_parent()
|
|
|
|
{
|
|
|
|
//console.log("sync_status_from_parent");
|
|
|
|
|
|
|
|
let data_url = chrome.runtime.getURL("data/status.json");
|
|
|
|
fetch(data_url)
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.json()
|
|
|
|
} else if(response.status === 404) {
|
|
|
|
return Promise.reject('error 404')
|
|
|
|
} else {
|
|
|
|
return Promise.reject('some other error: ' + response.status)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then((data) =>
|
|
|
|
{
|
|
|
|
console.log(data);
|
|
|
|
if(data) {
|
2024-01-06 17:44:06 +00:00
|
|
|
set_status_to(data.status);
|
2024-01-05 08:10:13 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
//console.log('error is', error)
|
|
|
|
});
|
2024-01-06 17:44:06 +00:00
|
|
|
}
|
2024-01-05 08:10:13 +00:00
|
|
|
|
2024-01-05 02:29:39 +00:00
|
|
|
function ack() {
|
|
|
|
//console.log("act");
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new HeartBeatConnector();
|