Last active
March 31, 2019 20:58
-
-
Save wlib/085ec2697972a88b4f1f806d794f5bb6 to your computer and use it in GitHub Desktop.
Ultra simple js console for when devtools are blocked
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
window.jsConsoleState = { | |
lines: ["This is a JavaScript console.\nTo clear history, run clear()\nTo exit, run exit()"], | |
isLooping: true | |
} | |
const jsConsole = () => { | |
// Show the previous lines above the prompt | |
const input = prompt(window.jsConsoleState.lines.join("\n")) | |
// Push user input for next prompt | |
window.jsConsoleState.lines.push(input) | |
// Evaluate user input | |
let result | |
try { | |
result = window.eval(input) | |
} catch (err) { | |
result = err | |
} | |
// Quit execution if the user exited | |
if (!window.jsConsoleState.isLooping) { | |
return | |
} else { | |
// Push the evaluation return value and then display the next prompt | |
window.jsConsoleState.lines.push("> " + result) | |
jsConsole() | |
} | |
} | |
window.exit = () => { | |
window.jsConsoleState.isLooping = false | |
} | |
window.clear = () => { | |
window.jsConsoleState.lines = [] | |
} | |
// Initiate | |
jsConsole() |
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
javascript:document.body.appendChild(document.createElement('script')).src='https://cdn.staticaly.com/gist/wlib/085ec2697972a88b4f1f806d794f5bb6/raw/e8924a773f848923dd5d77175e6e9c0bf8fa514a/jsconsole.js';void(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment