-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchrome-dumper.js
132 lines (116 loc) · 4.28 KB
/
chrome-dumper.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
123
124
125
126
127
128
129
130
131
132
/************************************
* Fast's JS Global Variable Dumper *
* Chrome Console Edition *
************************************/
// version 2
var dumper = {
isCursedKey: (key) => key.match(/[^(a-z|$|_|A-Z)]/),
justify: (string,value) => (string + "\t".repeat(Math.max(0,Math.ceil((value-string.length)/4)))),
isBanned: (key) => key == "window.dumper" || dumper.includesPartial(dumper.BANNED_KEYS,key), // pls don't remove hardcoded values from here
};
/* HOW TO USE:
Paste in chrome console and hit enter. Take care if you set the max search depth really high.
*/
dumper.BANNED_KEYS = ["document"]; // traversal will stop at these keys
dumper.MAX_SEARCH_DEPTH = 10; // max recursive depth to search
dumper.MAX_SEARCH_WIDTH = 100; // any object besides window with more objects stored under it than this will be ignored.
dumper.IGNORE_NATIVE_FUNCS = true; // don't dump native JS
dumper.LIST_GROUPING_MODE = console.groupCollapsed // can be changed to console.group, but not reccommended
dumper.COLORS = { // inspired by Wiremod's Expression 2 Language in Garry's Mod
string: "color: #999999;",
number: "color: #ff6666;",
bigint: "color: #a45b5b;",
boolean: "color: #668cff;",
symbol: "color: #fbfb51;",
object: "color: #80ff80;",
array: "color: #80ff80;",
undefined: "color: #ffb56b;",
function: "color: #fc83fc;",
};
dumper.getPath = function(path,key){
if( dumper.isCursedKey(key) ){
if( parseInt(key) != NaN ){ // int
return `${path}[${key}]`
}
else{ // something nasty
return `${path}[\`${key}\`]`
}
}
else{
return `${path}.${key}`;
}
}
dumper.includesPartial = function(strings,string){
for (const key in strings) {
if(string.includes(strings[key])){ return true; }
}
return false;
};
// call this on any value and leave location blank to print advanced data about it
dumper.advLog = function(thing,path,mode){
let type = typeof(thing);
let value = "failed..."
try{
switch(type){
case 'symbol': value = thing.valueOf(); break; // ugh
case 'string': value = `"${thing}"`; break;
case 'function':
value = (thing + "").match(/(function\s*)([^\)]*\(.+)/);
if(value){ value = value[2] }
break;
case 'object':
value = thing + ""
if(!value.startsWith("[")){
value = `[...]`
type = "array";
}
break;
default: value = thing + "";
}
}
finally{}
if(path){
dumper.advLog[mode]( `${path} = %c${type} %c${value}`, "color: #ff944d;", dumper.COLORS[type] )
}
else{
dumper.advLog[mode]( `%c${type} %c${value}`, "color: #ff944d;", dumper.COLORS[type] )
}
}
dumper.advLog.undefined = console.log
dumper.advLog.true = dumper.LIST_GROUPING_MODE
dumper.recurse = function(obj, path, depth=0, refs=new WeakSet()) {
if( depth > dumper.MAX_SEARCH_DEPTH ){ return; }
// Avoid infinite recursion
if(refs.has(obj)){ return; }
else if( obj!=null ){ refs.add(obj); }
dumper.advLog(obj, path, true);
bruh: for (const key in obj) {
try{
let value = obj[key]; // if we hit a css sheet this will throw an exception
if( value === null ){ continue; } // skip null
if( value.window ){ continue; } // no.
let type = typeof(value);
let newpath = dumper.getPath(path,key);
switch(type){
case 'function':
if( dumper.IGNORE_NATIVE_FUNCS && (value+"").includes("[native code]") ){
continue bruh;
}
case 'object':
if( dumper.isBanned(newpath) ){
continue bruh;
}
dumper.recurse(value, newpath, depth+1, refs);
break;
default:
dumper.advLog(value, newpath)
break;
}
}
catch(e){
console.error(e);
}
}
console.groupEnd();
};
dumper.recurse(window,"window")