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';
|
|
|
|
|
2024-01-03 11:36:26 +00:00
|
|
|
const storage = chrome.storage.local;
|
|
|
|
|
2024-01-01 15:58:30 +00:00
|
|
|
chrome.declarativeNetRequest.onRuleMatchedDebug.addListener((e) => {
|
|
|
|
const msg = `Navigation blocked to ${e.request.url} on tab ${e.request.tabId}.`;
|
|
|
|
//console.log(msg);
|
|
|
|
});
|
|
|
|
|
2023-12-31 18:40:47 +00:00
|
|
|
chrome.runtime.onInstalled.addListener(function(){
|
|
|
|
fetch("data/settings.json")
|
|
|
|
.then((resp) => resp.json())
|
|
|
|
.then((settings) =>
|
|
|
|
{
|
|
|
|
chrome.storage.local.set(
|
|
|
|
{
|
|
|
|
settings: settings
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2024-01-03 11:36:26 +00:00
|
|
|
|
|
|
|
let default_status='ON';
|
|
|
|
chrome.action.setBadgeText({
|
|
|
|
text: default_status
|
|
|
|
});
|
|
|
|
storage.set({status: default_status});
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.action.onClicked.addListener(async (tab) => {
|
|
|
|
const prevState = await chrome.action.getBadgeText({ tabId: tab.id });
|
|
|
|
// Next state will always be the opposite
|
|
|
|
const nextState = prevState === 'ON' ? 'OFF' : 'ON';
|
|
|
|
storage.set({status: nextState});
|
|
|
|
|
|
|
|
// Set the action badge to the next state
|
|
|
|
await chrome.action.setBadgeText({
|
|
|
|
tabId: tab.id,
|
|
|
|
text: nextState
|
|
|
|
});
|
2024-01-01 15:58:30 +00:00
|
|
|
});
|