Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- const old = document.getElementById('console');
- if(old){
- old.parentElement.removeChild(old);
- window.console = window._console;
- }
- const setStyle = function(){
- const s = document.createElement('style');
- s.innerHTML = `
- /* The console container element */
- #console {
- position: absolute;
- width: 330px;
- height: 240px;
- background-color:black;
- }
- /* The inner console element. */
- .jqconsole {
- padding: 10px;
- }
- /* The cursor. */
- .jqconsole-cursor {
- background-color: gray;
- }
- /* The cursor color when the console looses focus. */
- .jqconsole-blurred .jqconsole-cursor {
- background-color: #666;
- }
- /* The current prompt text color */
- .jqconsole-prompt {
- color: #0d0;
- }
- /* The command history */
- .jqconsole-old-prompt {
- color: #0b0;
- font-weight: normal;
- }
- /* The text color when in input mode. */
- .jqconsole-input {
- color: #dd0;
- }
- /* Previously entered input. */
- .jqconsole-old-input {
- color: #bb0;
- font-weight: normal;
- }
- /* The text color of the output. */
- .jqconsole-output {
- color: white;
- }
- /* The text color of the output. */
- .jqconsole-warning {
- color: yellow;
- }
- /* The text color of the output. */
- .jqconsole-error {
- color: red;
- }
- /* The text color of the output. */
- .jqconsole-info {
- color: blue;
- }
- /* The text color of the output. */
- .jqconsole-return {
- color: gray;
- }
- `;
- document.head.appendChild(s);
- };
- setStyle();
- const loadScript = function(src, cb){
- const s = document.createElement('script');
- document.head.appendChild(s);
- s.onload = cb;
- s.src = src;
- };
- const loadStyle = function(src, cb){
- const s = document.createElement('link');
- document.head.appendChild(s);
- s.onload = cb;
- s.href = src;
- s.rel = 'stylesheet';
- };
- const initConsole = function(){
- var d = document.createElement('div');
- d.id = 'console';
- document.body.appendChild(d);
- $('#console').draggable();
- $('#console').resizable();
- var jqconsole = $('#console').jqconsole('', '');
- window._console = window.console;
- const writeString = {
- log(string){
- jqconsole.Write(string + '\n', 'jqconsole-output');
- window._console.log(string);
- },
- warn(string){
- jqconsole.Write(string + '\n', 'jqconsole-warning');
- window._console.warn(string);
- },
- error(string){
- jqconsole.Write(string + '\n', 'jqconsole-error');
- window._console.error(string);
- },
- info(string){
- jqconsole.Write(string + '\n', 'jqconsole-info');
- window._console.info(string);
- },
- isJqConsole: true
- };
- if(!window.console.isJqConsole){
- window.console = writeString;
- }
- jqconsole.RegisterShortcut('A', function() {
- jqconsole.MoveToStart();
- });
- jqconsole.RegisterShortcut('E', function() {
- jqconsole.MoveToEnd();
- });
- var startPrompt = function(){
- jqconsole.RegisterMatching('(', ')', 'parents');
- const prompt = '> ';
- jqconsole.Write(prompt, 'jqconsole-prompt');
- const processInput = function(input){
- try{
- const result = eval(input);
- jqconsole.Write(result + '\n', 'jqconsole-return');
- }catch(err){
- console.log(err);
- jqconsole.Write('ERROR: ' + err.message + '\n', 'jqconsole-error');
- }
- startPrompt();
- };
- jqconsole.Prompt(true, processInput);
- };
- startPrompt();
- };
- const jquiCss = '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css';
- const jq = '//jscl-project.github.io/jquery.js';
- const jqui = '//code.jquery.com/ui/1.12.1/jquery-ui.js';
- const jqconsole = '//jscl-project.github.io/jqconsole.min.js';
- loadStyle(jquiCss, function(){
- loadScript(jq, function(){
- loadScript(jqui, function(){
- loadScript(jqconsole, function(){
- initConsole();
- });
- });
- });
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment