From 74d1f902647b98ad9a1c9992cad6c86a8b8d9a29 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 26 Nov 2021 12:23:18 -0500 Subject: [PATCH] Allow reporter to select a choice of URLs to report Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1836 The URL to report can now be picked from a list of related URLs in order to allow the reporter to publish edited version of the reported URL. Additionally, the hash, user name, and password which could be present in a reported URL are always removed. --- src/css/support.css | 8 ++------ src/js/support.js | 49 ++++++++++++++++++++++++++++++--------------- src/support.html | 6 ++++-- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/css/support.css b/src/css/support.css index 9344dc0af..9b97493e4 100644 --- a/src/css/support.css +++ b/src/css/support.css @@ -25,20 +25,16 @@ body { margin-top: 0; } - .e > .supportEntry { flex-direction: column; } .e > .supportEntry > div:not(:first-of-type) { margin-top: 1em; } -.e > .supportEntry *:is(input,select) { +.e > .supportEntry select { padding: var(--default-gap-xxsmall); } -.e > .supportEntry input[type="url"] { - width: 100%; - } -.e > .supportEntry *:is(input,select) { +.e > .supportEntry select { max-width: calc(100% - 1em); } body:not(.filterIssue) .body > div.e { diff --git a/src/js/support.js b/src/js/support.js index 0edd877dc..e67ea1032 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -29,6 +29,7 @@ let supportData; const uselessKeys = [ 'modifiedHiddenSettings.benchmarkDatasetURL', + 'modifiedUserSettings.alwaysDetachLogger', 'modifiedUserSettings.popupPanelSections', 'modifiedUserSettings.externalLists', 'modifiedUserSettings.importedLists', @@ -135,19 +136,18 @@ function showData() { // If the report is for a specific site, report per-site switches which // are triggered on the reported site. if ( - reportURL !== null && + reportHostname !== '' && shownData.switchRuleset instanceof Object && Array.isArray(shownData.switchRuleset.added) ) { - const hostname = reportURL.hostname; const added = []; const triggered = []; for ( const rule of shownData.switchRuleset.added ) { const match = /^[^:]+:\s+(\S+)/.exec(rule); if ( match[1] === '*' || - hostname === match[1] || - hostname.endsWith(`.${match[1]}`) + reportHostname === match[1] || + reportHostname.endsWith(`.${match[1]}`) ) { triggered.push(rule); } else { @@ -187,37 +187,54 @@ function showData() { /******************************************************************************/ -const reportURL = (( ) => { +const reportHostname = (( ) => { const url = new URL(window.location.href); try { const reportURL = url.searchParams.get('reportURL'); + const parsedURL = new URL(reportURL); + parsedURL.username = ''; + parsedURL.password = ''; + parsedURL.hash = ''; + const select = document.querySelector('select[name="url"]'); + select.options[0].textContent = parsedURL.href; + if ( parsedURL.search !== '' ) { + const option = document.createElement('option'); + parsedURL.search = ''; + option.textContent = parsedURL.href; + select.append(option); + } + if ( parsedURL.pathname !== '/' ) { + const option = document.createElement('option'); + parsedURL.pathname = ''; + option.textContent = parsedURL.href; + select.append(option); + } if ( reportURL !== null ) { document.body.classList.add('filterIssue'); } - document.querySelector('[data-i18n="supportS6URL"] ~ input').value = reportURL; - return new URL(reportURL); + return parsedURL.hostname.replace(/^www\./, ''); } catch(ex) { } - return null; + return ''; })(); -function reportSpecificFilterHostname() { - return reportURL.hostname.replace(/^www\./, ''); -} - function reportSpecificFilterType() { - return document.querySelector('[data-i18n="supportS6Select1"] ~ select').value; + return document.querySelector('select[name="type"]').value; } function reportSpecificFilterIssue(ev) { const githubURL = new URL('https://github.com/uBlockOrigin/uAssets/issues/new?template=specific_report_from_ubo.yml'); const issueType = reportSpecificFilterType(); - let title = `${reportSpecificFilterHostname()}: ${issueType}`; + let title = `${reportHostname}: ${issueType}`; if ( document.getElementById('isNSFW').checked ) { title = `[nsfw] ${title}`; } githubURL.searchParams.set('title', title); - githubURL.searchParams.set('url_address_of_the_web_page', '`' + reportURL.href + '`'); + githubURL.searchParams.set( + 'url_address_of_the_web_page', '`' + + document.querySelector('select[name="url"]').value + + '`' + ); githubURL.searchParams.set('category', issueType); githubURL.searchParams.set('configuration', configToMarkdown(true)); vAPI.messaging.send('default', { @@ -263,7 +280,7 @@ uBlockDashboard.patchCodeMirrorEditor(cmEditor); uDom('[data-i18n="supportFindSpecificButton"]').on('click', ev => { const url = new URL('https://github.com/uBlockOrigin/uAssets/issues'); - url.searchParams.set('q', `is:issue "${reportSpecificFilterHostname()}" in:title`); + url.searchParams.set('q', `is:issue "${reportHostname}" in:title`); vAPI.messaging.send('default', { what: 'gotoURL', details: { url: url.href, select: true, index: -1 }, diff --git a/src/support.html b/src/support.html index d602cb204..e9c9b40de 100644 --- a/src/support.html +++ b/src/support.html @@ -75,10 +75,12 @@


- +


-