2021-10-12 09:19:56 -06:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2023-12-04 10:10:34 -07:00
|
|
|
uBlock Origin - a comprehensive, efficient content blocker
|
2021-10-12 09:19:56 -06:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2022-11-12 07:51:22 -07:00
|
|
|
/* global CodeMirror, uBlockDashboard */
|
2021-10-12 09:19:56 -06:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2023-12-01 12:35:28 -07:00
|
|
|
import { onBroadcast } from './broadcast.js';
|
2022-11-12 07:51:22 -07:00
|
|
|
import { dom, qs$ } from './dom.js';
|
|
|
|
|
2021-10-12 09:19:56 -06:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-15 12:50:34 -06:00
|
|
|
const uselessKeys = [
|
2023-04-27 17:16:46 -06:00
|
|
|
'hiddenSettings.benchmarkDatasetURL',
|
|
|
|
'hiddenSettings.blockingProfiles',
|
|
|
|
'hiddenSettings.consoleLogLevel',
|
|
|
|
'hiddenSettings.uiPopupConfig',
|
|
|
|
'userSettings.alwaysDetachLogger',
|
|
|
|
'userSettings.firewallPaneMinimized',
|
|
|
|
'userSettings.externalLists',
|
|
|
|
'userSettings.importedLists',
|
|
|
|
'userSettings.popupPanelSections',
|
|
|
|
'userSettings.uiAccentCustom',
|
|
|
|
'userSettings.uiAccentCustom0',
|
|
|
|
'userSettings.uiTheme',
|
2021-10-15 12:50:34 -06:00
|
|
|
];
|
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
const sensitiveValues = [
|
2021-11-11 12:06:59 -07:00
|
|
|
'filterset (user)',
|
2023-04-27 17:16:46 -06:00
|
|
|
'userSettings.popupPanelSections',
|
|
|
|
'hiddenSettings.userResourcesLocation',
|
2021-10-13 09:18:23 -06:00
|
|
|
'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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 10:49:55 -07:00
|
|
|
function configToMarkdown(collapse = false) {
|
2021-11-20 07:38:00 -07:00
|
|
|
const text = cmEditor.getValue().trim();
|
2021-11-11 10:49:55 -07:00
|
|
|
return collapse
|
|
|
|
? '<details>\n\n```yaml\n' + text + '\n```\n</details>'
|
|
|
|
: '```yaml\n' + text + '\n```\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDetailsToReportURL(id, collapse = false) {
|
2022-11-12 07:51:22 -07:00
|
|
|
const elem = qs$(`#${id}`);
|
|
|
|
const url = new URL(dom.attr(elem, 'data-url'));
|
2021-11-11 10:49:55 -07:00
|
|
|
url.searchParams.set('configuration', configToMarkdown(collapse));
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.attr(elem, 'data-url', url);
|
2021-10-15 12:50:34 -06:00
|
|
|
}
|
|
|
|
|
2023-04-27 17:16:46 -06:00
|
|
|
function renderData(data, depth = 0) {
|
|
|
|
const indent = ' '.repeat(depth);
|
|
|
|
if ( Array.isArray(data) ) {
|
|
|
|
const out = [];
|
|
|
|
for ( const value of data ) {
|
|
|
|
out.push(renderData(value, depth));
|
|
|
|
}
|
|
|
|
return out.join('\n');
|
|
|
|
}
|
2023-04-28 14:59:14 -06:00
|
|
|
if ( typeof data !== 'object' || data === null ) {
|
2023-04-27 17:16:46 -06:00
|
|
|
return `${indent}${data}`;
|
|
|
|
}
|
|
|
|
const out = [];
|
|
|
|
for ( const [ name, value ] of Object.entries(data) ) {
|
2023-04-28 14:59:14 -06:00
|
|
|
if ( typeof value === 'object' && value !== null ) {
|
2023-04-27 17:16:46 -06:00
|
|
|
out.push(`${indent}${name}:`);
|
|
|
|
out.push(renderData(value, depth + 1));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
out.push(`${indent}${name}: ${value}`);
|
|
|
|
}
|
|
|
|
return out.join('\n');
|
|
|
|
}
|
|
|
|
|
2023-04-23 11:45:11 -06:00
|
|
|
async function showSupportData() {
|
|
|
|
const supportData = await vAPI.messaging.send('dashboard', {
|
|
|
|
what: 'getSupportData',
|
|
|
|
});
|
2021-10-13 09:18:23 -06:00
|
|
|
const shownData = JSON.parse(JSON.stringify(supportData));
|
2021-10-15 12:50:34 -06:00
|
|
|
uselessKeys.forEach(prop => { removeKey(shownData, prop); });
|
2021-11-21 05:53:36 -07:00
|
|
|
const redacted = true;
|
2021-11-11 10:49:55 -07:00
|
|
|
if ( redacted ) {
|
2021-10-13 09:18:23 -06:00
|
|
|
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-11-27 09:58:32 -07:00
|
|
|
if ( reportedPage !== null ) {
|
|
|
|
shownData.popupPanel = reportedPage.popupPanel;
|
|
|
|
}
|
2023-04-27 17:16:46 -06:00
|
|
|
const text = renderData(shownData);
|
2021-10-15 12:50:34 -06:00
|
|
|
cmEditor.setValue(text);
|
2021-10-14 06:54:38 -06:00
|
|
|
cmEditor.clearHistory();
|
2021-10-15 12:50:34 -06:00
|
|
|
|
2021-11-27 09:58:32 -07:00
|
|
|
addDetailsToReportURL('filterReport', true);
|
|
|
|
addDetailsToReportURL('bugReport', true);
|
2021-11-11 10:49:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-11-27 09:58:32 -07:00
|
|
|
const reportedPage = (( ) => {
|
2021-11-11 10:49:55 -07:00
|
|
|
const url = new URL(window.location.href);
|
|
|
|
try {
|
2021-11-27 09:58:32 -07:00
|
|
|
const pageURL = url.searchParams.get('pageURL');
|
|
|
|
if ( pageURL === null ) { return null; }
|
|
|
|
const parsedURL = new URL(pageURL);
|
2021-11-26 10:23:18 -07:00
|
|
|
parsedURL.username = '';
|
|
|
|
parsedURL.password = '';
|
|
|
|
parsedURL.hash = '';
|
2022-11-12 07:51:22 -07:00
|
|
|
const select = qs$('select[name="url"]');
|
|
|
|
dom.text(select.options[0], parsedURL.href);
|
2021-11-26 10:23:18 -07:00
|
|
|
if ( parsedURL.search !== '' ) {
|
2022-11-12 07:51:22 -07:00
|
|
|
const option = dom.create('option');
|
2021-11-26 10:23:18 -07:00
|
|
|
parsedURL.search = '';
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.text(option, parsedURL.href);
|
2021-11-26 10:23:18 -07:00
|
|
|
select.append(option);
|
|
|
|
}
|
|
|
|
if ( parsedURL.pathname !== '/' ) {
|
2022-11-12 07:51:22 -07:00
|
|
|
const option = dom.create('option');
|
2021-11-26 10:23:18 -07:00
|
|
|
parsedURL.pathname = '';
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.text(option, parsedURL.href);
|
2021-11-26 10:23:18 -07:00
|
|
|
select.append(option);
|
|
|
|
}
|
2023-10-16 05:33:38 -06:00
|
|
|
const shouldUpdateLists = url.searchParams.get('shouldUpdateLists');
|
|
|
|
if ( shouldUpdateLists !== null ) {
|
|
|
|
dom.body.dataset.shouldUpdateLists = shouldUpdateLists;
|
2023-04-23 11:45:11 -06:00
|
|
|
}
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.cl.add(dom.body, 'filterIssue');
|
2021-11-27 09:58:32 -07:00
|
|
|
return {
|
2021-11-28 05:47:16 -07:00
|
|
|
hostname: parsedURL.hostname.replace(/^(m|mobile|www)\./, ''),
|
2021-11-27 09:58:32 -07:00
|
|
|
popupPanel: JSON.parse(url.searchParams.get('popupPanel')),
|
|
|
|
};
|
2021-11-11 10:49:55 -07:00
|
|
|
} catch(ex) {
|
|
|
|
}
|
2021-11-27 09:58:32 -07:00
|
|
|
return null;
|
2021-11-11 10:49:55 -07:00
|
|
|
})();
|
|
|
|
|
|
|
|
function reportSpecificFilterType() {
|
2022-11-12 07:51:22 -07:00
|
|
|
return qs$('select[name="type"]').value;
|
2021-11-11 10:49:55 -07:00
|
|
|
}
|
|
|
|
|
2023-04-23 11:45:11 -06:00
|
|
|
function reportSpecificFilterIssue() {
|
2023-04-23 14:32:38 -06:00
|
|
|
const githubURL = new URL(
|
|
|
|
'https://github.com/uBlockOrigin/uAssets/issues/new?template=specific_report_from_ubo.yml'
|
|
|
|
);
|
2021-11-12 07:11:28 -07:00
|
|
|
const issueType = reportSpecificFilterType();
|
2021-11-27 09:58:32 -07:00
|
|
|
let title = `${reportedPage.hostname}: ${issueType}`;
|
2022-11-12 07:51:22 -07:00
|
|
|
if ( qs$('#isNSFW').checked ) {
|
2021-11-16 06:11:04 -07:00
|
|
|
title = `[nsfw] ${title}`;
|
|
|
|
}
|
|
|
|
githubURL.searchParams.set('title', title);
|
2021-11-26 10:23:18 -07:00
|
|
|
githubURL.searchParams.set(
|
2022-11-12 07:51:22 -07:00
|
|
|
'url_address_of_the_web_page',
|
|
|
|
'`' + qs$('select[name="url"]').value + '`'
|
2021-11-26 10:23:18 -07:00
|
|
|
);
|
2021-11-12 07:11:28 -07:00
|
|
|
githubURL.searchParams.set('category', issueType);
|
2021-11-20 07:38:00 -07:00
|
|
|
githubURL.searchParams.set('configuration', configToMarkdown(true));
|
2021-11-11 10:49:55 -07:00
|
|
|
vAPI.messaging.send('default', {
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: { url: githubURL.href, select: true, index: -1 },
|
|
|
|
});
|
2021-10-13 09:18:23 -06:00
|
|
|
}
|
|
|
|
|
2023-04-23 11:45:11 -06:00
|
|
|
async function updateFilterLists() {
|
2023-10-16 05:33:38 -06:00
|
|
|
if ( dom.body.dataset.shouldUpdateLists === undefined ) { return false; }
|
2023-04-23 11:45:11 -06:00
|
|
|
dom.cl.add(dom.body, 'updating');
|
2023-10-16 05:33:38 -06:00
|
|
|
const assetKeys = JSON.parse(dom.body.dataset.shouldUpdateLists);
|
|
|
|
vAPI.messaging.send('dashboard', { what: 'purgeCaches', assetKeys });
|
2023-04-23 11:45:11 -06:00
|
|
|
vAPI.messaging.send('dashboard', { what: 'forceUpdateAssets' });
|
2023-10-16 05:33:38 -06:00
|
|
|
return true;
|
2023-04-23 11:45:11 -06:00
|
|
|
}
|
|
|
|
|
2021-10-13 09:18:23 -06:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-11-12 07:51:22 -07:00
|
|
|
const cmEditor = new CodeMirror(qs$('#supportData'), {
|
2021-10-13 09:18:23 -06:00
|
|
|
autofocus: true,
|
2021-11-11 10:49:55 -07:00
|
|
|
readOnly: true,
|
2021-10-13 09:18:23 -06:00
|
|
|
styleActiveLine: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2021-10-12 09:19:56 -06:00
|
|
|
(async ( ) => {
|
2023-04-23 11:45:11 -06:00
|
|
|
await showSupportData();
|
2021-10-13 09:18:23 -06:00
|
|
|
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.on('[data-url]', 'click', ev => {
|
2021-10-15 12:50:34 -06:00
|
|
|
const elem = ev.target.closest('[data-url]');
|
2022-11-12 07:51:22 -07:00
|
|
|
const url = dom.attr(elem, 'data-url');
|
2021-10-13 09:18:23 -06:00
|
|
|
if ( typeof url !== 'string' || url === '' ) { return; }
|
|
|
|
vAPI.messaging.send('default', {
|
|
|
|
what: 'gotoURL',
|
2021-11-27 09:58:32 -07:00
|
|
|
details: { url, select: true, index: -1, shiftKey: ev.shiftKey },
|
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-11-27 09:58:32 -07:00
|
|
|
if ( reportedPage !== null ) {
|
2023-10-16 05:33:38 -06:00
|
|
|
if ( dom.body.dataset.shouldUpdateLists ) {
|
2023-04-28 06:38:26 -06:00
|
|
|
dom.on('.supportEntry.shouldUpdate button', 'click', ev => {
|
2023-10-16 05:33:38 -06:00
|
|
|
if ( updateFilterLists() === false ) { return; }
|
2023-04-23 11:45:11 -06:00
|
|
|
ev.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.on('[data-i18n="supportReportSpecificButton"]', 'click', ev => {
|
2023-04-23 11:45:11 -06:00
|
|
|
reportSpecificFilterIssue();
|
|
|
|
ev.preventDefault();
|
2021-11-27 09:58:32 -07:00
|
|
|
});
|
2021-11-11 10:49:55 -07:00
|
|
|
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.on('[data-i18n="supportFindSpecificButton"]', 'click', ev => {
|
2021-11-27 09:58:32 -07:00
|
|
|
const url = new URL('https://github.com/uBlockOrigin/uAssets/issues');
|
2021-11-28 05:47:16 -07:00
|
|
|
url.searchParams.set('q', `is:issue sort:updated-desc "${reportedPage.hostname}" in:title`);
|
2021-11-27 09:58:32 -07:00
|
|
|
vAPI.messaging.send('default', {
|
|
|
|
what: 'gotoURL',
|
|
|
|
details: { url: url.href, select: true, index: -1 },
|
|
|
|
});
|
|
|
|
ev.preventDefault();
|
2021-11-11 10:49:55 -07:00
|
|
|
});
|
2022-01-31 11:28:43 -07:00
|
|
|
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.on('#showSupportInfo', 'click', ev => {
|
2023-04-28 06:38:26 -06:00
|
|
|
const button = ev.target.closest('#showSupportInfo');
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.cl.add(button, 'hidden');
|
|
|
|
dom.cl.add('.a.b.c.d', 'e');
|
2022-01-31 11:28:43 -07:00
|
|
|
cmEditor.refresh();
|
|
|
|
});
|
2021-11-27 09:58:32 -07:00
|
|
|
}
|
2021-11-11 10:49:55 -07:00
|
|
|
|
2023-12-01 12:35:28 -07:00
|
|
|
onBroadcast(msg => {
|
2023-04-28 06:38:26 -06:00
|
|
|
if ( msg.what === 'assetsUpdated' ) {
|
|
|
|
dom.cl.remove(dom.body, 'updating');
|
|
|
|
dom.cl.add(dom.body, 'updated');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( msg.what === 'staticFilteringDataChanged' ) {
|
|
|
|
showSupportData();
|
|
|
|
return;
|
|
|
|
}
|
2023-04-24 07:38:37 -06:00
|
|
|
});
|
|
|
|
|
2022-11-12 07:51:22 -07:00
|
|
|
dom.on('#selectAllButton', '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
|
|
|
})();
|