Add Counter #4

Closed
amovah wants to merge 7 commits from master into master
5 changed files with 47 additions and 4 deletions

View File

@ -510,3 +510,12 @@ a[href="#"].running {
background-color: rgba(255, 255, 255, 0.2);
color: white;
}
.counter {
padding: 10px;
position: fixed;
left: 0px;
bottom: 0px;
}
.counter p {
font-size: 20px;
}

View File

@ -191,3 +191,12 @@ a[href="#"].running {
background-color: rgba(255, 255, 255, 0.2);
color: white;
}
.counter {
padding: 10px;
position: fixed;
left: 0px;
bottom: 0px;
}
.counter p {
font-size: 20px;
}

View File

@ -1,3 +1,5 @@
var socket = io();
var $run = $('h1, h3, .options, a');
$('li[contenteditable]').click(function(e) {
@ -39,3 +41,7 @@ function success(ipsum) {
selection.removeAllRanges();
selection.addRange(range);
}
socket.on('counter', function(count) {
$('#count').text(count);
});

1
count.json Normal file
View File

@ -0,0 +1 @@
0

View File

@ -1,7 +1,12 @@
var express = require('express'),
app = express();
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server),
fs = require('fs');
app.use(express.static(__dirname + '/ipsum', {maxAge: 60*60*24*7}));
var count = require('./count.json');
app.use(express.static(__dirname + '/client', {maxAge: 60*60*24*7}));
module.exports.app = app;
@ -87,6 +92,19 @@ function loremipsum(data) {
}
}
function go(url) {
var req = url.split('/');
return loremipsum(req.slice(1));
var lorem = loremipsum(url.split('/').slice(1));
counting(lorem);
return lorem;
}
//COUNTER
io.on('connection', function(socket) {
io.emit('counter', count);
});
function counting(data) {
var r = data.split(' ').join('').length + count;
fs.writeFile(__dirname + '/count.json', r, function() {
count = +(fs.readFileSync(__dirname + '/count.json', 'utf8'));
})
io.emit('counter', r);
}