Add counter #7

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

View File

@ -22,7 +22,7 @@ Examples:
http://ipsum.ir/design/p/2 http://ipsum.ir/design/p/2
http://ipsum.ir/normal/c/250 http://ipsum.ir/normal/c/250
http://ipsum.ir/design/w/10 http://ipsum.ir/news/w/10
## Contributing ## Contributing

1
count.json Normal file
View File

@ -0,0 +1 @@
0

View File

@ -1,13 +1,18 @@
var express = require('express'), 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 + '/client', {maxAge: 60*60*24*7})); app.use(express.static(__dirname + '/ipsum', {maxAge: 60*60*24*7}));
module.exports.app = app; module.exports.app = app;
app.get(/.*\/.*\/.*/, function(req, res) { app.get(/.*\/.*\/.*/, function(req, res) {
if(req.url.split('/')[1] != 'socket.io') {
res.charset = 'utf-8'; res.charset = 'utf-8';
res.end(go(req.url)); res.end(go(req.url));
}
}); });
if(!String.prototype.repeat) { if(!String.prototype.repeat) {
@ -86,7 +91,21 @@ function loremipsum(data) {
return s; return s;
} }
} }
function go(url) {
var req = url.split('/'); //COUNTER
return loremipsum(req.slice(1)); io.on('connection', function(socket) {
socket.emit('count', +fs.readFileSync('count.json', 'utf8'));
});
function counter(data) {
var count = data.split(' ').length + (+fs.readFileSync('count.json', 'utf8'));
fs.writeFileSync('count.json', count);
io.emit('count', count);
}
function go(url) {
var req = url.split('/'),
ipsum = loremipsum(req.slice(1));
counter(ipsum);
return ipsum;
} }

View File

@ -510,3 +510,10 @@ a[href="#"].running {
background-color: rgba(255, 255, 255, 0.2); background-color: rgba(255, 255, 255, 0.2);
color: white; color: white;
} }
.count {
position: fixed;
bottom: 3rem;
left: 3rem;
font-size: 2.2rem;
}

View File

@ -51,8 +51,13 @@
</div> </div>
<div class="count">
تا حالا <span id="count"></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> <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="/socket.io/socket.io.js"></script>
<script src='js/libs/zepto.js'></script> <script src='js/libs/zepto.js'></script>
<script src='js/main.js'></script> <script src='js/main.js'></script>
</body> </body>

View File

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