Trying new things

This commit is contained in:
Jordan Wages 2025-07-06 18:05:19 -05:00
commit 13751b3ab2
3 changed files with 23 additions and 21 deletions

View file

@ -258,7 +258,7 @@ async function clearCacheForMessages(idsInput) {
logger = await import(browser.runtime.getURL("logger.js")); logger = await import(browser.runtime.getURL("logger.js"));
try { try {
AiClassifier = await import(browser.runtime.getURL("modules/AiClassifier.js")); AiClassifier = await import(browser.runtime.getURL("modules/AiClassifier.js"));
logger.aiLog("AiClassifier imported", {debug: true}); logger.aiLog("AiClassifier imported", { debug: true });
const td = await import(browser.runtime.getURL("resources/js/turndown.js")); const td = await import(browser.runtime.getURL("resources/js/turndown.js"));
TurndownService = td.default || td.TurndownService; TurndownService = td.default || td.TurndownService;
} catch (e) { } catch (e) {
@ -291,7 +291,7 @@ async function clearCacheForMessages(idsInput) {
if (r.stopProcessing) rule.stopProcessing = true; if (r.stopProcessing) rule.stopProcessing = true;
return rule; return rule;
}) : []; }) : [];
logger.aiLog("configuration loaded", {debug: true}, store); logger.aiLog("configuration loaded", { debug: true }, store);
storage.onChanged.addListener(async changes => { storage.onChanged.addListener(async changes => {
if (changes.aiRules) { if (changes.aiRules) {
const newRules = changes.aiRules.newValue || []; const newRules = changes.aiRules.newValue || [];
@ -304,30 +304,30 @@ async function clearCacheForMessages(idsInput) {
if (r.stopProcessing) rule.stopProcessing = true; if (r.stopProcessing) rule.stopProcessing = true;
return rule; return rule;
}); });
logger.aiLog("aiRules updated from storage change", {debug: true}, aiRules); logger.aiLog("aiRules updated from storage change", { debug: true }, aiRules);
} }
if (changes.htmlToMarkdown) { if (changes.htmlToMarkdown) {
htmlToMarkdown = changes.htmlToMarkdown.newValue === true; htmlToMarkdown = changes.htmlToMarkdown.newValue === true;
logger.aiLog("htmlToMarkdown updated from storage change", {debug: true}, htmlToMarkdown); logger.aiLog("htmlToMarkdown updated from storage change", { debug: true }, htmlToMarkdown);
} }
if (changes.stripUrlParams) { if (changes.stripUrlParams) {
stripUrlParams = changes.stripUrlParams.newValue === true; stripUrlParams = changes.stripUrlParams.newValue === true;
logger.aiLog("stripUrlParams updated from storage change", {debug: true}, stripUrlParams); logger.aiLog("stripUrlParams updated from storage change", { debug: true }, stripUrlParams);
} }
if (changes.altTextImages) { if (changes.altTextImages) {
altTextImages = changes.altTextImages.newValue === true; altTextImages = changes.altTextImages.newValue === true;
logger.aiLog("altTextImages updated from storage change", {debug: true}, altTextImages); logger.aiLog("altTextImages updated from storage change", { debug: true }, altTextImages);
} }
if (changes.collapseWhitespace) { if (changes.collapseWhitespace) {
collapseWhitespace = changes.collapseWhitespace.newValue === true; collapseWhitespace = changes.collapseWhitespace.newValue === true;
logger.aiLog("collapseWhitespace updated from storage change", {debug: true}, collapseWhitespace); logger.aiLog("collapseWhitespace updated from storage change", { debug: true }, collapseWhitespace);
} }
}); });
} catch (err) { } catch (err) {
logger.aiLog("failed to load config", {level: 'error'}, err); logger.aiLog("failed to load config", { level: 'error' }, err);
} }
logger.aiLog("background.js loaded ready to classify", {debug: true}); logger.aiLog("background.js loaded ready to classify", { debug: true });
if (browser.messageDisplayAction) { if (browser.messageDisplayAction) {
browser.messageDisplayAction.setTitle({ title: "Details" }); browser.messageDisplayAction.setTitle({ title: "Details" });
if (browser.messageDisplayAction.setLabel) { if (browser.messageDisplayAction.setLabel) {
@ -372,7 +372,7 @@ async function clearCacheForMessages(idsInput) {
//for the love of god work please //for the love of god work please
browser.messageDisplayAction.onClicked.addListener(async (tab, info) => { browser.messageDisplayAction.onClicked.addListener(async (tab, info) => {
try { try {
let header = await browser.messageDisplay.getDisplayedMessages(); let header = await browser.messageDisplay.getDisplayedMessages(tab.id);
if (!header) { if (!header) {
logger.aiLog("No header, no message loaded?", { debug: true }); logger.aiLog("No header, no message loaded?", { debug: true });
return; return;
@ -386,6 +386,10 @@ async function clearCacheForMessages(idsInput) {
} }
}); });
browser.messageDisplay.onMessagesDisplayed.addListener(async (tab, displayedMessages) => {
logger.aiLog("Messages displayed!", { debug: true }, displayedMessages);
});
browser.menus.onClicked.addListener(async (info, tab) => { browser.menus.onClicked.addListener(async (info, tab) => {
if (info.menuItemId === "apply-ai-rules-list" || info.menuItemId === "apply-ai-rules-display") { if (info.menuItemId === "apply-ai-rules-list" || info.menuItemId === "apply-ai-rules-display") {
const ids = info.selectedMessages?.messages?.map(m => m.id) || const ids = info.selectedMessages?.messages?.map(m => m.id) ||

View file

@ -8,14 +8,14 @@ document.addEventListener("DOMContentLoaded", async () => {
} }
const thisTab = await browser.tabs.getCurrent(); const thisTab = await browser.tabs.getCurrent();
const baseTabId = thisTab.openerTabId ?? thisTab.id; //const baseTabId = thisTab.openerTabId ?? thisTab.id;
const [header] = await browser.messageDisplay.getDisplayedMessages(baseTabId); //const [header] = await browser.messageDisplay.getDisplayedMessages(baseTabId);
if (header) { //if (header) {
loadMessage(header.id); // loadMessage(header.id);
} else { //} else {
aiLog("Details popup: no displayed message found"); // aiLog("Details popup: no displayed message found");
} //}
}); });
async function loadMessage(id) { async function loadMessage(id) {

View file

@ -40,8 +40,6 @@
"accountsRead", "accountsRead",
"menus", "menus",
"scripting", "scripting",
"tabs", "tabs"
"*://*/*" ]
],
"content_security_policy": "script-src 'self'; object-src 'none'; connect-src 'self' http: https:"
} }