mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01: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:
parent
59f491c500
commit
4c7635514a
@ -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({
|
||||
|
@ -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; }
|
||||
|
||||
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(matches[1]),
|
||||
title: decodeURIComponent(matches[2]),
|
||||
location: decodeURIComponent(location),
|
||||
title: decodeURIComponent(title),
|
||||
});
|
||||
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
} catch (_) {
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('click', onMaybeSubscriptionLinkClicked);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user