|
9 | 9 | const weakSet = new WeakSet(); |
10 | 10 | const pathRouter = ["root"]; |
11 | 11 | const regexp = /以熔体流动速率/; |
| 12 | +const log = console.table; |
| 13 | + |
| 14 | +const isKeywords = (key, value) => { |
| 15 | + return ( |
| 16 | + value instanceof Node || |
| 17 | + value instanceof Window || |
| 18 | + key.includes("_react") || |
| 19 | + key.includes("cssRule") || |
| 20 | + key.includes("previousSibling") || |
| 21 | + key.includes("nextSibling") || |
| 22 | + key.includes("previousElementSibling") || |
| 23 | + key.includes("nextElementSibling") |
| 24 | + ); |
| 25 | +}; |
12 | 26 |
|
13 | 27 | const deepScanObject = (origin, deep, maxDeep) => { |
14 | | - if (deep > maxDeep) return; |
15 | | - if (origin instanceof Map) { |
16 | | - weakSet.add(origin); |
17 | | - if (weakSet.has(origin)) return; |
18 | | - origin = [...origin.entries()]; |
19 | | - } |
20 | | - for (const item in origin) { |
21 | | - const currentPath = pathRouter.join("/") + "/" + item; |
| 28 | + if (deep > maxDeep || weakSet.has(origin) || ArrayBuffer.isView(origin)) return; |
| 29 | + if (origin instanceof Map) origin = [...origin.entries()]; |
| 30 | + for (const _item in origin) { |
| 31 | + const currentPath = pathRouter.join("/") + "/" + _item; |
22 | 32 | try { |
| 33 | + const item = String(_item); |
23 | 34 | const value = origin[item]; |
24 | | - if ( |
25 | | - value instanceof Node || |
26 | | - value instanceof Window || |
27 | | - item.includes("_react") || |
28 | | - item.includes("cssRule") |
29 | | - ) { |
30 | | - continue; |
31 | | - } |
| 35 | + if (isKeywords(item, value)) continue; |
32 | 36 | if (value && typeof value === "object") { |
33 | | - if (weakSet.has(value)) { |
34 | | - regexp.test(item) && console.log(currentPath); |
35 | | - continue; |
36 | | - } |
37 | | - weakSet.add(value); |
| 37 | + regexp.test(item) && log(currentPath, "===>", value); |
| 38 | + if (weakSet.has(value)) continue; |
38 | 39 | pathRouter.push(item); |
39 | 40 | deepScanObject(value, deep + 1, maxDeep); |
| 41 | + weakSet.add(value); |
40 | 42 | pathRouter.pop(); |
41 | | - } else { |
42 | | - if (regexp.test(item) || regexp.test(value)) { |
43 | | - console.log(currentPath, "================", value); |
44 | | - } |
| 43 | + } else if (regexp.test(item) || regexp.test(String(value))) { |
| 44 | + if (typeof value === "function") continue; |
| 45 | + log(currentPath, "===>", value); |
45 | 46 | } |
46 | 47 | } catch (e) { |
47 | | - console.warn(e); |
| 48 | + log("warn", "--->", e); |
48 | 49 | } |
49 | 50 | } |
50 | 51 | }; |
51 | 52 |
|
52 | 53 | deepScanObject.toString = () => ""; |
53 | | -console.log("start"); |
| 54 | +log("start"); |
54 | 55 | deepScanObject(window, 0, 10); |
55 | | -console.log("finish"); |
| 56 | +log("finish"); |
56 | 57 |
|
57 | 58 | // =========================================================================== // |
58 | 59 |
|
|
0 commit comments