Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Object.prototype.toString = function dogToString() {
  2.     return logObject(this);
  3. }
  4.  
  5. global.logObject = function(obj, depth, currentDepth, isRoot)
  6. {
  7.     if(isRoot == undefined) {isRoot = true; currentDepth = 0; obj = JSON.parse(JSON.stringify(obj))};
  8.     if(depth != undefined && depth <= currentDepth)
  9.     {
  10.         return '...';
  11.     }
  12.  
  13.     var str = "";
  14.  
  15.     if(isRoot)
  16.     {
  17.         str = '<style>details[open] > summary {background-color: rgba(255,255,255,0.1);} summary:hover {cursor: pointer;} details div, details summary {padding-left: 25px;} .singleline:hover{background-color: rgba(255,255,255,0.1);} details {width:100%;}</style><details><summary class="singleline">LogObject Out:</summary><div>';
  18.     }
  19.  
  20.     var index = 0;
  21.  
  22.     for(var name in obj)
  23.     {
  24.         if(typeof(obj[name]) == 'object')
  25.         {
  26.             //Subdaten scan
  27.  
  28.             var count = 0;
  29.  
  30.             for(var name2 in obj[name])
  31.             {
  32.                 count++;
  33.             }
  34.  
  35.             str += '<details><summary class="singleline">' + name + ' (' + count + ')</summary><div>';
  36.             str += logObject(obj[name], depth, currentDepth + 1, false);
  37.             str += '</div></details>';
  38.         }
  39.         else
  40.         {
  41.             str += '<div class="singleline">' + name + ': ' + obj[name] + '</div>';
  42.         }
  43.  
  44.         index++;
  45.     }
  46.  
  47.     if(index == 0)
  48.     {
  49.         str += '<div>(empty)</div>';
  50.     }
  51.  
  52.  
  53.     if(isRoot)
  54.     {
  55.         str += '</div></details>';
  56.         return str;//console.log(str);
  57.     }
  58.     return str;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement