Skip to content

Commit

Permalink
Allow filter list subscription through context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed May 15, 2021
1 parent a5f6dc5 commit 0010945
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,10 @@
"message": "Block element in frame...",
"description": "An entry in the browser's contextual menu"
},
"contextMenuSubscribeToList": {
"message": "Subscribe to filter list...",
"description": "An entry in the browser's contextual menu"
},
"contextMenuTemporarilyAllowLargeMediaElements": {
"message": "Temporarily allow large media elements",
"description": "A context menu entry, present when large media elements have been blocked on the current site"
Expand Down
36 changes: 36 additions & 0 deletions src/js/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ const onBlockElementInFrame = function(details, tab) {

/******************************************************************************/

const onSubscribeToList = function(details) {
let parsedURL;
try {
parsedURL = new URL(details.linkUrl);
}
catch(ex) {
}
if ( parsedURL instanceof URL === false ) { return; }
const url = parsedURL.searchParams.get('location');
if ( url === null ) { return; }
const title = parsedURL.searchParams.get('title') || '?';
const hash = µBlock.selectedFilterLists.indexOf(parsedURL) !== -1
? '#subscribed'
: '';
vAPI.tabs.open({
url:
`/asset-viewer.html` +
`?url=${encodeURIComponent(url)}` +
`&title=${encodeURIComponent(title)}` +
`&subscribe=1${hash}`,
select: true,
});
};

/******************************************************************************/

const onTemporarilyAllowLargeMediaElements = function(details, tab) {
if ( tab === undefined ) { return; }
let pageStore = µBlock.pageStoreFromTabId(tab.id);
Expand All @@ -88,6 +114,9 @@ const onEntryClicked = function(details, tab) {
if ( details.menuItemId === 'uBlock0-blockElementInFrame' ) {
return onBlockElementInFrame(details, tab);
}
if ( details.menuItemId === 'uBlock0-subscribeToList' ) {
return onSubscribeToList(details);
}
if ( details.menuItemId === 'uBlock0-temporarilyAllowLargeMediaElements' ) {
return onTemporarilyAllowLargeMediaElements(details, tab);
}
Expand All @@ -106,6 +135,12 @@ const menuEntries = {
title: vAPI.i18n('contextMenuBlockElementInFrame'),
contexts: ['frame'],
},
subscribeToList: {
id: 'uBlock0-subscribeToList',
title: vAPI.i18n('contextMenuSubscribeToList'),
contexts: ['link'],
targetUrlPatterns: [ 'abp:*' ],
},
temporarilyAllowLargeMediaElements: {
id: 'uBlock0-temporarilyAllowLargeMediaElements',
title: vAPI.i18n('contextMenuTemporarilyAllowLargeMediaElements'),
Expand Down Expand Up @@ -134,6 +169,7 @@ const update = function(tabId = undefined) {
if ( newBits & 0x01 ) {
usedEntries.push(menuEntries.blockElement);
usedEntries.push(menuEntries.blockElementInFrame);
usedEntries.push(menuEntries.subscribeToList);
}
if ( newBits & 0x02 ) {
usedEntries.push(menuEntries.temporarilyAllowLargeMediaElements);
Expand Down

0 comments on commit 0010945

Please sign in to comment.