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 | (function(global){ function handleConnect(e) { try { if(e.ports && e.ports[0]) { e.ports[0].onmessage = handleMessage(e.ports[0]); } } catch(e) { } } function handleMessage(o) { return function(e) { if(e.data.indexOf('start') > -1) { var str = '<table width="100%" border="1" cellspacing="0" cellpadding="2">\n'; for (var i in global) { if(i!=='onconnect') { str += '<tr><td style="background: #AABBCC">' + i + '</td><td style="background: #DDEEFF">' + global[i] + '</td></tr>\n'; } else { str += '<tr><td style="background: #AABBCC">' + i + '</td><td style="background: #DDEEFF">onconnect eventHandler</td></tr>\n'; } } str += '</table>\n'; o.postMessage(str); } }; } global.onconnect = handleConnect; })(this); |
Direct link: https://paste.plurk.com/show/325395