Show suggestion to right click on a link, if the user right clicks text

This commit is contained in:
shinigami-eyes 2020-12-26 08:55:04 +00:00
parent 64a10cdb19
commit 15bc6a3417
3 changed files with 43 additions and 17 deletions

View File

@ -383,14 +383,7 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesMessage
loadBloomFilter('transphobic');
loadBloomFilter('t-friendly');
function createContextMenu(text: string, id: ContextMenuCommand) {
browser.contextMenus.create({
id: id,
title: text,
contexts: ["link"],
targetUrlPatterns: [
const socialNetworkPatterns = [
"*://*.facebook.com/*",
"*://*.youtube.com/*",
"*://*.reddit.com/*",
@ -404,7 +397,9 @@ function createContextMenu(text: string, id: ContextMenuCommand) {
"*://*.google.com/*",
"*://*.bing.com/*",
"*://duckduckgo.com/*",
];
const homepagePatterns = [
"*://*/",
"*://*/?fbclid=*",
"*://*/about*",
@ -417,16 +412,45 @@ function createContextMenu(text: string, id: ContextMenuCommand) {
"*://*/en/",
"*://*/index.html",
"*://*/index.php",
]
];
const allPatterns = socialNetworkPatterns.concat(homepagePatterns);
function createEntityContextMenu(text: string, id: ContextMenuCommand) {
browser.contextMenus.create({
id: id,
title: text,
contexts: ["link"],
targetUrlPatterns: allPatterns
});
}
createContextMenu('Mark as anti-trans', 'mark-transphobic');
createContextMenu('Mark as t-friendly', 'mark-t-friendly');
createContextMenu('Clear', 'mark-none');
browser.contextMenus.create({ type: 'separator' });
createContextMenu('Settings', 'options');
createContextMenu('Help', 'help');
function createSystemContextMenu(text: string, id: ContextMenuCommand, separator?: boolean) {
browser.contextMenus.create({
id: id,
title: text,
contexts: ["all"],
type: separator ? 'separator' : 'normal',
documentUrlPatterns: allPatterns
});
}
browser.contextMenus.create({
title: '(Please right click on a link instead)',
enabled: false,
contexts: ['page'],
documentUrlPatterns: socialNetworkPatterns
});
createEntityContextMenu('Mark as anti-trans', 'mark-transphobic');
createEntityContextMenu('Mark as t-friendly', 'mark-t-friendly');
createEntityContextMenu('Clear', 'mark-none');
createSystemContextMenu('---', 'separator', true);
createSystemContextMenu('Settings', 'options');
createSystemContextMenu('Help', 'help');
var uncommittedResponse: ShinigamiEyesSubmission = null;

View File

@ -43,5 +43,5 @@ type LabelMap = { [identifier: string]: LabelKind };
interface ShinigamiEyesMessage extends ShinigamiEyesSubmission, ShinigamiEyesCommand {
}
type ContextMenuCommand = 'mark-t-friendly' | 'mark-transphobic' | 'mark-none' | 'help' | 'options';
type ContextMenuCommand = 'mark-t-friendly' | 'mark-transphobic' | 'mark-none' | 'help' | 'options' | 'separator';
type BadIdentifierReason = 'SN' | 'AR';

View File

@ -27,8 +27,10 @@ declare type Browser = {
create(options: {
id?: string
title?: string
contexts?: 'link'[]
enabled?: boolean
contexts?: ('all' | 'page' | 'frame' | 'selection' | 'link' | 'editable' | 'image' | 'video' | 'audio' | 'launcher' | 'browser_action' | 'page_action' | 'action')[]
targetUrlPatterns?: string[]
documentUrlPatterns?: string[]
type?: 'normal' | 'separator'
}): void
onClicked: {