1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-03 09:39:38 +02:00

Support rendering xhr requests in new code viewer

Related commit:
- 33c437f99f
This commit is contained in:
Raymond Hill 2023-03-07 13:40:52 -05:00
parent 63d8fe524c
commit bd84a7c8d5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 19 additions and 14 deletions

View File

@ -37,21 +37,29 @@ import { dom, qs$ } from './dom.js';
dom.attr(a, 'title', url);
const response = await fetch(url);
const text = await response.text();
let value = '', mode = '';
switch ( params.get('type') ) {
case 'css':
mode = 'text/css';
let mime = response.headers.get('Content-Type') || '';
mime = mime.replace(/\s*;.*$/, '').trim();
let value = '';
switch ( mime ) {
case 'text/css':
value = beautifier.css(text, { indent_size: 2 });
break;
case 'html':
mode = 'text/html';
case 'text/html':
case 'application/xhtml+xml':
case 'application/xml':
case 'image/svg+xml':
value = beautifier.html(text, { indent_size: 2 });
break;
case 'js':
mode = 'text/javascript';
case 'text/javascript':
case 'application/javascript':
case 'application/x-javascript':
value = beautifier.js(text, { indent_size: 4 });
break;
case 'application/json':
value = beautifier.js(text, { indent_size: 2 });
break;
default:
value = text;
break;
}
const cmEditor = new CodeMirror(qs$('#content'), {
@ -60,7 +68,7 @@ import { dom, qs$ } from './dom.js';
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
mode,
mode: mime,
styleActiveLine: {
nonEmpty: true,
},

View File

@ -285,14 +285,11 @@ const nodeFromURL = function(parent, url, re, type) {
let href = url;
switch ( type ) {
case 'css':
href = `code-viewer.html?url=${encodeURIComponent(url)}&type=css`;
break;
case 'doc':
case 'frame':
href = `code-viewer.html?url=${encodeURIComponent(url)}&type=html`;
break
case 'script':
href = `code-viewer.html?url=${encodeURIComponent(url)}&type=js`;
case 'xhr':
href = `code-viewer.html?url=${encodeURIComponent(href)}`;
break;
default:
break;