2021-10-12 09:19:56 -06: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 09:18:23 -06:00
|
|
|
/* global CodeMirror, uBlockDashboard, uDom */
|
2021-10-12 09:19:56 -06:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
let supportData;
|
|
|
|
|
2021-10-15 12:50:34 -06:00
|
|
|
const uselessKeys = [
|
|
|
|
'modifiedUserSettings.popupPanelSections',
|
|
|
|
'modifiedUserSettings.externalLists',
|
|
|
|
'modifiedUserSettings.importedLists',
|
|
|
|
];
|
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
const sensitiveValues = [
|
|
|
|
'filterset',
|
2021-10-15 12:50:34 -06:00
|
|
|
'modifiedUserSettings.popupPanelSections',
|
2021-10-13 09:18:23 -06:00
|
|
|
'modifiedHiddenSettings.userResourcesLocation',
|
|
|
|
'trustedset.added',
|
|
|
|
'hostRuleset.added',
|
|
|
|
'switchRuleset.added',
|
|
|
|
'urlRuleset.added',
|
|
|
|
];
|
|
|
|
|
|
|
|
const sensitiveKeys = [
|
|
|
|
'listset.added',
|
|
|
|
];
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-15 12:50:34 -06: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 09:18:23 -06: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 12:50:34 -06:00
|
|
|
if ( value.length !== 0 ) {
|
|
|
|
value = `[array of ${value.length} redacted]`;
|
|
|
|
} else {
|
|
|
|
value = '[empty]';
|
|
|
|
}
|
2021-10-13 09:18:23 -06: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 12:50:34 -06: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDetailsToReportURL(id) {
|
2021-10-16 06:43:31 -06:00
|
|
|
const text = cmEditor.getValue().replace(/^ /gm, '');
|
2021-10-15 12:50:34 -06:00
|
|
|
const elem = uDom.nodeFromId(id);
|
|
|
|
const url = new URL(elem.getAttribute('data-url'));
|
2021-10-16 06:43:31 -06:00
|
|
|
url.searchParams.set(
|
|
|
|
'configuration',
|
|
|
|
'<details>\n\n```yaml\n' + text + '\n```\n</details>'
|
|
|
|
);
|
2021-10-15 12:50:34 -06:00
|
|
|
elem.setAttribute('data-url', url);
|
|
|
|
}
|
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
function showData() {
|
|
|
|
const shownData = JSON.parse(JSON.stringify(supportData));
|
2021-10-15 12:50:34 -06:00
|
|
|
uselessKeys.forEach(prop => { removeKey(shownData, prop); });
|
2021-10-13 09:18:23 -06:00
|
|
|
if ( document.body.classList.contains('redacted') ) {
|
|
|
|
sensitiveValues.forEach(prop => { redactValue(shownData, prop); });
|
|
|
|
sensitiveKeys.forEach(prop => { redactKeys(shownData, prop); });
|
2021-10-15 12:50:34 -06:00
|
|
|
}
|
|
|
|
for ( const prop in shownData ) {
|
|
|
|
patchEmptiness(shownData, prop);
|
2021-10-13 09:18:23 -06:00
|
|
|
}
|
2021-10-14 06:54:38 -06:00
|
|
|
const text = JSON.stringify(shownData, null, 2)
|
|
|
|
.split('\n')
|
|
|
|
.slice(1, -1)
|
|
|
|
.map(v => {
|
|
|
|
return v
|
|
|
|
.replace( /^( *)"/, ' $1')
|
|
|
|
.replace( /^( +.*[^\\])(?:": "|": \{$|": \[$|": )/, '$1: ')
|
2021-10-16 06:43:31 -06:00
|
|
|
.replace( /(?:",?|\},?|\],?|,)$/, '');
|
2021-10-14 06:54:38 -06:00
|
|
|
})
|
|
|
|
.filter(v => v.trim() !== '')
|
2021-10-15 12:50:34 -06:00
|
|
|
.join('\n') + '\n';
|
|
|
|
|
|
|
|
cmEditor.setValue(text);
|
2021-10-14 06:54:38 -06:00
|
|
|
cmEditor.clearHistory();
|
2021-10-15 12:50:34 -06:00
|
|
|
|
|
|
|
addDetailsToReportURL('filterReport');
|
|
|
|
addDetailsToReportURL('bugReport');
|
2021-10-13 09:18:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
const cmEditor = new CodeMirror(document.getElementById('supportData'), {
|
|
|
|
autofocus: true,
|
|
|
|
lineWrapping: true,
|
|
|
|
styleActiveLine: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-12 09:19:56 -06:00
|
|
|
(async ( ) => {
|
2021-10-13 09:18:23 -06:00
|
|
|
supportData = await vAPI.messaging.send('dashboard', {
|
|
|
|
what: 'getSupportData',
|
2021-10-12 09:19:56 -06:00
|
|
|
});
|
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
// Remove unnecessary information
|
|
|
|
if ( supportData.modifiedHiddenSettings instanceof Object ) {
|
|
|
|
const o = supportData.modifiedHiddenSettings;
|
|
|
|
o.benchmarkDatasetURL = undefined;
|
|
|
|
}
|
2021-10-12 09:19:56 -06:00
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
showData();
|
|
|
|
|
2021-10-14 06:54:38 -06:00
|
|
|
uDom('[data-url]').on('click', ev => {
|
2021-10-15 12:50:34 -06:00
|
|
|
const elem = ev.target.closest('[data-url]');
|
|
|
|
const url = elem.getAttribute('data-url');
|
2021-10-13 09:18:23 -06:00
|
|
|
if ( typeof url !== 'string' || url === '' ) { return; }
|
|
|
|
vAPI.messaging.send('default', {
|
|
|
|
what: 'gotoURL',
|
2021-10-15 12:50:34 -06:00
|
|
|
details: { url, select: true, index: -1 },
|
2021-10-13 09:18:23 -06:00
|
|
|
});
|
2021-10-14 06:54:38 -06:00
|
|
|
ev.preventDefault();
|
2021-10-12 09:19:56 -06:00
|
|
|
});
|
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
uDom('#redactButton').on('click', ( ) => {
|
|
|
|
document.body.classList.add('redacted');
|
|
|
|
showData();
|
|
|
|
});
|
|
|
|
|
|
|
|
uDom('#unredactButton').on('click', ( ) => {
|
|
|
|
document.body.classList.remove('redacted');
|
|
|
|
showData();
|
|
|
|
});
|
|
|
|
|
|
|
|
uDom('#selectAllButton').on('click', ( ) => {
|
2021-10-14 10:00:24 -06:00
|
|
|
cmEditor.focus();
|
2021-10-13 09:18:23 -06:00
|
|
|
cmEditor.execCommand('selectAll');
|
|
|
|
});
|
2021-10-12 09:19:56 -06:00
|
|
|
})();
|