tixcraft_bot/webdriver/Maxbotplus_1.0.0/background.js

89 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-01-03 11:36:26 +00:00
/*
* extension process crashes or your extension is manually stopped at
* chrome://serviceworker-internals
*/
2024-01-01 15:58:30 +00:00
'use strict';
2023-12-31 18:40:47 +00:00
chrome.runtime.onInstalled.addListener(function(){
console.log("onInstalled");
let default_status='ON';
chrome.action.setBadgeText({
text: default_status
});
2023-12-31 18:40:47 +00:00
fetch("data/settings.json")
.then((resp) => resp.json())
.then((settings) =>
{
chrome.storage.local.set(
{
settings: settings,
status: default_status
2023-12-31 18:40:47 +00:00
}
);
console.log("dump settings.json to storage");
2023-12-31 18:40:47 +00:00
}
);
});
2024-01-03 11:36:26 +00:00
chrome.declarativeNetRequest.onRuleMatchedDebug.addListener((e) => {
const msg = `Navigation blocked to ${e.request.url} on tab ${e.request.tabId}.`;
//console.log(msg);
2024-01-03 11:36:26 +00:00
});
2024-01-06 17:44:06 +00:00
function set_status_to(flag)
{
let nextState = 'ON';
if(!flag) nextState = 'OFF';
2024-01-05 04:59:42 +00:00
chrome.storage.local.set(
{
status: nextState
}
);
2024-01-03 11:36:26 +00:00
2024-01-06 17:44:06 +00:00
chrome.action.setBadgeText({
text: nextState
});
}
chrome.action.onClicked.addListener(async (tab) => {
chrome.storage.local.get('status', function (items)
{
let next_flag = true;
if (items.status && items.status=='ON')
{
next_flag = false;
}
console.log("next_flag:"+next_flag);
set_status_to(next_flag);
2024-01-03 11:36:26 +00:00
});
2024-01-01 15:58:30 +00:00
});
import heartbeatconnect from './modules/heartbeatconnect.js';
let heartbeatInterval;
async function runHeartbeat()
{
//console.log("runHeartbeat");
heartbeatconnect.start();
}
async function startHeartbeat()
{
runHeartbeat().then(() =>
{
heartbeatInterval = setInterval(runHeartbeat, 1 * 1000);
}
);
}
async function stopHeartbeat()
{
clearInterval(heartbeatInterval);
}
startHeartbeat();