diff --git a/src/js/epicker-ui.js b/src/js/epicker-ui.js index abb9d86edfe50..2242ec538c761 100644 --- a/src/js/epicker-ui.js +++ b/src/js/epicker-ui.js @@ -53,9 +53,9 @@ const epickerId = (( ) => { })(); if ( epickerId === null ) { return; } +const docURL = new URL(vAPI.getURL('')); + let epickerConnectionId; -let filterHostname = ''; -let filterOrigin = ''; let resultsetOpt; let netFilterCandidates = []; @@ -102,9 +102,11 @@ const renderRange = function(id, value, invert = false) { const userFilterFromCandidate = function(filter) { if ( filter === '' || filter === '!' ) { return; } + const hn = vAPI.hostnameFromURI(docURL.href); + // Cosmetic filter? if ( filter.startsWith('##') ) { - return filterHostname + filter; + return hn + filter; } // Assume net filter @@ -112,7 +114,7 @@ const userFilterFromCandidate = function(filter) { // If no domain included in filter, we need domain option if ( filter.startsWith('||') === false ) { - opts.push(`domain=${filterHostname}`); + opts.push(`domain=${hn}`); } if ( resultsetOpt !== undefined ) { @@ -416,8 +418,7 @@ const onCreateClicked = function() { what: 'createUserFilter', autoComment: true, filters: filter, - origin: filterOrigin, - pageDomain: filterHostname, + docURL: docURL.href, killCache: /^#[$?]?#/.test(candidate) === false, }); } @@ -672,13 +673,7 @@ const showDialog = function(details) { } cosmeticFilterCandidates = cosmeticFilters; - // https://github.com/gorhill/uBlock/issues/738 - // Trim dots. - filterHostname = details.hostname; - if ( filterHostname.slice(-1) === '.' ) { - filterHostname = filterHostname.slice(0, -1); - } - filterOrigin = details.origin; + docURL.href = details.url; populateCandidates(netFilters, '#netFilters'); populateCandidates(cosmeticFilters, '#cosmeticFilters'); diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index 939ff672095d5..cfd9ed4be2450 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -1263,13 +1263,16 @@ const reloadTab = function(ev) { // Avoid duplicates if ( createdStaticFilters.hasOwnProperty(value) ) { return; } createdStaticFilters[value] = true; + // https://github.com/uBlockOrigin/uBlock-issues/issues/1281#issuecomment-704217175 + // TODO: + // Figure a way to use the actual document URL. Currently using + // a synthetic URL derived from the document hostname. if ( value !== '' ) { messaging.send('loggerUI', { what: 'createUserFilter', autoComment: true, filters: value, - origin: targetPageDomain, - pageDomain: targetPageDomain, + docURL: `https://${targetFrameHostname}/`, }); } updateWidgets(); @@ -1872,8 +1875,6 @@ const reloadTab = function(ev) { ); })(); -// https://www.youtube.com/watch?v=XyNYrmmdUd4 - /******************************************************************************/ /******************************************************************************/ diff --git a/src/js/scriptlets/epicker.js b/src/js/scriptlets/epicker.js index 311c226f312ba..c249de68c688c 100644 --- a/src/js/scriptlets/epicker.js +++ b/src/js/scriptlets/epicker.js @@ -843,8 +843,7 @@ const onOptmizeCandidate = function(details) { const showDialog = function(options) { vAPI.MessagingConnection.sendTo(epickerConnectionId, { what: 'showDialog', - hostname: self.location.hostname, - origin: self.location.origin, + url: self.location.href, netFilters: netFilterCandidates, cosmeticFilters: cosmeticFilterCandidates, filter: bestCandidateFilter, diff --git a/src/js/storage.js b/src/js/storage.js index 79ea86051e49e..4fc5457de7590 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -399,12 +399,15 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { // Date in YYYY-MM-DD format - https://stackoverflow.com/a/50130338 const ISO8061Date = new Date(d.getTime() + (d.getTimezoneOffset()*60000)).toISOString().split('T')[0]; + const url = new URL(options.docURL); comment = '! ' + this.hiddenSettings.autoCommentFilterTemplate .replace('{{date}}', ISO8061Date) .replace('{{time}}', d.toLocaleTimeString()) - .replace('{{origin}}', options.origin); + .replace('{{hostname}}', url.hostname) + .replace('{{origin}}', url.origin) + .replace('{{url}}', url.href); } const details = await this.loadUserFilters(); @@ -414,10 +417,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { // from the last comment found in the user filter list. if ( comment !== '' ) { const pos = details.content.lastIndexOf(comment); - if ( - pos === -1 || - details.content.indexOf('\n!', pos + 1) !== -1 - ) { + if ( pos === -1 || details.content.indexOf('\n!', pos + 1) !== -1 ) { filters = '\n' + comment + '\n' + filters; } } @@ -462,7 +462,10 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { µBlock.createUserFilters = function(details) { this.appendUserFilters(details.filters, details); // https://github.com/gorhill/uBlock/issues/1786 - this.cosmeticFilteringEngine.removeFromSelectorCache(details.pageDomain); + if ( details.docURL === undefined ) { return; } + this.cosmeticFilteringEngine.removeFromSelectorCache( + vAPI.hostnameFromURI(details.docURL) + ); }; /******************************************************************************/