Skip to content

Commit

Permalink
UX of add slur and Crowdsource in single button
Browse files Browse the repository at this point in the history
Add Slur to Uli: Words added through this option are redacted from your local browser
Crowdsource Slur Word: Words added through this option are submitted to the list of slurs on the server for anyone to see.
integrated both the button in single button with both functionality
  • Loading branch information
anshuman-rai-27 committed Oct 27, 2023
1 parent c54490b commit 646a74a
Showing 1 changed file with 76 additions and 39 deletions.
115 changes: 76 additions & 39 deletions browser-extension/plugin/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,90 @@ if (userBrowser === 'firefox') {
}
console.log(contextMenus);

// contextMenus.create(
// {
// id: 'add-slur',
// title: 'Add Slur to Uli',
// contexts: ['selection']
// },
// () => {
// console.log('context menu created');
// }
// );
// contextMenus.create(
// {
// id: 'add-crowdsource-slur',
// title: 'Crowdsource Slur Word',
// contexts: ['selection']
// },
// () => {
// console.log('crowdsource context menu created');
// }
// );

// contextMenus.onClicked.addListener(async (info, tab) => {
// switch (info.menuItemId) {
// case 'add-slur':
// console.log('slur added');
// tabs.sendMessage(
// tab.id,
// { type: 'SLUR_ADDED', slur: info.selectionText },
// function (response) {
// console.log(response);
// }
// );
// break;
// case 'add-crowdsource-slur':
// console.log('Crowdsource slur word added');
// tabs.sendMessage(
// tab.id,
// {
// type: 'CROWDSOURCE_SLUR_WORD',
// crowdsourcedSlur: info.selectionText
// },
// function (response) {
// console.log(response);
// }
// );
// break;
// default:
// console('unexpected action');
// }
// });
contextMenus.create(
{
id: 'add-slur',
title: 'Add Slur to Uli',
contexts: ['selection']
},
() => {
console.log('context menu created');
}
);
contextMenus.create(
{
id: 'add-crowdsource-slur',
title: 'Crowdsource Slur Word',
id: 'add-slur-crowdsource',
title: 'Add Slur to Uli and Crowdsource',
contexts: ['selection']
},
() => {
console.log('crowdsource context menu created');
console.log('Unified context menu created');
}
);

contextMenus.onClicked.addListener(async (info, tab) => {
switch (info.menuItemId) {
case 'add-slur':
console.log('slur added');
tabs.sendMessage(
tab.id,
{ type: 'SLUR_ADDED', slur: info.selectionText },
function (response) {
console.log(response);
}
);
break;
case 'add-crowdsource-slur':
console.log('Crowdsource slur word added');
tabs.sendMessage(
tab.id,
{
type: 'CROWDSOURCE_SLUR_WORD',
crowdsourcedSlur: info.selectionText
},
function (response) {
console.log(response);
}
);
break;
default:
console('unexpected action');
if (info.menuItemId === 'add-slur-crowdsource') {
console.log('Slur added and Crowdsourced');
tabs.sendMessage(
tab.id,
{ type: 'SLUR_ADDED', slur: info.selectionText },
function (response) {
console.log(response);
}
);

tabs.sendMessage(
tab.id,
{
type: 'CROWDSOURCE_SLUR_WORD',
crowdsourcedSlur: info.selectionText
},
function (response) {
console.log(response);
}
);
} else {
console('unexpected action');
}
});

0 comments on commit 646a74a

Please sign in to comment.