Created
April 26, 2013 04:52
-
-
Save davidfowl/5465096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addUser(name, room, active, owner) { | |
| var user = { | |
| name: name, | |
| hash: null, | |
| owner: owner, | |
| active: active, | |
| noteClass: '', | |
| note: 'This is a note', | |
| flagClass: '', | |
| flag: 'bb', | |
| country: 'Barbados', | |
| lastActive: new Date(), | |
| timeAgo: $.timeago(new Date()), | |
| admin: false | |
| }; | |
| window.chat.ui.addUser(user, room); | |
| } | |
| function removeUser(name, room) { | |
| window.chat.ui.removeUser({Name: name}, room) | |
| } | |
| function isOwner(n) { | |
| return n < 3; | |
| } | |
| function isActive(n) { | |
| return getRandomInt(0, n) > (n/2); | |
| } | |
| function randomActivity(maxUsers, room) | |
| { | |
| var index = getRandomInt(0, maxUsers); | |
| if(getRandomInt(0, 1) === 1) { | |
| addUser("user_" + index, room, isActive(index), isOwner(index), room); | |
| } | |
| else { | |
| removeUser("user_" + index, room); | |
| } | |
| var nextInterval = Math.round(Math.random() * (1000 - 500)) + 500; | |
| setTimeout(function() { | |
| randomActivity(maxUsers, room); | |
| }, | |
| nextInterval); | |
| } | |
| function getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } | |
| randomActivity(300, "newRoom") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment