Advertisement
Guest User

js parse

a guest
Feb 25th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. (() => {
  3.     let idx = 0
  4.     let isEnd = false
  5.     let full_list = [document]
  6.     let find_names = ["claim", "claimID"]
  7.  
  8.     function parse(obj, obj_name, line_names=[]) {
  9.         if(isEnd) return        
  10.         if(obj == null) return
  11.         if(typeof obj != "object") return        
  12.         if(['ServiceWorkerContainer'].includes(obj_name)) return
  13.         if(full_list.includes(obj)) return        
  14.        
  15.         full_list.push(obj)
  16.         line_names.push(obj_name)
  17.         idx += 1;
  18.         if(idx % 1000 == 0) {
  19.             console.log("idx:", idx)
  20.             // console.log(line_names)
  21.             // setTimeout(() => {
  22.             //     parse(obj, obj_name, line_names)
  23.             // }, 100)
  24.             // return
  25.         }
  26.  
  27.         if(find_names.includes(obj_name)) {
  28.             console.log("============== FIND SUCCESS ==============")
  29.             console.log(line_names)
  30.             isEnd = true
  31.             return
  32.         }
  33.  
  34.         for(let child_name in obj) {
  35.            
  36.             let _child_obj = null
  37.             try {
  38.                 _child_obj = obj[child_name]                
  39.                 if(_child_obj != null && typeof _child_obj.then === 'function'){
  40.                     _child_obj.then((x) => {
  41.                         parse(x, child_name, line_names)
  42.                     })
  43.                     continue
  44.                 }
  45.             } catch (error) {}            
  46.  
  47.             if(_child_obj != null){
  48.                 parse(_child_obj, child_name, line_names)
  49.             }
  50.  
  51.             if(isEnd) return
  52.         }
  53.        
  54.         let _proto = null        
  55.         try {
  56.             _proto = obj.__proto__
  57.         } catch (error) {}
  58.         if (_proto!=null){
  59.             parse(_proto, "__proto__", line_names)
  60.         }
  61.        
  62.         line_names.splice(-1,1)
  63.     }
  64.  
  65.     parse(window, 'window')
  66.  
  67. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement