From 4c7635514ac3b379e8d5e88d727a186025609440 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 13 Sep 2020 11:44:42 -0400 Subject: [PATCH] Fine tuning changes to click-to-subscribe code Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/763#issuecomment-691682195 Additionally, enable an existing subscription when subscribing again to it. --- src/js/messaging.js | 6 +----- src/js/scriptlets/subscriber.js | 33 +++++++++++++++++++++------------ src/js/storage.js | 5 ++++- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index 60a086cf0..e6f623028 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -1590,10 +1590,6 @@ const onMessage = function(request, sender, callback) { let response; switch ( request.what ) { - case 'applyFilterListSelection': - response = µb.applyFilterListSelection(request); - break; - case 'inlinescriptFound': if ( µb.logger.enabled && pageStore !== null ) { const fctxt = µb.filteringContext.duplicate(); @@ -1624,7 +1620,7 @@ const onMessage = function(request, sender, callback) { case 'subscribeTo': const url = encodeURIComponent(request.location); const title = encodeURIComponent(request.title); - const hash = µb.availableFilterLists[request.location] !== undefined + const hash = µb.selectedFilterLists.indexOf(request.location) !== -1 ? '#subscribed' : ''; vAPI.tabs.open({ diff --git a/src/js/scriptlets/subscriber.js b/src/js/scriptlets/subscriber.js index 627bf68af..5b1f83b49 100644 --- a/src/js/scriptlets/subscriber.js +++ b/src/js/scriptlets/subscriber.js @@ -55,18 +55,27 @@ const onMaybeSubscriptionLinkClicked = function(ev) { return; } - const href = target.href || ''; - const matches = /^(?:abp|ubo):\/*subscribe\/*\?location=([^&]+).*title=([^&]+)/.exec(href); - if ( matches === null ) { return; } - - vAPI.messaging.send('scriptlets', { - what: 'subscribeTo', - location: decodeURIComponent(matches[1]), - title: decodeURIComponent(matches[2]), - }); - - ev.stopPropagation(); - ev.preventDefault(); + const subscribeURL = new URL('about:blank'); + try { + subscribeURL.href = target.href; + if ( + /^(abp|ubo):$/.test(subscribeURL.protocol) === false && + subscribeURL.hostname !== 'subscribe.adblockplus.org' + ) { + return; + } + const location = subscribeURL.searchParams.get('location') || ''; + const title = subscribeURL.searchParams.get('title') || ''; + if ( location === '' || title === '' ) { return; } + vAPI.messaging.send('scriptlets', { + what: 'subscribeTo', + location: decodeURIComponent(location), + title: decodeURIComponent(title), + }); + ev.stopPropagation(); + ev.preventDefault(); + } catch (_) { + } }; document.addEventListener('click', onMaybeSubscriptionLinkClicked); diff --git a/src/js/storage.js b/src/js/storage.js index 3bbfaf103..75921f92d 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -326,7 +326,10 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { const importedSet = new Set(this.listKeysFromCustomFilterLists(externalLists)); const toImportSet = new Set(this.listKeysFromCustomFilterLists(details.toImport)); for ( const urlKey of toImportSet ) { - if ( importedSet.has(urlKey) ) { continue; } + if ( importedSet.has(urlKey) ) { + selectedListKeySet.add(urlKey); + continue; + } const assetKey = assetKeyFromURL(urlKey); if ( assetKey === urlKey ) { importedSet.add(urlKey);