Difference between revisions of "Widget:Pamela"

From Whitespace (Hackerspace Gent)
Jump to: navigation, search
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
 +
<nowiki>
 
<div style="width: 845px;">
 
<div style="width: 845px;">
 
   <a href="https://0x20.be/pam" alt="graphical presentation of all users present in the space" ><div id="openbanner">The space is open!</div></a>
 
   <a href="https://0x20.be/pam" alt="graphical presentation of all users present in the space" ><div id="openbanner">The space is open!</div></a>
 
</div>
 
</div>
 +
<nowiki>
 
{{#widget:Pamela}}</noinclude><includeonly>
 
{{#widget:Pamela}}</noinclude><includeonly>
 
<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>

Revision as of 18:49, 13 February 2011

<div style="width: 845px;"> <a href="https://0x20.be/pam" alt="graphical presentation of all users present in the space" ><div id="openbanner">The space is open!</div></a> </div> <nowiki> {{#widget:Pamela}}</noinclude><includeonly> <div id="pamelaWidget">Loading <a href='http://0x20.be/Pamela'>Pamela</a>...</div> <script type="text/javascript"> var xmlHttp = null; function LoadPamelaCountWidget() { var Url = window.location.protocol + "//0x20.be/pam/data"; xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = ProcessRequest; xmlHttp.open( "GET", Url, true ); xmlHttp.send( null ); setTimeout( function() { LoadPamelaCountWidget(); }, 60000 ); } function ProcessRequest() { var data, i; var pamTalkPeople = ['is nobody', 'is one person', 'are two people', 'are three people', 'are four people', 'are five people']; var pamTalkMachines = ['are no machines', 'is one machine', 'are two machines', 'are three machines', 'are four machines', 'are five machines']; if ( !(xmlHttp.readyState == 4 && xmlHttp.status == 200)) return; if ( xmlHttp.responseText == "Not found" ) return; var data = eval ( "(" + xmlHttp.responseText + ")" ); var people = []; var services = []; var entities = []; for (i = data.length -1; i >= 0; i--) { if (data[i].indexOf('(') != -1) { services.push('<span style="color:darkgray">' + data[i] + '</span>'); } else if (data[i].split( ':' ).length == 6) { entities.push(data[i]); } // Hack please remove once the pamela db has been fixed else if (data[i] == 'the cable guy') { services.push('<span style="color:darkgray">' + data[i] + '</span>'); } // End of code to remove else { people.unshift('<a href="' + window.location.protocol + '//0x20.be/' + data[i] + '">' + data[i] + '</a>'); } } document.getElementById('openbanner').style.display = people.length > 0 ? 'block' : 'none'; if ( data.length > 0 ) { var msg = ""; // Dealing with unknown entities if ( entities.length > 0 ) { msg = msg + "<span style='color:red'>WARNING: </span><span style='color:darkred'>According to <a href='" + window.location.protocol + "//0x20.be/Pamela'>Pamela</a> there "; if ( entities.length == 1 ) { msg = msg + "is 1 unknown entity"; } else { msg = msg + "are " + entities.length + " unknown entities"; } msg = msg + " present in Whitespace!!!<br><p style='text-align:center'>>> " + entities.join(", " ) + " <<</p></span>Further <a href='" + window.location.protocol + "//0x20.be/Pamela'>Pamela</a> says there "; } else { msg = msg + "According to <a href='" + window.location.protocol + "//0x20.be/Pamela'>Pamela</a> there " } // Dealing with people if ( people.length > 5 ) { msg = msg + " are " + people.length + " people"; } else { msg = msg + pamTalkPeople[people.length]; } msg = msg + " in the space"; if ( people.length > 0 ) { msg = msg + ", namely: " + people.join(", " ); } // Dealing with machines msg = msg + " and there " if ( services.length > 5 ) { msg = msg + " are " + services.length + " machines"; } else { msg = msg + pamTalkMachines[services.length]; } msg = msg + " active"; if ( services.length > 0 ) { msg = msg + ", namely: " + services.join(", " ); } msg = msg + "."; } else { var msg = "<span style='color:red'><b>THE WORLD EXPLODED!!! </b></span><span style='color:darkred'>According to <a href='" + window.location.protocol + "//0x20.be/Pamela'>Pamela</a> there's no man or machine left alive!!!</span>"; } document.getElementById( "pamelaWidget" ).innerHTML = msg; } LoadPamelaCountWidget(); </script> </includeonly>