Restore popup defaults and update message lookups
This commit is contained in:
parent
58543b9ccd
commit
34cf8e234e
3 changed files with 17 additions and 29 deletions
|
@ -334,18 +334,6 @@ async function clearCacheForMessages(idsInput) {
|
||||||
browser.messageDisplayAction.setLabel({ label: "Details" });
|
browser.messageDisplayAction.setLabel({ label: "Details" });
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.messageDisplayAction.onClicked.addListener(async (tab) => {
|
|
||||||
const header = await browser.messageDisplay.getDisplayedMessage(tab.id);
|
|
||||||
if (!header) {
|
|
||||||
console.warn("[Sortana] no displayed message in tab", tab.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const popupUrl = `${browser.runtime.getURL("details.html")}?mid=${header.id}`;
|
|
||||||
|
|
||||||
await browser.messageDisplayAction.setPopup({ tabId: tab.id, popup: popupUrl });
|
|
||||||
await browser.messageDisplayAction.openPopup({ tabId: tab.id });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
|
@ -393,7 +381,7 @@ async function clearCacheForMessages(idsInput) {
|
||||||
(info.messageId ? [info.messageId] : []);
|
(info.messageId ? [info.messageId] : []);
|
||||||
await clearCacheForMessages(ids);
|
await clearCacheForMessages(ids);
|
||||||
} else if (info.menuItemId === "view-ai-reason-list" || info.menuItemId === "view-ai-reason-display") {
|
} else if (info.menuItemId === "view-ai-reason-list" || info.menuItemId === "view-ai-reason-display") {
|
||||||
const header = await browser.messageDisplay.getDisplayedMessage(tab.id);
|
const [header] = await browser.messageDisplay.getDisplayedMessages(tab.id);
|
||||||
if (!header) { return; }
|
if (!header) { return; }
|
||||||
|
|
||||||
const url = `${browser.runtime.getURL("details.html")}?mid=${header.id}`;
|
const url = `${browser.runtime.getURL("details.html")}?mid=${header.id}`;
|
||||||
|
|
27
details.js
27
details.js
|
@ -1,22 +1,21 @@
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
const logger = (await import(browser.runtime.getURL('logger.js'))).aiLog;
|
const aiLog = (await import(browser.runtime.getURL("logger.js"))).aiLog;
|
||||||
|
|
||||||
const midParam = new URLSearchParams(location.search).get('mid');
|
const qMid = parseInt(new URLSearchParams(location.search).get("mid"), 10);
|
||||||
const messageId = parseInt(midParam, 10);
|
if (!isNaN(qMid)) {
|
||||||
|
loadMessage(qMid);
|
||||||
if (!messageId) {
|
|
||||||
logger('no ?mid → trying displayedMessage fallback');
|
|
||||||
const openerTabId = (await browser.tabs.getCurrent()).openerTabId;
|
|
||||||
const header = await browser.messageDisplay.getDisplayedMessage(openerTabId);
|
|
||||||
if (!header) {
|
|
||||||
logger('still no message – aborting');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const thisTab = await browser.tabs.getCurrent();
|
||||||
|
const baseTabId = thisTab.openerTabId ?? thisTab.id;
|
||||||
|
const [header] = await browser.messageDisplay.getDisplayedMessages(baseTabId);
|
||||||
|
|
||||||
|
if (header) {
|
||||||
loadMessage(header.id);
|
loadMessage(header.id);
|
||||||
return;
|
} else {
|
||||||
|
aiLog("Details popup: no displayed message found");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMessage(messageId);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function loadMessage(id) {
|
async function loadMessage(id) {
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
"message_display_action": {
|
"message_display_action": {
|
||||||
"default_icon": "resources/img/brain.png",
|
"default_icon": "resources/img/brain.png",
|
||||||
"default_title": "Details",
|
"default_title": "Details",
|
||||||
"default_label": "Details"
|
"default_label": "Details",
|
||||||
|
"default_popup": "details.html"
|
||||||
},
|
},
|
||||||
"background": { "scripts": [ "background.js" ] },
|
"background": { "scripts": [ "background.js" ] },
|
||||||
"options_ui": {
|
"options_ui": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue