2021-10-12 17:19:56 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
uBlock Origin - a browser extension to block requests.
|
|
|
|
Copyright (C) 2014-present Raymond Hill
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
2021-10-13 17:18:23 +02:00
|
|
|
/* global CodeMirror, uBlockDashboard, uDom */
|
2021-10-12 17:19:56 +02:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-13 17:18:23 +02:00
|
|
|
let supportData;
|
|
|
|
|
2021-10-15 20:50:34 +02:00
|
|
|
const uselessKeys = [
|
2021-11-11 18:49:55 +01:00
|
|
|
'modifiedHiddenSettings.benchmarkDatasetURL',
|
2021-11-27 17:58:32 +01:00
|
|
|
'modifiedHiddenSettings.consoleLogLevel',
|
|
|
|
'modifiedHiddenSettings.uiPopupConfig',
|
2021-11-26 18:23:18 +01:00
|
|
|
'modifiedUserSettings.alwaysDetachLogger',
|
2021-12-04 16:44:57 +01:00
|
|
|
'modifiedUserSettings.firewallPaneMinimized',
|
2021-10-15 20:50:34 +02:00
|
|
|
'modifiedUserSettings.externalLists',
|
|
|
|
'modifiedUserSettings.importedLists',
|
2021-12-04 16:44:57 +01:00
|
|
|
'modifiedUserSettings.popupPanelSections',
|
2021-10-15 20:50:34 +02:00
|
|
|
];
|
|
|
|
|
2021-10-13 17:18:23 +02:00
|
|
|
const sensitiveValues = [
|
2021-11-11 20:06:59 +01:00
|
|
|
'filterset (user)',
|
2021-10-15 20:50:34 +02:00
|
|
|
'modifiedUserSettings.popupPanelSections',
|
2021-10-13 17:18:23 +02:00
|
|
|
'modifiedHiddenSettings.userResourcesLocation',
|
|
|
|
'trustedset.added',
|
|
|
|
'hostRuleset.added',
|
|
|
|
'switchRuleset.added',
|
|
|
|
'urlRuleset.added',
|
|
|
|
];
|
|
|
|
|
|
|
|
const sensitiveKeys = [
|
|
|
|
'listset.added',
|
|
|
|
];
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-15 20:50:34 +02:00
|
|
|
function removeKey(data, prop) {
|
|
|
|
if ( data instanceof Object === false ) { return; }
|
|
|
|
const pos = prop.indexOf('.');
|
|
|
|
if ( pos !== -1 ) {
|
|
|
|
const key = prop.slice(0, pos);
|
|
|
|
return removeKey(data[key], prop.slice(pos + 1));
|
|
|
|
}
|
|
|
|
delete data[prop];
|
|
|
|
}
|
|
|
|
|
2021-10-13 17:18:23 +02:00
|
|
|
function redactValue(data, prop) {
|
|
|
|
if ( data instanceof Object === false ) { return; }
|
|
|
|
const pos = prop.indexOf('.');
|
|
|
|
if ( pos !== -1 ) {
|
|
|
|
return redactValue(data[prop.slice(0, pos)], prop.slice(pos + 1));
|
|
|
|
}
|
|
|
|
let value = data[prop];
|
|
|
|
if ( value === undefined ) { return; }
|
|
|
|
if ( Array.isArray(value) ) {
|
2021-10-15 20:50:34 +02:00
|
|
|
if ( value.length !== 0 ) {
|
|
|
|
value = `[array of ${value.length} redacted]`;
|
|
|
|
} else {
|
|
|
|
value = '[empty]';
|
|
|
|
}
|
2021-10-13 17:18:23 +02:00
|
|
|
} else {
|
|
|
|
value = '[redacted]';
|
|
|
|
}
|
|
|
|
data[prop] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function redactKeys(data, prop) {
|
|
|
|
if ( data instanceof Object === false ) { return; }
|
|
|
|
const pos = prop.indexOf('.');
|
|
|
|
if ( pos !== -1 ) {
|
|
|
|
return redactKeys(data[prop.slice(0, pos)], prop.slice(pos + 1));
|
|
|
|
}
|
|
|
|
const obj = data[prop];
|
|
|
|
if ( obj instanceof Object === false ) { return; }
|
|
|
|
let count = 1;
|
|
|
|
for ( const key in obj ) {
|
|
|
|
if ( key.startsWith('file://') === false ) { continue; }
|
|
|
|
const newkey = `[list name ${count} redacted]`;
|
|
|
|
obj[newkey] = obj[key];
|
|
|
|
obj[key] = undefined;
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 20:50:34 +02:00
|
|
|
function patchEmptiness(data, prop) {
|
|
|
|
const entry = data[prop];
|
|
|
|
if ( Array.isArray(entry) && entry.length === 0 ) {
|
|
|
|
data[prop] = '[empty]';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( entry instanceof Object === false ) { return; }
|
|
|
|
if ( Object.keys(entry).length === 0 ) {
|
|
|
|
data[prop] = '[none]';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for ( const key in entry ) {
|
|
|
|
patchEmptiness(entry, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 18:49:55 +01:00
|
|
|
function configToMarkdown(collapse = false) {
|
2021-11-20 15:38:00 +01:00
|
|
|
const text = cmEditor.getValue().trim();
|
2021-11-11 18:49:55 +01:00
|
|
|
return collapse
|
|
|
|
? '<details>\n\n```yaml\n' + text + '\n```\n</details>'
|
|
|
|
: '```yaml\n' + text + '\n```\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDetailsToReportURL(id, collapse = false) {
|
2021-10-15 20:50:34 +02:00
|
|
|
const elem = uDom.nodeFromId(id);
|
|
|
|
const url = new URL(elem.getAttribute('data-url'));
|
2021-11-11 18:49:55 +01:00
|
|
|
url.searchParams.set('configuration', configToMarkdown(collapse));
|
2021-10-15 20:50:34 +02:00
|
|
|
elem.setAttribute('data-url', url);
|
|
|
|
}
|
|
|
|
|
2021-10-13 17:18:23 +02:00
|
|
|
function showData() {
|
|
|
|
const shownData = JSON.parse(JSON.stringify(supportData));
|
2021-10-15 20:50:34 +02:00
|
|
|
uselessKeys.forEach(prop => { removeKey(shownData, prop); });
|
2021-11-21 13:53:36 +01:00
|
|
|
const redacted = true;
|
2021-11-11 18:49:55 +01:00
|
|
|
if ( redacted ) {
|
2021-10-13 17:18:23 +02:00
|
|
|
sensitiveValues.forEach(prop => { redactValue(shownData, prop); });
|
|
|
|
sensitiveKeys.forEach(prop => { redactKeys(shownData, prop); });
|
2021-10-15 20:50:34 +02:00
|
|
|
}
|
|
|
|
for ( const prop in shownData ) {
|
|
|
|
patchEmptiness(shownData, prop);
|
2021-10-13 17:18:23 +02:00
|
|
|
}
|
2021-11-27 17:58:32 +01:00
|
|
|
if ( reportedPage !== null ) {
|
|
|
|
shownData.popupPanel = reportedPage.popupPanel;
|
|
|
|
}
|
2021-10-14 14:54:38 +02:00
|
|
|
const text = JSON.stringify(shownData, null, 2)
|
|
|
|
.split('\n')
|
|
|
|
.slice(1, -1)
|
|
|
|
.map(v => {
|
|
|
|
return v
|
2021-11-27 17:58:32 +01:00
|
|
|
.replace(/^( *?) "/, '$1')
|
|
|
|
.replace(/^( *.*[^\\])(?:": "|": \{$|": \[$|": )/, '$1: ')
|
|
|
|
.replace(/(?:",?|\},?|\],?|,)$/, '');
|
2021-10-14 14:54:38 +02:00
|
|
|
})
|
|
|
|
.filter(v => v.trim() !== '')
|
2021-10-15 20:50:34 +02:00
|
|
|
.join('\n') + '\n';
|
|
|
|
|
|
|
|
cmEditor.setValue(text);
|
2021-10-14 14:54:38 +02:00
|
|
|
cmEditor.clearHistory();
|
2021-10-15 20:50:34 +02:00
|
|
|
|
2021-11-27 17:58:32 +01:00
|
|
|
addDetailsToReportURL('filterReport', true);
|
|
|
|
addDetailsToReportURL('bugReport', true);
|
2021-11-11 18:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-11-27 17:58:32 +01:00
|
|
|
const reportedPage = (( ) => {
|
2021-11-11 18:49:55 +01:00
|
|
|
const url = new URL(window.location.href);
|
|
|
|
try {
|
2021-11-27 17:58:32 +01:00
|
|
|
const pageURL = url.searchParams.get('pageURL');
|
|
|
|
if ( pageURL === null ) { return null; }
|
|
|
|
const parsedURL = new URL(pageURL);
|
2021-11-26 18:23:18 +01:00
|
|
|
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);
|
|
|
|
}
|
2021-11-27 17:58:32 +01:00
|
|
|
document.body.classList.add('filterIssue');
|
|
|
|
return {
|
2021-11-28 13:47:16 +01:00
|
|
|
hostname: parsedURL.hostname.replace(/^(m|mobile|www)\./, ''),
|
2021-11-27 17:58:32 +01:00
|
|
|
popupPanel: JSON.parse(url.searchParams.get('popupPanel')),
|
|
|
|
};
|
2021-11-11 18:49:55 +01:00
|
|
|
} catch(ex) {
|
|
|
|
}
|
2021-11-27 17:58:32 +01:00
|
|
|
return null;
|
2021-11-11 18:49:55 +01:00
|
|
|
})();
|
|
|
|
|
|
|
|
function reportSpecificFilterType() {
|
2021-11-26 18:23:18 +01:00
|
|
|
return document.querySelector('select[name="type"]').value;
|
2021-11-11 18:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function reportSpecificFilterIssue(ev) {
|
2021-11-12 15:11:28 +01:00
|
|
|
const githubURL = new URL('https://github.com/uBlockOrigin/uAssets/issues/new?template=specific_report_from_ubo.yml');
|
|
|
|
const issueType = reportSpecificFilterType();
|
2021-11-27 17:58:32 +01:00
|
|
|
let title = `${reportedPage.hostname}: ${issueType}`;
|
2021-11-16 14:11:04 +01:00
|
|
|
if ( document.getElementById('isNSFW').checked ) {
|
|
|
|
title = `[nsfw] ${title}`;
|
|
|
|
}
|
|
|
|
githubURL.searchParams.set('title', title);
|
2021-11-26 18:23:18 +01:00
|
|
|
githubURL.searchParams.set(
|
|
|
|
'url_address_of_the_web_page', '`' +
|
|
|
|
document.querySelector('select[name="url"]').value +
|
|
|
|
'`'
|
|
|
|
);
|
2021-11-12 15:11:28 +01:00
|
|
|
githubURL.searchParams.set('category', issueType);
|
2021-11-20 15:38:00 +01:00
|
|
|
githubURL.searchParams.set('configuration', configToMarkdown(true));
|
2021-11-11 18:49:55 +01:00
|
|
|
vAPI.messaging.send('default', {
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: { url: githubURL.href, select: true, index: -1 },
|
|
|
|
});
|
|
|
|
ev.preventDefault();
|
2021-10-13 17:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const cmEditor = new CodeMirror(document.getElementById('supportData'), {
|
|
|
|
autofocus: true,
|
2021-11-11 18:49:55 +01:00
|
|
|
readOnly: true,
|
2021-10-13 17:18:23 +02:00
|
|
|
styleActiveLine: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-12 17:19:56 +02:00
|
|
|
(async ( ) => {
|
2021-10-13 17:18:23 +02:00
|
|
|
supportData = await vAPI.messaging.send('dashboard', {
|
|
|
|
what: 'getSupportData',
|
2021-10-12 17:19:56 +02:00
|
|
|
});
|
|
|
|
|
2021-10-13 17:18:23 +02:00
|
|
|
showData();
|
|
|
|
|
2021-10-14 14:54:38 +02:00
|
|
|
uDom('[data-url]').on('click', ev => {
|
2021-10-15 20:50:34 +02:00
|
|
|
const elem = ev.target.closest('[data-url]');
|
|
|
|
const url = elem.getAttribute('data-url');
|
2021-10-13 17:18:23 +02:00
|
|
|
if ( typeof url !== 'string' || url === '' ) { return; }
|
|
|
|
vAPI.messaging.send('default', {
|
|
|
|
what: 'gotoURL',
|
2021-11-27 17:58:32 +01:00
|
|
|
details: { url, select: true, index: -1, shiftKey: ev.shiftKey },
|
2021-10-13 17:18:23 +02:00
|
|
|
});
|
2021-10-14 14:54:38 +02:00
|
|
|
ev.preventDefault();
|
2021-10-12 17:19:56 +02:00
|
|
|
});
|
|
|
|
|
2021-11-27 17:58:32 +01:00
|
|
|
if ( reportedPage !== null ) {
|
|
|
|
uDom('[data-i18n="supportReportSpecificButton"]').on('click', ev => {
|
|
|
|
reportSpecificFilterIssue(ev);
|
|
|
|
});
|
2021-11-11 18:49:55 +01:00
|
|
|
|
2021-11-27 17:58:32 +01:00
|
|
|
uDom('[data-i18n="supportFindSpecificButton"]').on('click', ev => {
|
|
|
|
const url = new URL('https://github.com/uBlockOrigin/uAssets/issues');
|
2021-11-28 13:47:16 +01:00
|
|
|
url.searchParams.set('q', `is:issue sort:updated-desc "${reportedPage.hostname}" in:title`);
|
2021-11-27 17:58:32 +01:00
|
|
|
vAPI.messaging.send('default', {
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: { url: url.href, select: true, index: -1 },
|
|
|
|
});
|
|
|
|
ev.preventDefault();
|
2021-11-11 18:49:55 +01:00
|
|
|
});
|
2021-11-27 17:58:32 +01:00
|
|
|
}
|
2021-11-11 18:49:55 +01:00
|
|
|
|
2021-10-13 17:18:23 +02:00
|
|
|
uDom('#selectAllButton').on('click', ( ) => {
|
2021-10-14 18:00:24 +02:00
|
|
|
cmEditor.focus();
|
2021-10-13 17:18:23 +02:00
|
|
|
cmEditor.execCommand('selectAll');
|
|
|
|
});
|
2021-10-12 17:19:56 +02:00
|
|
|
})();
|