📄 objbrowser.js
字号:
// Otherwise call it a property and move on.
else aIndex = 1;
// Create a new object within the Objects[] array, to which we'll add data.
var aRef = Objects[aIndex][Objects[aIndex].length] = new Object();
aRef.type = objType;
aRef.name = propName;
// Now the hard bit... detect the value of the object, and set as aRef.value.
// Check if this property has a forced value, if it does set it and loop again.
if (JSObj.forceValues && JSObj.forceValues[propName]) aRef.value = forceValues[propName];
else
{
var str = '';
// Windows NT4 seems to crash on 'domain' for some reason under IE5.
// IE6 dies horribly when window.frameElement is a property too.
if ((propName != 'domain') && ((propName != 'frameElement') || (objType == 'object')))
{
var errStr = '????';
// IE4 seems to throw fits when being made to access innerHTML etc. So skip 'em.
if ((document.all && !document.getElementById) &&
(propName=='innerHTML' || propName=='innerText' || propName=='outerHTML' ||
propName=='outerText'))
str = errStr;
// OK, if the script is crashing about here, add this property to JSObj.forceValues
eval(tryString('str = new String(objRef[propName])', 'str = errStr'));
}
// Lose angle brackets, otherwise innerHTML etc. look really weird :).
str = str.replace(/</g, '<').replace(/>/g, '>');
// Trim it down and record the final value in the array.
if (str.length > 100) str = str.substring(0, 100) +
' <span style="font-weight: bold; color: #009900">...</span>';
aRef.value = str;
}
// Move onto next object in for() loop...
}
// All hands on deck for a dirty old Mozilla hack. Since some versions (1.2-1.3ish)
// won't list window.document, we really have to add it manually as it's pretty useful.
if (navigator.userAgent.indexOf('Gecko')>-1 && objRef && objRef.navigator)
{
var docFound = false;
for (var count = 0; count < Objects[0].length; count++)
if (Objects[0][count].name == 'document') { docFound = true; break }
if (!docFound) Objects[0][Objects[0].length] =
{ name:'document', type:'object', value:'[object HTMLDocument]' }
}
// Likewise, help out NS4 with some document.layers fakery.
if (objRef && objRef.layers)
{
var lyrFound = false;
for (var count = 0; count < Objects[0].length; count++)
if (Objects[0][count].name == 'layers') { lyrFound = true; break }
if (!lyrFound) Objects[0][Objects[0].length] =
{ name:'layers', type:'object', value:'[object LayerArray]' }
}
// *** WRITE HEADING OF OUTPUT WINDOW ***
// Find our output document. Opera 7.01 and 7.02 are a bit stupid and throw security errors
// when I attempt to write to "outF.document", so here's a workaround using the neat old
// DOM getElementsByName function (ironically, I used this script to get the right one :).
var doc = window.opera ? document.getElementsByName('outF')[0].contentDocument : outF.document;
// Clear anything already written to output document.
doc.close();
doc.open('text/html');
// The title of this frameset document, not the output frame.
document.title = objText + ' - Object Model Browser';
doc.writeln('<html>\n<head>\n<title>'+document.title+'</title>\n' +
'<style type="text/css"><!--\n' +
' td { font: 8pt/10pt Verdana, Arial }\n' +
' .prop { color: #000099; text-decoration: none }\n' +
'--></style>\n</head>\n');
// Start the body, and prepare to write the top links...
// Yeah, I know the marginxyz attributes aren't kosher, but NS4 doesn't like CSS much.
doc.writeln('<body onLoad="document.forms.goTo.text.select()" ' +
'marginwidth="10" marginheight="10" leftmargin="10" topmargin="10">');
doc.writeln('<div align="center">\n');
doc.writeln('<h2>\n Object:');
// Split up object name into array of pieces...
var objSplit = objText.split('.');
var wholeName = '';
for (var count = 0; count < objSplit.length; count++)
{
// ...And recombine bit by bit.
wholeName += objSplit[count];
doc.write('<a href="javascript:parent.JSObj.browse(\'' + wholeName + '\', ' +
getSafeObj(preObj + wholeName) + ')">' + objSplit[count] + '</a>');
if (objSplit[count + 1])
{
doc.write('.');
wholeName += '.';
}
}
doc.writeln('\n</h2>\n');
// Don't want form resubmitting, so call objBrowse function & return false.
// Pass only the text, the reference will be sorted out by this function.
doc.writeln('<form name="goTo" onSubmit="setTimeout(\'parent.JSObj.browse(' +
'document.forms.goTo.text.value)\', 10); return false">\n' +
' <b>Go To:</b> <input name="text" type="text" size="50" value="' + objText + '">\n' +
' <input type="submit" value="Go / Refresh">\n</form>\n');
// *** DISPLAY THE OBJECT TYPES IN A TABLE ***
// Define colours used for properties.
var propCols = new Object();
// Define the colours used for various object types.
// NS4 doesn't like setting propCols.boolean as it's kind of a reserved word :).
propCols['string'] = '#990000';
propCols['number'] = '#006600';
propCols['boolean'] = '#000099';
//alert('Writing the properties...');
doc.writeln('<table border="1" cellpadding="1" cellspacing="1">');
for (var objType = 0; objType < 3; objType++)
{
// Write grey table heading using catNames[]
doc.writeln(' <tr><td colspan="2" bgcolor="#CCCCCC" align="center"><b>' + catNames[objType] +
'</b></td></tr>');
// Sort them into alphabetical order then loop through.
// Don't apply sort to collections (.length property), but do apply to windows.
if (objRef && (!objRef.length||objRef.navigator))
Objects[objType].sort(new Function('a', 'b',
'return (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1)'));
// No objects in this category?
if (!Objects[objType].length)
{
doc.writeln(' <tr><td colspan="2" align="center">There are no indexed ' + catNames[objType] +
' for this Object.</td></tr>');
}
else for (var propCount = 0; propCount < Objects[objType].length; propCount++)
{
// Reference to this array entry, and set propName for debugging help.
var propName = Objects[objType][propCount].name;
// Write out a table row, first cell containing object's proper name (skip leading chars).
wholeName = objText + '.' + Objects[objType][propCount].name;
doc.write(' <tr><td>');
if (objType == 0)
{
// It's an object, so write a link tag, we can browse into this.
doc.write('<a href="javascript:parent.JSObj.browse(\'' + wholeName +
'\', ' + getSafeObj(preObj + wholeName) + ')">' + wholeName + '</a>');
}
else
{
// Just write the name, it's a property or event handler.
doc.write('<a class="prop" href="javascript:parent.JSObj.alterProp(\'' + wholeName +
'\')">' + wholeName + '</a>');
}
// Write its value from the array -- use a space for empty objects.
with (Objects[objType][propCount])
doc.writeln('</td><td ' +
((type && objType==1) ? 'style="color: '+propCols[type]+'"' : '') + '>' +
((value != '') ? value : ' ') + '</td></tr>')
}
}
// Page footer.
doc.writeln('</table>\n\n<form name="openFile" onSubmit="setTimeout(\'' +
'parent.JSObj.loadURL(document.forms.openFile.fileName.value)\', 10); return false">\n' +
' Open: <input name="fileName" type="file"></input>\n' +
' <input type="submit" value="Open Selection..."></input>\n</form>\n');
// Let's give us the ability to type in some JavaScript.
doc.writeln('<form onsubmit="with (this.txt){'+preObj+'eval(value);focus();select();' +
'return false}">\n JavaScript eval(): <input name="txt" type="text" size="50"></input>\n</form>\n');
// The bookmarklet link, use double quotes for obvious reasons here.
var bkmk = "javascript:var JSObjPath='file:///C:/Windows/JSObj.js';"+
"with(window.open('','','menubar=1,toolbar=1,location=0,status=1,scrollbars=1,resizable=1').document)"+
"{open('text/html');write('<html><script type=\\\'text/javascript\\\' src=\\\''+JSObjPath+'\\\'></script>"+
"<noframes>Error, JSOBJ.JS cannot be located!</noframes></html>');close()}";
doc.writeln('<p><a href="'+bkmk+'" onclick="alert(\'To use: Drag onto links toolbar or bookmarks.\\n' +
'Click OK to the warning, then edit the link to point at the correct JSOBJ.JS file.\\n' +
'You can then click that link to browse the DOM of any page on any domain.\'); return false">' +
'JSObj</a> (bookmarklet; click for instructions).</p>\n');
doc.writeln('\n</div>\n</body>\n</html>');
// That's it, tell browser it's finally 'loaded'.
doc.close();
}}
// *** OPEN A CHILD WINDOW TO BROWSE ***
JSObj.loadURL = function(fName) { with (this)
{
// Fix up the URL for Netscape 4.
if ((fName.substring(0,4) != 'http') && (fName.substring(0,4) != 'file'))
fName = 'file:///' +fName;
// Open a window there, set it as the root for browsing, and browse it.
top.JSObjWin = top.open(fName,'',
'menubar=yes,toolbar=yes,location=yes,directories=no,status=yes,resizable=yes,scrollbars=yes');
preObj = 'top.JSObjWin.';
browse('window');
}}
// *** PROPERTY CLICK HANDLER ***
// Gets the new value for a property, sets it, then refreshes.
JSObj.alterProp = function(objText) { with (this)
{
var newVal = prompt('Enter new value for: ' + objText, eval(getSafeObj(preObj + objText)));
if (typeof newVal == 'string')
{
// Parse the full text into object/property and get reference.
var objName = objText.substring(0, objText.lastIndexOf('.'));
var propName = objText.substring(objText.lastIndexOf('.') + 1);
var objRef = eval(getSafeObj(preObj + objName));
// Now decide what type we're setting -- use string only as the default.
if (newVal == parseFloat(newVal).toString()) objRef[propName] = parseFloat(newVal);
else if (newVal=='true') objRef[propName] = true;
else if (newVal=='false') objRef[propName] = false;
else if (newVal=='null') objRef[propName] = null;
else objRef[propName] = newVal;
browse(objName);
}
}}
// *** MAIN SCRIPT EXECUTION STARTS HERE ***
// *** IE CONTEXT MENU COMPATIBILITY ***
if (document.all && window.external && external.menuArguments && external.menuArguments!=self)
{
// Instructs the caller to open a new window to this location so top.opener
// is detected next time, then exit as this connection is not persistent.
external.menuArguments.open(window.location.href, '',
'menubar=1,toolbar=1,location=0,status=1,scrollbars=1,resizable=1');
}
// *** OTHERWISE START OBJECT BROWSER SCRIPT WITH FRAMESET ***
else
{
// Create a frameset within the current document, which will run the browse function onload.
document.write('<frameset rows="100%,*" resizable="no" frameborder="0" border="0" ' +
'onload="JSObj.browse(\'window\')"><frame name="outF" src="about:blank"></frame>\n</frameset>');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -