Use let or const to avoid scope issues and hoisting
var MemoryStats = function (){
1/**2 * @author mrdoob / http://mrdoob.com/3 * @author jetienne / http://jetienne.com/4 * @author paulirish / http://paulirish.com/5 */6var MemoryStats = function (){78 var msMin = 100;9 var msMax = 0;1011 var container = document.createElement( 'div' );12 container.id = 'stats';13 container.style.cssText = 'width:80px;opacity:0.9;cursor:pointer';1415 var msDiv = document.createElement( 'div' );16 msDiv.id = 'ms';17 msDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;';18 container.appendChild( msDiv );1920 var msText = document.createElement( 'div' );21 msText.id = 'msText';22 msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';23 msText.innerHTML= 'Memory';24 msDiv.appendChild( msText );2526 var msGraph = document.createElement( 'div' );27 msGraph.id = 'msGraph';28 msGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0';29 msDiv.appendChild( msGraph );3031 while ( msGraph.children.length < 74 ) {3233 var bar = document.createElement( 'span' );34 bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#131';35 msGraph.appendChild( bar );3637 }3839 var updateGraph = function ( dom, height, color ) {4041 var child = dom.appendChild( dom.firstChild );42 child.style.height = height + 'px';43 if( color ) child.style.backgroundColor = color;4445 }4647 var perf = window.performance || {};48 // polyfill usedJSHeapSize49 if (!perf.memory){50 perf.memory = { usedJSHeapSize : 0 };51 }5253 // support of the API?54 if( perf.memory.totalJSHeapSize === 0 ){55 console.warn('totalJSHeapSize === 0... performance.memory is only available in Chrome .')56 }5758 // TODO, add a sanity check to see if values are bucketed.59 // If so, remind user to adopt the --enable-precise-memory-info flag.60 // open -a "/Applications/Google Chrome.app" --args --enable-precise-memory-info6162 var lastTime = Date.now();63 var lastUsedHeap= perf.memory.usedJSHeapSize;64 return {65 domElement: container,6667 update: function () {6869 // refresh only 30time per second70 if( Date.now() - lastTime < 1000/30 ) return;71 lastTime = Date.now()7273 var delta = perf.memory.usedJSHeapSize - lastUsedHeap;74 lastUsedHeap = perf.memory.usedJSHeapSize;75 var color = delta < 0 ? '#830' : '#131';7677 var ms = perf.memory.usedJSHeapSize;78 msMin = Math.min( msMin, ms );79 msMax = Math.max( msMax, ms );80 msText.textContent = "Mem: " + bytesToSize(ms, 2);8182 var normValue = ms / (30*1024*1024);83 var height = Math.min( 30, 30 - normValue * 30 );84 updateGraph( msGraph, height, color);8586 function bytesToSize( bytes, nFractDigit ){87 var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];88 if (bytes == 0) return 'n/a';89 nFractDigit = nFractDigit !== undefined ? nFractDigit : 0;90 var precision = Math.pow(10, nFractDigit);91 var i = Math.floor(Math.log(bytes) / Math.log(1024));92 return Math.round(bytes*precision / Math.pow(1024, i))/precision + ' ' + sizes[i];93 };94 }9596 }9798};
Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.