Skip to content

Instantly share code, notes, and snippets.

@lukegalea
Created March 16, 2011 13:46
Show Gist options
  • Save lukegalea/872514 to your computer and use it in GitHub Desktop.
Save lukegalea/872514 to your computer and use it in GitHub Desktop.
Panopticon JS
// The Panopticon is a type of prison building designed by English philosopher and social theorist Jeremy Bentham in 1785.
// The concept of the design is to allow an observer to observe (-opticon) all (pan-) prisoners without the incarcerated being able to tell whether they are being watched,
// thereby conveying what one architect has called the "sentiment of an invisible omniscience."
// Bentham himself described the Panopticon as "a new mode of obtaining power of mind over mind, in a quantity hitherto without example."
var lastAction = new Date(),
timeoutMins = 2,
keepAliveMins = 1,
timeoutEvent,
keepAliveEvent,
debugLog = function(msg) {
$('<p>' + msg + '</p>').appendTo($('div#debug'));
},
updateTimeouts = function() {
if (timeoutEvent) {
clearTimeout(timeoutEvent);
}
timeoutEvent = setTimeout(noAction, timeoutMins * 60 * 1000);
if (!keepAliveEvent) {
debugLog("Activating Keep Alive");
// Quickly fire off one right now so they don't have to wait
doKeepAlive();
keepAliveEvent = setTimeout(doKeepAlive, keepAliveMins * 60 * 1000);
}
},
updateLastAction = function(e) {
lastAction = new Date();
updateTimeouts();
},
// This means they haven't moved in a while, shut 'em down
noAction = function() {
clearInterval(keepAliveEvent);
keepAliveEvent = null;
debugLog("Timeout");
},
doKeepAlive = function() {
debugLog("Keeping Alive");
},
panopticonWatch = function() {
debugLog("Starting up");
$(window.document).mousemove(updateLastAction);
$(window.document).keypress(updateLastAction);
updateTimeouts();
};
$(document).ready(panopticonWatch);
@lukegalea
Copy link
Author

<html>
  <head>
    <script src="javascripts/jquery_bundle.js"></script>
    <script src="javascripts/panopticon.js"></script>
  </head>
  <body>
    <h3 id="watcher">You are being watched</h3>
    <div id="debug"></div>
  </body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment