-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add source code viewer (from logger)
This commits add the ability to open html/css/script resources from the logger, as a formatted and syntax- highligthed document. The goal is to make it easier for filter list authors to investigate filter-related issues.
- Loading branch information
Showing
17 changed files
with
2,588 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Code viewer</title> | ||
<link rel="stylesheet" href="lib/codemirror/lib/codemirror.css"> | ||
<link rel="stylesheet" href="lib/codemirror/theme/night.css"> | ||
<link rel="stylesheet" href="lib/codemirror/addon/search/matchesonscrollbar.css"> | ||
<link rel="stylesheet" href="css/themes/default.css"> | ||
<link rel="stylesheet" href="css/common.css"> | ||
<link rel="stylesheet" href="css/fa-icons.css"> | ||
<link rel="stylesheet" href="css/codemirror.css"> | ||
<link rel="stylesheet" href="css/code-viewer.css"> | ||
</head> | ||
<body class="loading"> | ||
|
||
<div id="content" class="codeMirrorContainer codeMirrorBreakAll"></div> | ||
|
||
<script src="lib/codemirror/lib/codemirror.js"></script> | ||
<script src="lib/codemirror/addon/display/panel.js"></script> | ||
<script src="lib/codemirror/addon/scroll/annotatescrollbar.js"></script> | ||
<script src="lib/codemirror/addon/search/searchcursor.js"></script> | ||
<script src="lib/codemirror/addon/selection/active-line.js"></script> | ||
<script src="lib/codemirror/mode/javascript/javascript.js"></script> | ||
<script src="lib/codemirror/mode/css/css.js"></script> | ||
<script src="lib/codemirror/mode/xml/xml.js"></script> | ||
<script src="lib/codemirror/mode/htmlmixed/htmlmixed.js"></script> | ||
|
||
<script src="js/codemirror/search.js"></script> | ||
<script src="js/codemirror/search-thread.js"></script> | ||
<script src="lib/js-beautify/beautify.min.js"></script> | ||
<script src="js/fa-icons.js"></script> | ||
<script src="js/vapi.js"></script> | ||
<script src="js/vapi-common.js"></script> | ||
<script src="js/vapi-client.js"></script> | ||
<script src="js/theme.js" type="module"></script> | ||
<script src="js/i18n.js" type="module"></script> | ||
<script src="js/dashboard-common.js" type="module"></script> | ||
<script src="js/code-viewer.js" type="module"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
body { | ||
border: 0; | ||
display: flex; | ||
flex-direction: column; | ||
height: 100vh; | ||
margin: 0; | ||
overflow: hidden; | ||
padding: 0; | ||
width: 100vw; | ||
} | ||
#content { | ||
flex-grow: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
uBlock Origin - a browser extension to block requests. | ||
Copyright (C) 2023-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 | ||
*/ | ||
|
||
/* globals CodeMirror, uBlockDashboard, beautifier */ | ||
|
||
'use strict'; | ||
|
||
/******************************************************************************/ | ||
|
||
import { dom, qs$ } from './dom.js'; | ||
|
||
/******************************************************************************/ | ||
|
||
(async ( ) => { | ||
const params = new URLSearchParams(document.location.search); | ||
const url = params.get('url'); | ||
const a = qs$('.cm-search-widget .sourceURL'); | ||
dom.attr(a, 'href', url); | ||
dom.attr(a, 'title', url); | ||
const response = await fetch(url); | ||
const text = await response.text(); | ||
const formatOptions = { indent_size: 2 }; | ||
let value = '', mode = ''; | ||
switch ( params.get('type') ) { | ||
case 'css': | ||
mode = 'text/css'; | ||
value = beautifier.css(text, formatOptions); | ||
break; | ||
case 'html': | ||
mode = 'text/html'; | ||
value = beautifier.html(text, formatOptions); | ||
break; | ||
case 'js': | ||
mode = 'text/javascript'; | ||
value = beautifier.js(text, formatOptions); | ||
break; | ||
default: | ||
break; | ||
} | ||
const cmEditor = new CodeMirror(qs$('#content'), { | ||
autofocus: true, | ||
gutters: [ 'CodeMirror-linenumbers' ], | ||
lineNumbers: true, | ||
lineWrapping: true, | ||
mode, | ||
readOnly: true, | ||
styleActiveLine: { | ||
nonEmpty: true, | ||
}, | ||
value, | ||
}); | ||
uBlockDashboard.patchCodeMirrorEditor(cmEditor); | ||
if ( dom.cl.has(dom.html, 'dark') ) { | ||
dom.cl.add('#content .cm-s-default', 'cm-s-night'); | ||
dom.cl.remove('#content .cm-s-default', 'cm-s-default'); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
33c437f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name of the js is
beautifier.min.js
, while the script path mentions -beautify.min.js
as a result of the name mis-match, script fails to load.33c437f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh... I changed the name right before committing during code review, then forgot to other side.
33c437f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just keep it
beautifier.min.js
?33c437f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what it's supposed to be, it was originally named
beautify.min.js
and I ended up using the other library because it supports html/css as well.33c437f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I thought it was the other way round.