Skip to content

Commit 6a51a58

Browse files
committed
Added the template toggle to firefox's tab context menu
1 parent a1429e5 commit 6a51a58

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

background/background.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ async function createMenus() {
165165
title: "Download All Tabs as Markdown",
166166
contexts: ["tab"]
167167
}, () => {});
168+
169+
browser.contextMenus.create({
170+
id: "separator-0",
171+
type: "separator",
172+
contexts: ["tab"]
173+
}, () => { });
174+
175+
browser.contextMenus.create({
176+
id: "tabtoggle-includeTemplate",
177+
type: "checkbox",
178+
title: "Include front/back template",
179+
contexts: ["tab"],
180+
checked: options.includeTemplate
181+
}, () => { });
168182
} catch {
169183
// add the download all tabs option to the page context menu instead
170184
browser.contextMenus.create({
@@ -249,7 +263,7 @@ browser.contextMenus.onClicked.addListener(function (info, tab) {
249263
downloadMarkdownFromContext(info, tab);
250264
}
251265
// a settings toggle command
252-
else if (info.menuItemId.startsWith("toggle-")) {
266+
else if (info.menuItemId.startsWith("toggle-") || info.menuItemId.startsWith("tabtoggle-")) {
253267
toggleSetting(info.menuItemId.split('-')[1]);
254268
}
255269
});
@@ -265,6 +279,16 @@ async function toggleSetting(setting, options = null) {
265279
// toggle the option and save back to storage
266280
options[setting] = !options[setting];
267281
await browser.storage.sync.set(options);
282+
if (setting == "includeTemplate") {
283+
browser.contextMenus.update("toggle-includeTemplate", {
284+
checked: options.includeTemplate
285+
});
286+
try {
287+
browser.contextMenus.update("tabtoggle-includeTemplate", {
288+
checked: options.includeTemplate
289+
});
290+
} catch { }
291+
}
268292
}
269293
}
270294

options/options.js

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const saveOptions = e => {
4343
browser.contextMenus.update("toggle-includeTemplate", {
4444
checked: options.includeTemplate
4545
});
46+
try {
47+
browser.contextMenus.update("tabtoggle-includeTemplate", {
48+
checked: options.includeTemplate
49+
});
50+
} catch { }
4651
document.querySelectorAll(".status").forEach(statusEl => {
4752
statusEl.textContent = "Options saved.";
4853
statusEl.classList.remove('error');

popup/popup.js

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const toggleIncludeTemplate = options => {
4343
browser.contextMenus.update("toggle-includeTemplate", {
4444
checked: options.includeTemplate
4545
});
46+
try {
47+
browser.contextMenus.update("tabtoggle-includeTemplate", {
48+
checked: options.includeTemplate
49+
});
50+
} catch { }
4651
return clipSite()
4752
}).catch((error) => {
4853
console.error(error);

0 commit comments

Comments
 (0)