Skip to content

Commit

Permalink
Fix ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkxin committed Apr 16, 2024
1 parent 3f9cbde commit 856f242
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
3 changes: 2 additions & 1 deletion firefox/hacks.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
globalThis["PERIDOCIALLY_REFRESH_MENU"] = true;
/* eslint-disable no-undef */
globalThis.PERIDOCIALLY_REFRESH_MENU = true;
53 changes: 27 additions & 26 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ async function flashBadge(type) {
chrome.alarms.create('clear', { when: Date.now() + FLASH_BADGE_TIMEOUT });
}

function createMenus() {
chrome.contextMenus.create({
id: 'current-page',
title: 'Copy [Page Title](URL)',
type: 'normal',
contexts: ['page'],
});

chrome.contextMenus.create({
id: 'link',
title: 'Copy [Link Content](URL)',
type: 'normal',
contexts: ['link'],
});

chrome.contextMenus.create({
id: 'image',
title: 'Copy ![](Image URL)', // TODO: how to fetch alt text?
type: 'normal',
contexts: ['image'],
});
}

chrome.alarms.onAlarm.addListener((alarm) => {
const entrypoint = chrome.action /* MV3 */ || chrome.browserAction; /* Firefox MV2 */

Expand Down Expand Up @@ -176,36 +199,14 @@ async function mustGetCurrentTab() {
return Promise.resolve(tabs[0]);
}

function createMenus() {
chrome.contextMenus.create({
id: 'current-page',
title: 'Copy [Page Title](URL)',
type: 'normal',
contexts: ['page'],
});

chrome.contextMenus.create({
id: 'link',
title: 'Copy [Link Content](URL)',
type: 'normal',
contexts: ['link'],
});

chrome.contextMenus.create({
id: 'image',
title: 'Copy ![](Image URL)', // TODO: how to fetch alt text?
type: 'normal',
contexts: ['image'],
});
}

chrome.runtime.onInstalled.addListener(createMenus);

if (globalThis["PERIDOCIALLY_REFRESH_MENU"] === true) {
// eslint-disable-next-line no-undef
if (globalThis.PERIDOCIALLY_REFRESH_MENU === true) {
// Hack for Firefox, in which Context Menu disappears after some time.
// See https://discourse.mozilla.org/t/strange-mv3-behaviour-browser-runtime-oninstalled-event-and-menus-create/111208/7
console.info("Hack PERIDOCIALLY_REFRESH_MENU is enabled");
chrome.alarms.create("refreshMenu", { periodInMinutes: 0.5});
console.info('Hack PERIDOCIALLY_REFRESH_MENU is enabled');
chrome.alarms.create('refreshMenu', { periodInMinutes: 0.5 });
}

// NOTE: All listeners must be registered at top level scope.
Expand Down

0 comments on commit 856f242

Please sign in to comment.