Difference between revisions of "Widget:Pamela"

From Whitespace (Hackerspace Gent)
Jump to: navigation, search
m
Line 1: Line 1:
<includeonly>
+
<noinclude>
 +
<div style="width: 845px;">
 +
  <div style="text-align:center;">[[File:Ws-banner.jpg]]</div>
 +
  <div id="openbanner">The space is open!</div>
 +
</div>
 +
</noinclude>
 
<div id="pamelaWidget">Loading <a href='http://0x20.be/Pamela'>Pamela</a>...</div>
 
<div id="pamelaWidget">Loading <a href='http://0x20.be/Pamela'>Pamela</a>...</div>
 
<script type="text/javascript">
 
<script type="text/javascript">
Line 47: Line 52:
 
LoadPamelaCountWidget();
 
LoadPamelaCountWidget();
 
</script>
 
</script>
</includeonly>
 

Revision as of 23:08, 14 January 2011

Ws-banner.jpg
The space is open!
Loading <a href='http://0x20.be/Pamela'>Pamela</a>...

<script type="text/javascript"> var xmlHttp = null;

function LoadPamelaCountWidget() {

   var Url = window.location.protocol + "//0x20.be/pam/macs";
   xmlHttp = new XMLHttpRequest();
   xmlHttp.onreadystatechange = ProcessRequest;
   xmlHttp.open( "GET", Url, true );
   xmlHttp.send( null );
   setTimeout( function() { LoadPamelaCountWidget(); }, 60000 );

}

function ProcessRequest() {

   var macs, i;
   if ( !(xmlHttp.readyState == 4 && xmlHttp.status == 200))
       return;
   if ( xmlHttp.responseText == "Not found" )
       return;
   var macs = eval ( "(" + xmlHttp.responseText + ")" );
   var people = [];
   var services = [];
   for (i = macs.length -1; i >= 0; i--) {
       if (macs[i].indexOf('(') != -1) {
           services.push('' + macs[i] + '');
       }
       else if ( macs[i].split( ':' ).length == 6 ) {
           people.push(macs[i]);
       }
       else {
           people.unshift(macs[i]);
       }
   }
   document.getElementById('openbanner').style.display = people.length > 0 ? 'block' : 'none';
   document.getElementById( "pamelaWidget" ).innerHTML = "According to <a href='" + window.location.protocol + "//0x20.be/Pamela'>Pamela</a> there are " + macs.length + " devices active in the space: " + people.concat(services).join( ", " );

}

LoadPamelaCountWidget(); </script>