1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-14 23:12:28 +02:00

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.
This commit is contained in:
Raymond Hill 2020-09-13 11:44:42 -04:00
parent 59f491c500
commit 4c7635514a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 26 additions and 18 deletions

View File

@ -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({

View File

@ -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);

View File

@ -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);