1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
/*******************************************************************************
uBlock Origin - a comprehensive, efficient content blocker
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
*/
/* global CodeMirror, uBlockDashboard */
'use strict';
import { onBroadcast } from './broadcast.js';
import { dom, qs$ } from './dom.js';
/******************************************************************************/
const uselessKeys = [
'hiddenSettings.benchmarkDatasetURL',
'hiddenSettings.blockingProfiles',
'hiddenSettings.consoleLogLevel',
'hiddenSettings.uiPopupConfig',
'userSettings.alwaysDetachLogger',
'userSettings.firewallPaneMinimized',
'userSettings.externalLists',
'userSettings.importedLists',
'userSettings.popupPanelSections',
'userSettings.uiAccentCustom',
'userSettings.uiAccentCustom0',
'userSettings.uiTheme',
];
const sensitiveValues = [
'filterset (user)',
'userSettings.popupPanelSections',
'hiddenSettings.userResourcesLocation',
'trustedset.added',
'hostRuleset.added',
'switchRuleset.added',
'urlRuleset.added',
];
const sensitiveKeys = [
'listset.added',
];
/******************************************************************************/
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];
}
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) ) {
if ( value.length !== 0 ) {
value = `[array of ${value.length} redacted]`;
} else {
value = '[empty]';
}
} 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;
}
}
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 configToMarkdown(collapse = false) {
const text = cmEditor.getValue().trim();
return collapse
? '<details>\n\n```yaml\n' + text + '\n```\n</details>'
: '```yaml\n' + text + '\n```\n';
}
function addDetailsToReportURL(id, collapse = false) {
const elem = qs$(`#${id}`);
const url = new URL(dom.attr(elem, 'data-url'));
url.searchParams.set('configuration', configToMarkdown(collapse));
dom.attr(elem, 'data-url', url);
}
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');
}
if ( typeof data !== 'object' || data === null ) {
return `${indent}${data}`;
}
const out = [];
for ( const [ name, value ] of Object.entries(data) ) {
if ( typeof value === 'object' && value !== null ) {
out.push(`${indent}${name}:`);
out.push(renderData(value, depth + 1));
continue;
}
out.push(`${indent}${name}: ${value}`);
}
return out.join('\n');
}
async function showSupportData() {
const supportData = await vAPI.messaging.send('dashboard', {
what: 'getSupportData',
});
const shownData = JSON.parse(JSON.stringify(supportData));
uselessKeys.forEach(prop => { removeKey(shownData, prop); });
const redacted = true;
if ( redacted ) {
sensitiveValues.forEach(prop => { redactValue(shownData, prop); });
sensitiveKeys.forEach(prop => { redactKeys(shownData, prop); });
}
for ( const prop in shownData ) {
patchEmptiness(shownData, prop);
}
if ( reportedPage !== null ) {
shownData.popupPanel = reportedPage.popupPanel;
}
const text = renderData(shownData);
cmEditor.setValue(text);
cmEditor.clearHistory();
addDetailsToReportURL('filterReport', true);
addDetailsToReportURL('bugReport', true);
}
/******************************************************************************/
const reportedPage = (( ) => {
const url = new URL(window.location.href);
try {
const pageURL = url.searchParams.get('pageURL');
if ( pageURL === null ) { return null; }
const parsedURL = new URL(pageURL);
parsedURL.username = '';
parsedURL.password = '';
parsedURL.hash = '';
const select = qs$('select[name="url"]');
dom.text(select.options[0], parsedURL.href);
if ( parsedURL.search !== '' ) {
const option = dom.create('option');
parsedURL.search = '';
dom.text(option, parsedURL.href);
select.append(option);
}
if ( parsedURL.pathname !== '/' ) {
const option = dom.create('option');
parsedURL.pathname = '';
dom.text(option, parsedURL.href);
select.append(option);
}
const shouldUpdateLists = url.searchParams.get('shouldUpdateLists');
if ( shouldUpdateLists !== null ) {
dom.body.dataset.shouldUpdateLists = shouldUpdateLists;
}
dom.cl.add(dom.body, 'filterIssue');
return {
hostname: parsedURL.hostname.replace(/^(m|mobile|www)\./, ''),
popupPanel: JSON.parse(url.searchParams.get('popupPanel')),
};
} catch(ex) {
}
return null;
})();
function reportSpecificFilterType() {
return qs$('select[name="type"]').value;
}
function reportSpecificFilterIssue() {
const githubURL = new URL(
'https://github.com/uBlockOrigin/uAssets/issues/new?template=specific_report_from_ubo.yml'
);
const issueType = reportSpecificFilterType();
let title = `${reportedPage.hostname}: ${issueType}`;
if ( qs$('#isNSFW').checked ) {
title = `[nsfw] ${title}`;
}
githubURL.searchParams.set('title', title);
githubURL.searchParams.set(
'url_address_of_the_web_page',
'`' + qs$('select[name="url"]').value + '`'
);
githubURL.searchParams.set('category', issueType);
githubURL.searchParams.set('configuration', configToMarkdown(true));
vAPI.messaging.send('default', {
what: 'gotoURL',
details: { url: githubURL.href, select: true, index: -1 },
});
}
async function updateFilterLists() {
if ( dom.body.dataset.shouldUpdateLists === undefined ) { return false; }
dom.cl.add(dom.body, 'updating');
const assetKeys = JSON.parse(dom.body.dataset.shouldUpdateLists);
vAPI.messaging.send('dashboard', { what: 'supportUpdateNow', assetKeys });
return true;
}
/******************************************************************************/
const cmEditor = new CodeMirror(qs$('#supportData'), {
autofocus: true,
readOnly: true,
styleActiveLine: true,
});
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
/******************************************************************************/
(async ( ) => {
await showSupportData();
dom.on('[data-url]', 'click', ev => {
const elem = ev.target.closest('[data-url]');
const url = dom.attr(elem, 'data-url');
if ( typeof url !== 'string' || url === '' ) { return; }
vAPI.messaging.send('default', {
what: 'gotoURL',
details: { url, select: true, index: -1, shiftKey: ev.shiftKey },
});
ev.preventDefault();
});
if ( reportedPage !== null ) {
if ( dom.body.dataset.shouldUpdateLists ) {
dom.on('.supportEntry.shouldUpdate button', 'click', ev => {
if ( updateFilterLists() === false ) { return; }
ev.preventDefault();
});
}
dom.on('[data-i18n="supportReportSpecificButton"]', 'click', ev => {
reportSpecificFilterIssue();
ev.preventDefault();
});
dom.on('[data-i18n="supportFindSpecificButton"]', 'click', ev => {
const url = new URL('https://github.com/uBlockOrigin/uAssets/issues');
url.searchParams.set('q', `is:issue sort:updated-desc "${reportedPage.hostname}" in:title`);
vAPI.messaging.send('default', {
what: 'gotoURL',
details: { url: url.href, select: true, index: -1 },
});
ev.preventDefault();
});
dom.on('#showSupportInfo', 'click', ev => {
const button = ev.target.closest('#showSupportInfo');
dom.cl.add(button, 'hidden');
dom.cl.add('.a.b.c.d', 'e');
cmEditor.refresh();
});
}
onBroadcast(msg => {
if ( msg.what === 'assetsUpdated' ) {
dom.cl.remove(dom.body, 'updating');
dom.cl.add(dom.body, 'updated');
return;
}
if ( msg.what === 'staticFilteringDataChanged' ) {
showSupportData();
return;
}
});
dom.on('#selectAllButton', 'click', ( ) => {
cmEditor.focus();
cmEditor.execCommand('selectAll');
});
})();
|