forked from johnwun/js4ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explore.js
122 lines (111 loc) · 3.31 KB
/
explore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/////////////////////////////////////////////////////////////////
// The Document Object Model Explorer v.2 -- CS
//>=--------------------------------------
//
// Select an object on the page, then run this script.
// It will return a list of everything that object contains.
// You can also manually explore the document object model by entering an object's path.
//
// As of version 2, a "displayErrors" variable has been added.
// Now users can view objects that failed.
// "displayErrors" defaults to true, but can be turned off by
// setting it to "0" in the first line of the script.
//
// Output is also now alphabetized, and is broken into multiple alerts if output is
// longer than the "maxLines" variable.
//
// Prompt can now be used as a javascript command line too.
// If user input returns a value, the value is returned in an alert box.
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( [email protected] ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
var displayErrors = 1;
var maxLines = 50;
var bob = "";
var disp_ar = new Array();
//the item count object:
var c = 0;
var observed = prompt("What do you want to explore? i.e.;\r app (not used before CS)\r documents\r activeDocument.pageItems[0]","activeDocument.selection[0]");
//assign prompt text to actual object;
// a side effect of which is,
// if the user input is actually a line of executable code,
// it gets run here:
var thisObject = eval(observed);
try
{
for (all in thisObject )
{
c++;
//attempt to decypher each sub object
try
{
bob= all+"=";
bob+= eval(observed+"."+all);
disp_ar.push(bob);
}
catch (e)
{
// if undecypherable, say why:
if(displayErrors){
bob = all+"="+(e.toString().split(":"))[1];
disp_ar.push(bob);
}
}
disp_ar.sort();
}
//decide arbitrary max length of list before switching to tabs.
if(c>1){
// if object has more than one object content:
var nicedisp = "";
var dispLen = disp_ar.length;
// if longer than max, divide by the amount longer than max, so you don't
// end up with a dangling variable at the end.
var maxNum = dispLen>maxLines?dispLen/Math.ceil(dispLen/maxLines):maxLines;
var dispOutput = new Array("");
var more = "";
var myLoc = 0;
for (var x=0;x<dispLen;x++)
{
// add spacing for formatting of line numbers less that 10.
if(x<9 ){
spc = " ";
} else{
spc = "";
}
var thisMod = Math.ceil(x%maxNum);
if(thisMod==true && x>maxNum -1){
myLoc++;
//initialize array slot:
dispOutput[myLoc] = "";
}
dispOutput[myLoc]+=(spc+(x+1)+") "+disp_ar[x]+"\r");
}
//show output page(s):
var outLen = dispOutput.length;
for (var a=0;a<outLen;a++)
{
more = a<(outLen-1)?" More...":"";
alert("Contents of:\r"+observed+"\r------------------------\r"+dispOutput[a]+more);
}
}else{
alert("Value of:\r"+observed+"\r------------------------\r"+thisObject );
}
}
catch (e)
{
//if user is running code from command line, do nothing.
//if object returns something, show it:
if(thisObject!= undefined){
alert(thisObject);
}
}
//handle spacing for columns
function makeSpace(num){
spc = "";
for (var j=0;j<num ;j++ )
{
spc+="|";
}
return spc;
}