Add counter
This commit is contained in:
parent
d16e6fb07e
commit
c9e8fa7433
1
counter.json
Normal file
1
counter.json
Normal file
@ -0,0 +1 @@
|
||||
0
|
20
ipsum.js
20
ipsum.js
@ -1,5 +1,13 @@
|
||||
var express = require('express'),
|
||||
<<<<<<< HEAD
|
||||
app = express(),
|
||||
server = require('http').Server(app),
|
||||
io = require('socket.io')(server),
|
||||
fs = require('fs'),
|
||||
counter = require('./counter.json');
|
||||
=======
|
||||
app = express();
|
||||
>>>>>>> d16e6fb07eb8765657af0e649b91101ff835a332
|
||||
|
||||
app.use(express.static(__dirname + '/client', {maxAge: 60*60*24*7}));
|
||||
|
||||
@ -87,6 +95,14 @@ function loremipsum(data) {
|
||||
}
|
||||
}
|
||||
function go(url) {
|
||||
var req = url.split('/');
|
||||
return loremipsum(req.slice(1));
|
||||
var ipsum = loremipsum(url.split('/').slice(1));
|
||||
counter += ipsum.split(' ').length;
|
||||
fs.writeFileSync('counter.json', counter);
|
||||
io.emit('counter', counter);
|
||||
return ipsum;
|
||||
}
|
||||
|
||||
/* COUNTER */
|
||||
io.on('connection', function(socket) {
|
||||
socket.emit('counter', counter);
|
||||
});
|
||||
|
@ -510,3 +510,11 @@ a[href="#"].running {
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.counter {
|
||||
position: absolute;
|
||||
left: 1rem;
|
||||
bottom: 1rem;
|
||||
padding: 1.5rem;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
@ -191,3 +191,12 @@ a[href="#"].running {
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.counter {
|
||||
position: absolute;
|
||||
left: 1rem;
|
||||
bottom: 1rem;
|
||||
padding: 1.5rem;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,14 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="counter">
|
||||
تا حالا <span id="counter"></span> ساختم
|
||||
</div>
|
||||
|
||||
<a href="https://github.com/mdibaiee/ipsum"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>
|
||||
|
||||
<script src='js/libs/zepto.js'></script>
|
||||
<script src="js/libs/socket.io.js"></script>
|
||||
<script src='js/main.js'></script>
|
||||
</body>
|
||||
|
||||
|
3
ipsum/js/libs/socket.io.js
Normal file
3
ipsum/js/libs/socket.io.js
Normal file
File diff suppressed because one or more lines are too long
@ -1,3 +1,5 @@
|
||||
var socket = io();
|
||||
|
||||
var $run = $('h1, h3, .options, a');
|
||||
|
||||
$('li[contenteditable]').click(function(e) {
|
||||
@ -39,3 +41,9 @@ function success(ipsum) {
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
|
||||
var counterElement = $('#counter');
|
||||
socket.on('counter', function(data) {
|
||||
console.log(data);
|
||||
counterElement.html(data);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user