');
lastKnownLocation = url;
// frame.location = url;
var tidyUrl = '/cgi-bin/joey/tidy?url=';
if (new XMLHttpRequest()) {
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', tidyUrl+url, false);
httpRequest.send(null);
var xmlDocument = httpRequest.responseXML;
alert(xmlDocument.documentElement.nodeName)
} else if (new ActiveXObject('Microsoft.XMLHTTP')) {
var httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
httpRequest.open('GET', tidyUrl+url, false);
httpRequest.send();
var xmlDocument = httpRequest.responseXML;
alert(xmlDocument.documentElement.nodeName)
}
refreshTimer();
}
//////////////////////////// PowerBar modules ////////////////////////////
//////////////////////////// Module: Options
function componentTypeForJSType(jsType) {
return (
jsType == "boolean" ? "checkbox" :
jsType == "string" ? "text" :
jsType == "number" ? "text" :
"button"
);
}
function editOptions() {
var html = "";
html += "
";
writeToFrame(mainFrame,html);
}
// var thingy;
// function submitOptions(thing) {
// thingy = thing;
// alert("Got a thing: " + tryeval(thing) + " of type=" + trytypeof(thing));
// jsReflectorShow("top.thingy");
generatePowerBar();
// }
//////////////////////////// Module: JavaScript tester
function processJs(codeToExecute) {
var result;
try {
result = eval(codeToExecute);
} catch (e) {
result = e;
}
var report = "I executed\n" + codeToExecute + "\nand got\n" + result + "";
var htmlReport = toHtml(report);
top.log(report);
refreshTimer();
}
//////////////////////////// Module: JavaScript reflector
var jsReflectorHistory = new Array();
function jsReflectorInit() {
jsReflectorShow("top.powerBarFrame");
}
// TODO: popup reflector in a separate window
function jsReflectorShow(objName) {
if (!arrayContains(jsReflectorHistory,objName)) {
jsReflectorHistory.push(objName);
}
top.log("jsReflectorShow(\"" + objName + "\");");
try {
var obj = tryeval(objName);
var html = "";
html += "Go back to: ";
for (var i=0;i" + prevObjName + "";
if (i < jsReflectorHistory.length - 1) {
html += ", ";
}
}
var editableObjName = "";
html += "
";
var i = 0;
var list = "";
for (var name in obj) { // BUG: Mozilla doesn't find the "document" in window objects!
var globName = objName + "." + name;
var value = "";
var type = "";
try {
value = eval("obj." + name);
type = trytypeof(value);
// We need to ensure it can be evaluated as a string or it might fail when added to HTML later:
value = "" + value;
} catch (e) {
value = " (" + e + ")";
}
var link = 'javascript:top.jsReflectorShow("' + globName + '")';
list += "
";
list += "\n"; // for sortLines
}
list = sortLines(list);
html += list;
html += "
";
html += "
";
// BUG re. popup window: It's what we want really, but currently in Mozilla at least, subsequent calls to top.jsReflectorShow() from the new window can not find the function!
writeToWindow('jsReflector',html);
// writeToFrame(powerBarFrame,html);
} catch (e) {
top.log(e);
}
}
//////////////////////////// Module: XPath grabber
var cnt;
function xPathGrabber() {
cnt = 0;
try {
onAllNodesDo(top.mainFrame.document,"",attachClickListener,doNothing); // not working! hence showShapeOld
} catch (e) {
top.log("Problem during onAllNodesDo(): " + e);
}
top.log("Added XPath click capture to " + cnt + " nodes.");
}
function attachClickListener(context,node) {
// if (node.childNodes.length == 0) {
if (node.captureEvents) {
node.captureEvents(Event.CLICK); // only Moz needs this
}
node.onmouseup = processClick;
cnt++;
// node.onmouseup = 'alert("Node " + this + " has XPath = " + getXPath(this));';
// }
}
// var eventObj;
function processClick(event) {
var node = event.srcElement;
if (!node) {
node = event.currentTarget;
}
alert("Node " + node + " has " + node.childNodes.length + " kids and XPath:\n" + getXPath(node));
// LOG(getXPath(node) + ": \"" + toHtml(node.)));
try {
node.style.backgroundColor = randomColour();
} catch (e) {
top.log(e);
}
// event.currentTarget.onmouseup = "";
// eventObj = node;
// jsReflectorShow("top.eventObj");
}
function getXPath(node) {
var parent = node.parentNode;
if (!parent) {
return "";
}
var siblings = parent.childNodes;
var totalCount = 0;
var thisCount = -1;
for (var i=0;i1 ? "[" + thisCount + "]" : "" );
}
//////////////////////////// Module: View inner HTML
function viewInnerHtml() {
var targetPath = "top.mainFrame.document.documentElement.innerHTML";
try {
top.log("viewInnerHtml() called");
var innerHTML = eval(targetPath);
top.log("Got innerHTML length " + innerHTML.length);
var toHtml = top.toHtml(innerHTML);
top.log("Got toHtml length " + toHtml.length);
top.writeToWindow('Inner HTML of some page at some point',toHtml);
top.log("Wrote to window");
} catch (e) {
top.log(e);
whereDoesPathBreak(targetPath);
}
}
/////////////////////////// Library functions ///////////////////////////
function writeToFrame(frame,html) {
// if (frame.document.open()) {
frame.document.open();
frame.document.write(""); // you need /some/ kind of surrounding tag if you are just writing text
frame.document.write(html);
frame.document.write(""); // these tags seemed sensible to me
frame.document.close();
// } else {
// try {
// frame.location = "about:blank";
// } catch (e) {
// alert("Setting "+frame+".location to blank threw: "+e);
// }
// frame.document.body.innerHTML = html;
// }
}
function writeToWindow(title,contents,options) {
// var w = window.open('about:blank','jsReflector','menubar,resizable,scrollbars,width=800,height=600');
//// 'about:blank' causes Konqueror to empty window after writing the yummy stuff, so...
if (!options) {
options = 'menubar,resizable,scrollbars,width=800,height=600';
}
var w = window.open('',title,options);
// Dammit something goes wrong here with Konqueror if it is put in mode (open new windows in new tab)
writeToFrame(w,contents);
// w.document.writeln('Generated XPath of selected HTML Element: ');
// w.document.open();
// w.document.write("");
// w.document.write(contents);
// w.document.write("");
// w.document.close();
w.focus();
w.jsReflectorShow = new Function(top.jsReflectorShow);
if (w.opener == null) // for older browsers, tell the child window we are the parent:
w.opener = self;
}
function escapeString(text) {
var map = new Array(); // TODO: more!
map['\n'] = "\\n";
map['\t'] = "\\t";
map['\"'] = "\\\"";
map['\\'] = "\\\\";
var str = "";
for (var i=0;i";
map[' '] = " ";
map['\"'] = """;
map['<'] = "<";
map['>'] = ">";
var html = "";
for (var i=0;i 100) {
return str.substring(0,100 - 3) + "...";
}
return str;
}
function trytypeof(obj) {
try {
var type = typeof(obj);
return type;
} catch (e) {
return "TYPE_ERROR: "+e;
}
}
function tryeval(code) {
try {
var res = eval(code);
return res;
} catch (e) {
return "EVAL_ERROR: "+e;
}
}
function splitAt(str,srch) {
var list = new Array();
var i = 0;
while (true) {
var j = str.indexOf(srch);
if (j < 0)
break;
list[i] = str.substring(0,j);
str = str.substring(j + 1);
i++;
}
list[i] = str;
return list;
}
function sortLines(linesStr) {
var lines = splitAt(linesStr,'\n');
lines = lines.sort();
return lines.join("\n");
/*
var lines = splitAt(linesStr,'\n');
linesStr = ""; // can wait till later but why not save memory?!
// bubblesort
for (var start = 0; start lines[i + 1]) {
// if (lines[i].compareTo(lines[i + 1]) > 0) {
// if (false) {
if (!areOrderedStrings(lines[i],lines[i + 1])) {
// alert("Swapping " + i + " and " + (i + 1) + "." );
var tmp = lines[i];
lines[i] = lines[i + 1];
lines[i + 1] = tmp;
}
}
}
for (var i = 0; i= 0);
/*
for (var i=0;i= b.length) return false;
if (a.charAt(i) < b.charAt(i)) return true;
if (a.charAt(i) > b.charAt(i)) return false;
}
return true; // b is either identical or longer
*/
}
// From starfield3dj10.html:
function doNothing(context,node) {
return context;
}
// Note: possible difference in implementation: if context is always going to be a reference to an object (as opposed to a primitive), then it needn't be passed back by the action functions.
function onAllNodesDo(node,context,actionBefore,actionAfter) {
// TODO: if context is observably null, then needn't pass to actionBefore/After (which in turn shouldn't/needn't accept it). Note change to doNothing required too!
context = actionBefore(context,node);
var kids = node.childNodes;
for (var i=0;i
If you don't have Javascript, you're not getting in.