Merge both consoles
This commit is contained in:
parent
2b81593ad6
commit
75e9793001
|
@ -1,10 +1,10 @@
|
|||
# Windows XP Scripting Consoles
|
||||
|
||||
This repository holds some files that were created as part of a project to put JavaScript and VBScript consoles into every single possible place in Windows XP to learn more about how and why ActiveX was made available in so many spots.
|
||||
This repository holds some files that were created as part of a project to put a JavaScript and VBScript console into every single possible place in Windows XP to learn more about how and why ActiveX was made available in so many spots.
|
||||
|
||||
I will try to document how I placed the consoles in each spot, how you can do it too, and what else more is doable other than just running `console.log`.
|
||||
|
||||
* About the Consoles (soon™)
|
||||
* About the Console (soon™)
|
||||
* [Web Wizards](docs/web-wizards.md)
|
||||
* Web Slice (soon™)
|
||||
* Windows Media Player Online Store (soon™)
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JavaScript Console</title>
|
||||
<title>Windows Scripting Console</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=8" />
|
||||
<link rel="stylesheet" type="text/css" href="console.css" />
|
||||
<link rel="icon" type="image/x-icon" href="jsconsole.ico" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="jsconsole.ico" />
|
||||
<link rel="icon" type="image/x-icon" href="console.ico" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="console.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="hslice" id="slice">
|
||||
<div class="entry-title">JavaScript Console</div>
|
||||
<a rel="entry-content" href="./jsconsole.html"></a>
|
||||
<div class="entry-title">Windows Scripting Console</div>
|
||||
<a rel="entry-content" href="./console.html"></a>
|
||||
</div>
|
||||
<textarea id="input" placeholder="Type some JavaScript to run and press Shift+Enter"></textarea>
|
||||
<div id="output"></div>
|
||||
<div class="buttons">
|
||||
<select id="languageselect">
|
||||
<option value="js">JavaScript</option>
|
||||
<option value="vbs-eval">VBScript Eval</option>
|
||||
<option value="vbs-execute">VBScript Execute</option>
|
||||
</select>
|
||||
<input type="button" id="runbutton" value="run" />
|
||||
<input type="button" id="clearbutton" value="clear" />
|
||||
</div>
|
||||
<script type="text/vbscript" language="vbscript" src="console.vbs"></script>
|
||||
<script type="text/javascript" language="javascript" src="console.js"></script>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
100
console.js
100
console.js
|
@ -1,6 +1,19 @@
|
|||
function JSEval (code) {
|
||||
try {
|
||||
return eval(code);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
function supportsVB () {
|
||||
return typeof window.VBSEval === 'unknown' && typeof window.VBSExecute === 'unknown'
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
var output = document.getElementById("output");
|
||||
var input = document.getElementById("input");
|
||||
var languageSelect = document.getElementById("languageselect");
|
||||
var runButton = document.getElementById("runbutton");
|
||||
var clearButton = document.getElementById("clearbutton");
|
||||
|
||||
|
@ -74,6 +87,7 @@ window.onload = function () {
|
|||
}
|
||||
entry.appendChild(document.createTextNode(outputText));
|
||||
output.appendChild(entry);
|
||||
entry.scrollIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,18 +120,6 @@ window.onload = function () {
|
|||
}
|
||||
console.log(stack.trim());
|
||||
}
|
||||
|
||||
var inputLogger = makeLogger('log', 'lightblue');
|
||||
function run () {
|
||||
var code = getSelectedText(input) || input.value;
|
||||
if (!code.trim()) return;
|
||||
inputLogger(code);
|
||||
try {
|
||||
console.log(eval(code));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
console.clear = function () {
|
||||
if (originalConsole && originalConsole.clear) {
|
||||
|
@ -127,6 +129,33 @@ window.onload = function () {
|
|||
output.innerHTML = "";
|
||||
}
|
||||
|
||||
var inputLogger = makeLogger('log', 'lightblue');
|
||||
function run () {
|
||||
var code = getSelectedText(input) || input.value;
|
||||
if (!code.trim()) return;
|
||||
|
||||
inputLogger(code);
|
||||
try {
|
||||
switch (languageSelect.value) {
|
||||
case 'js':
|
||||
result = JSEval(code);
|
||||
break;
|
||||
case 'vbs-eval':
|
||||
result = VBSEval(code);
|
||||
break;
|
||||
case 'vbs-execute':
|
||||
result = VBSExecute(code);
|
||||
break;
|
||||
default:
|
||||
console.error('Unsupported language', languageSelect.value);
|
||||
return;
|
||||
}
|
||||
console.log(result);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
input.onkeypress = function (event) {
|
||||
if (!event) event = window.event;
|
||||
// Run code if Shift+Enter is pressed
|
||||
|
@ -138,6 +167,24 @@ window.onload = function () {
|
|||
run();
|
||||
}
|
||||
}
|
||||
|
||||
languageSelect.onchange = function () {
|
||||
switch (languageSelect.value) {
|
||||
case 'js':
|
||||
languageSelect.setAttribute('placeholder', 'Type some JavaScript to run and press Shift+Enter');
|
||||
break;
|
||||
case 'vbs-eval':
|
||||
languageSelect.setAttribute('placeholder', 'Type a VBScript expression to evaluate and press Shift+Enter');
|
||||
break;
|
||||
case 'vbs-execute':
|
||||
languageSelect.setAttribute('placeholder', 'Type some VBScript to run and press Shift+Enter');
|
||||
break;
|
||||
default:
|
||||
languageSelect.setAttribute('placeholder', 'Type the name of a demonic entity to summon and press Shift+Enter');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
runButton.onclick = run;
|
||||
clearButton.onclick = console.clear;
|
||||
|
||||
|
@ -152,20 +199,23 @@ window.onload = function () {
|
|||
input.style.height = document.documentElement.clientHeight - 7 + 'px';
|
||||
output.style.marginLeft = '7px';
|
||||
}
|
||||
}
|
||||
|
||||
// Try to detect the wizard extensions.
|
||||
if (typeof window.external === 'object') {
|
||||
if (typeof window.external.SetHeaderText === 'unknown')
|
||||
window.external.SetHeaderText('JavaScript Console', "Explore this wizard's JavaScript environment.");
|
||||
|
||||
if (typeof window.external.SetWizardButtons === 'unknown')
|
||||
window.external.SetWizardButtons(1, 0, 0);
|
||||
|
||||
if (typeof window.external.FinalBack === 'unknown') {
|
||||
// An onback function is required by the web wizard specification
|
||||
window.onback = function () {
|
||||
window.external.FinalBack();
|
||||
if (!supportsVB()) {
|
||||
for (var i = 0; i < languageSelect.children.length; i++) {
|
||||
if (languageSelect.children[i].value.slice(0, 3) === 'vbs') {
|
||||
languageSelect.children[i].disabled = true;
|
||||
languageSelect.children[i].title = 'VBScript is not supported in this browser.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to detect the wizard extensions.
|
||||
if (supportsVB() && InWebWizard()) {
|
||||
window.external.SetHeaderText('Windows Scripting Console', "Explore this wizard's scripting environment.");
|
||||
window.external.SetWizardButtons(1, 0, 0);
|
||||
// An onback function is required by the web wizard specification
|
||||
window.onback = function () {
|
||||
window.external.FinalBack();
|
||||
}
|
||||
}
|
||||
|
|
147
console.vbs
147
console.vbs
|
@ -1,150 +1,23 @@
|
|||
Option Explicit
|
||||
On Error Resume Next
|
||||
|
||||
Private input, output, runButton, clearButton
|
||||
|
||||
Private Sub ConsoleLog(message, color)
|
||||
Dim entry
|
||||
Set entry = document.createElement("div")
|
||||
With entry.style
|
||||
.margin = "0"
|
||||
.padding = "1px"
|
||||
.borderBottom = "1px solid lightgray"
|
||||
If Not IsNull(color) Then
|
||||
.color = color
|
||||
End If
|
||||
End With
|
||||
If IsEmpty(message) Then message = "[Empty]"
|
||||
If IsNull(message) Then message = "[Null]"
|
||||
entry.appendChild(document.createTextNode(CStr(message)))
|
||||
output.appendChild(entry)
|
||||
End Sub
|
||||
|
||||
Sub Log(message)
|
||||
ConsoleLog message, Null
|
||||
End Sub
|
||||
|
||||
Sub Debug(message)
|
||||
ConsoleLog message, "darkgray"
|
||||
End Sub
|
||||
|
||||
Sub Info(message)
|
||||
ConsoleLog message, Null
|
||||
End Sub
|
||||
|
||||
Sub Warn(message)
|
||||
ConsoleLog message, "orange"
|
||||
End Sub
|
||||
|
||||
Sub Error(message)
|
||||
ConsoleLog message, "red"
|
||||
End Sub
|
||||
|
||||
Sub Assert(condition, message)
|
||||
If Not condition Then Error message
|
||||
End Sub
|
||||
|
||||
Sub Clear
|
||||
output.innerHTML = ""
|
||||
End Sub
|
||||
|
||||
Private Function RemoveCr (ByVal text)
|
||||
RemoveCr = Replace(text, vbCrLf, vbLf)
|
||||
End Function
|
||||
|
||||
Private Function GetSelectedText (element)
|
||||
Dim range
|
||||
Set range = document.selection.createRange()
|
||||
If IsNull(range) Or range.parentElement() <> element Then
|
||||
GetSelectedText = ""
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
Dim normalizedValue, inputRange, endRange
|
||||
normalizedValue = RemoveCr(element.value)
|
||||
Set inputRange = element.createTextRange()
|
||||
inputRange.moveToBookmark range.getBookmark()
|
||||
Set endRange = element.createTextRange()
|
||||
endRange.collapse False
|
||||
|
||||
'Selection begins at the end of the input, so it's empty
|
||||
If inputRange.compareEndPoints("StartToEnd", endRange) > -1 Then
|
||||
GetSelectedText = ""
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
Dim selectionStart, selectionEnd
|
||||
selectionStart = -inputRange.moveStart("character", -Len(element.value))
|
||||
selectionStart = selectionStart + UBound(Split(Left(normalizedValue, selectionStart), vbLf)) + 1
|
||||
If selectionStart <= 0 Then selectionStart = 1
|
||||
|
||||
selectionEnd = Len(normalizedValue)
|
||||
If inputRange.compareEndPoints("EndToEnd", endRange) < 0 Then
|
||||
selectionEnd = -inputRange.moveEnd("character", -Len(element.value))
|
||||
selectionEnd = selectionEnd + UBound(Split(Left(normalizedValue, selectionEnd), vbLf))
|
||||
End If
|
||||
|
||||
GetSelectedText = Mid(normalizedValue, selectionStart, selectionEnd - selectionStart + 1)
|
||||
End Function
|
||||
|
||||
Private Sub Run
|
||||
Dim code
|
||||
code = GetSelectedText(input)
|
||||
If code = "" Then code = RemoveCr(input.value)
|
||||
If Trim(code) = "" Then Exit Sub
|
||||
Sub VBSExecute(code)
|
||||
Err.Clear
|
||||
ConsoleLog code, "lightblue"
|
||||
Execute "On Error Resume Next" & vbCrLf & code
|
||||
If Err.Number <> 0 Then
|
||||
Error "Error " & Err.Number & " - " & Err.Source & ": " & Err.Description
|
||||
console.error "VBScript Error " & Err.Number & " - " & Err.Source & ": " & Err.Description
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub InputKeyPress
|
||||
If window.event.keyCode = 13 And window.event.shiftKey Then
|
||||
window.event.cancelBubble = True
|
||||
window.event.returnValue = False
|
||||
Run
|
||||
Function VBSEval(code)
|
||||
Err.Clear
|
||||
VBSEval = Eval(code)
|
||||
If Err.Number <> 0 Then
|
||||
console.error "VBScript Error " & Err.Number & " - " & Err.Source & ": " & Err.Description
|
||||
End If
|
||||
End Sub
|
||||
End Function
|
||||
|
||||
'Auto-detect the wizard's browser extensions
|
||||
Private Function InWebWizard()
|
||||
Function InWebWizard()
|
||||
InWebWizard = TypeName(window.external) = "INewWDEvents"
|
||||
End Function
|
||||
|
||||
Private Function InIE7()
|
||||
InIE7 = InStr(navigator.userAgent, "MSIE 7.0")
|
||||
End Function
|
||||
|
||||
Sub window_onload
|
||||
With document
|
||||
Set input = .getElementById("input")
|
||||
Set output = .getElementById("output")
|
||||
Set runButton = .getElementById("runButton")
|
||||
Set clearButton = .getElementById("clearButton")
|
||||
End With
|
||||
|
||||
runButton.onclick = GetRef("Run")
|
||||
clearButton.onclick = GetRef("Clear")
|
||||
input.onkeypress = GetRef("InputKeyPress")
|
||||
|
||||
If InWebWizard() Then
|
||||
window.external.SetHeaderText "VBScript Console", "Explore this wizard's VBScript environment."
|
||||
window.external.SetWizardButtons True, False, False
|
||||
End If
|
||||
|
||||
'For some reason, IE 7 messes up the textarea's width and height
|
||||
'pretty badly. We hardcode the height, removing a little margin,
|
||||
'and add some margin to the output.
|
||||
'Setting the input's width causes it to somehow divide itself by 2 on every keystroke.
|
||||
If InIE7() Then
|
||||
input.style.height = document.documentElement.clientHeight - 7 & "px"
|
||||
output.style.marginLeft = "7px"
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'The web wizard specification requires every page to have an OnBack procedure
|
||||
Sub OnBack
|
||||
If InWebWizard() Then window.external.FinalBack
|
||||
End Sub
|
||||
End Function
|
|
@ -1,23 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>VBScript Console</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" type="text/css" href="console.css" />
|
||||
<link rel="icon" type="image/x-icon" href="vbsconsole.ico" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="vbsconsole.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="hslice" id="slice">
|
||||
<div class="entry-title">VBScript Console</div>
|
||||
<a rel="entry-content" href="./vbsconsole.html"></a>
|
||||
</div>
|
||||
<textarea id="input" placeholder="Type some VBScript to run and press Shift+Enter to run"></textarea>
|
||||
<div id="output"></div>
|
||||
<div class="buttons">
|
||||
<input type="button" id="runbutton" value="run" />
|
||||
<input type="button" id="clearbutton" value="clear" />
|
||||
</div>
|
||||
<script type="text/vbscript" language="vbscript" src="console.vbs"></script>
|
||||
</body>
|
||||
</html>
|
BIN
vbsconsole.ico
BIN
vbsconsole.ico
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in New Issue