meshenger/webapp.html

338 lines
7.9 KiB
HTML
Raw Normal View History

2014-04-28 23:49:38 +02:00
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="viewport" content="width=device-width, user-scalable=no">
2014-05-28 12:51:12 +02:00
<style>
2014-05-28 22:16:09 +02:00
body, html{margin: 0;padding: 0;}
2014-05-28 21:00:11 +02:00
body{
font-size:20px;
2014-05-28 21:38:12 +02:00
text-shadow: 1px 1px orange;
2014-05-28 21:00:11 +02:00
font-family: times, 'times new roman', helvetica,serif;
line-height:1.5em;
color:#444;
background:#fff;
background-image: url(css/marble.jpg);
}
2014-05-28 12:51:12 +02:00
textarea{
2014-05-28 21:38:12 +02:00
-webkit-appearance: none; -moz-appearance: none;
display: block;
2014-05-28 22:16:09 +02:00
margin-left: auto;
margin-right: auto;
width: 90%; height: 50px;
2014-05-28 21:38:12 +02:00
line-height: 40px; font-size: 17px;
border: 1px solid #bbb;
-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;
background-image: url(css/aqua.jpg);
font-family: inherit;
font-size: inherit;
2014-05-28 21:55:27 +02:00
font-size: 20px;
2014-05-28 12:51:12 +02:00
}
2014-05-28 21:38:12 +02:00
2014-05-28 12:51:12 +02:00
button {
2014-05-28 22:16:09 +02:00
display: block;
margin-left: auto;
margin-right: auto;
2014-05-28 12:51:12 +02:00
margin: 1.5em 0;
2014-05-28 21:00:11 +02:00
font-family: inherit;
font-size: inherit;
2014-05-28 21:55:27 +02:00
font-size: 20px;
2014-05-28 12:51:12 +02:00
}
2014-05-28 21:00:11 +02:00
h2{
font-size: 40px;
}
hr{
height:10px;
border: 10;
width:87%;
background-image: url(css/bg1.gif);
}
2014-05-28 21:55:27 +02:00
ul{
2014-05-28 22:16:09 +02:00
width:95%;
2014-05-28 21:55:27 +02:00
//margin-left: 0px;
padding-left:30px;
}
2014-05-28 21:00:11 +02:00
li{
2014-05-28 21:55:27 +02:00
2014-05-28 21:38:12 +02:00
word-wrap:break-word;
list-style: none;
overflow: visible;
padding:30px;
2014-05-28 21:00:11 +02:00
-moz-box-shadow:0 0 23px #bbb;
-webkit-box-shadow:0 0 23px #bbb;
2014-05-28 21:38:12 +02:00
box-shadow:0 0 23px #bbb;
2014-05-28 21:00:11 +02:00
-webkit-border-top-left-radius:123px;
-webkit-border-top-right-radius:123px;
-webkit-border-bottom-right-radius:123px;
-webkit-border-bottom-left-radius:123px;
-moz-border-radius-bottomright:123px;
-moz-border-radius-bottomleft:123px;
2014-05-28 21:38:12 +02:00
-moz-border-top-left-radius:123px;
-moz-border-top-right-radius:123px;
border-top-left-radius:123px;
border-top-right-radius:123px;
2014-05-28 21:00:11 +02:00
border-bottom-right-radius:123px;
border-bottom-left-radius:123px;
left:-35px;
2014-05-28 21:38:12 +02:00
width:100%;
//overflow:hidden;
2014-05-28 21:00:11 +02:00
position:relative;
background:#fff;
//background:-webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee));
//background:-moz-linear-gradient(top, #fff, #eee);
}
#outbox{
display:hidden;
}
#header{
width:100%;
text-align: center;
}
2014-05-28 22:16:09 +02:00
#name{
}
2014-05-28 21:00:11 +02:00
</style>
2014-05-28 12:51:12 +02:00
2014-04-28 23:49:38 +02:00
<title>meshed up</title>
</head>
<body>
2014-05-28 21:00:11 +02:00
<div id="header">
<h2>Meshenger</h2>
2014-05-28 22:16:09 +02:00
2014-05-28 21:00:11 +02:00
</div>
2014-05-28 22:16:09 +02:00
<textarea id="name" rows="1" placeholder="Your Name (leave empty for anonymous)"></textarea>
<textarea id="message" rows="3" placeholder="Your Message"></textarea>
2014-05-28 21:00:11 +02:00
<button style="width:100%" id="send">Send</button>
2014-05-28 22:16:09 +02:00
2014-05-28 21:00:11 +02:00
2014-04-28 23:49:38 +02:00
<ul id="inbox"></ul>
2014-05-28 21:00:11 +02:00
<!--<h2>outbox</h2>-->
<ul id="outbox"></ul>
2014-04-28 23:49:38 +02:00
2014-05-28 21:00:11 +02:00
2014-04-28 23:49:38 +02:00
<script type="text/javascript">
/*
* OUTBOX STUFF
*/
document.getElementById( 'send' ).onclick = function() {
var outStr = localStorage.getItem( 'outbox' ) || '';
2014-05-28 21:22:11 +02:00
if (document.getElementById('name').value == ""){
var namm= "anonymous";
}
else{
var namm= document.getElementById('name').value;
}
outStr += new Date().getTime() + ' ' + namm + '///' + document.getElementById('message').value + '\n';
2014-04-28 23:49:38 +02:00
localStorage.setItem( 'outbox', outStr );
updateOutboxView();
checkOutbox();
document.getElementById('message').value = '';
//localStorage.setItem(
// new Date().getTime(),
// document.getElementById('message').value );
//updateList();
};
function checkOutbox() {
var outStr = localStorage.getItem( 'outbox' );
if ( ! outStr ) {
return;
}
var lines = outStr.split( /\n/ );
for ( var i in lines ) {
if ( lines[i].length === 0 ) {
continue;
}
var ts = lines[ i ].substr( 0, lines[ i ].indexOf( ' ' ));
var msg = lines[ i ].substr( lines[ i ].indexOf( ' ' ));
sendMessage( ts, msg );
}
}
function sendMessage( timestamp, message ) {
var xhr = new XMLHttpRequest();
var data = 'time=' + encodeURIComponent( timestamp ) +
'&message=' + encodeURIComponent( message );
xhr.onreadystatechange = function(){
if ( xhr.readyState == 4){
if ( xhr.status == 200 ) {
removeOutboxItem( timestamp );
}
}
};
xhr.open('POST', 'send', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2005 00:00:00 GMT');
xhr.send(data);
}
function removeOutboxItem( timestamp ) {
var outStr = localStorage.getItem( 'outbox' ) || '';
var lines = outStr.split( /\n/ );
for ( var i in lines ) {
var ts = lines[ i ].substr( 0, lines[ i ].indexOf( ' ' ));
if ( ts === timestamp ) {
lines.splice( i, 1 );
break;
}
}
var newOutStr = lines.join('\n');
localStorage.setItem('outbox', newOutStr);
updateOutboxView();
}
function updateOutboxView() {
var contentString = '';
var outStr = localStorage.getItem( 'outbox' ) || '';
var lines = outStr.split( /\n/ );
for ( var i in lines ) {
if ( lines[ i ].length === 0 ) {
continue;
}
var ts = lines[ i ].substr( 0, lines[ i ].indexOf( ' ' ));
var msg = lines[ i ].substr( lines[ i ].indexOf( ' ' ));
contentString += '<li><b>' + ts + ' </b>' + msg + '</li>';
}
document.getElementById( 'outbox' ).innerHTML = contentString;
}
function doStuffForEach( entriesString, stuffFunction ) {
if ( ! entriesString ) {
return;
}
var lines = entriesString.split( /\n/ );
for ( var i in lines ) {
var ts = lines[ i ].substr( 0, lines[ i ].indexOf( ' ' ));
var msg = lines[ i ].substr( lines[ i ].indexOf( ' ' ) + 1 );
stuffFunction( ts, msg );
}
}
/*
* INBOX STUFF
*/
2014-05-28 20:48:08 +02:00
2014-04-28 23:49:38 +02:00
function updateInboxView() {
2014-05-28 20:48:08 +02:00
var localStorageArray = new Array();
2014-04-28 23:49:38 +02:00
var contentString = '';
2014-05-28 20:48:08 +02:00
if (localStorage.length>0) {
for (i=0;i<localStorage.length;i++){
element=localStorage.getItem(localStorage.key(i))
elesplit=element.split('///');
if ( localStorage.key(i).length === 0 || element === 'outbox' ) {
continue;
}
2014-05-28 21:22:11 +02:00
localStorageArray[i] = { time:localStorage.key(i), user:elesplit[0], message:elesplit[1] };
2014-05-28 20:48:08 +02:00
}
}
orderStorage = localStorageArray.sort(function(a,b) { return b.time - a.time } );
for(var i in orderStorage)
2014-04-28 23:49:38 +02:00
{
if ( i.length === 0 || i === 'outbox' ) {
continue;
}
2014-05-28 20:48:08 +02:00
var date = new Date(parseInt(orderStorage[i].time));
// date.setHours(date.getHours() + 2);
var datereadable = date.getDate()+"/"+date.getMonth()+"/"+date.getFullYear()+" "+date.getHours()+":"+date.getMinutes();
2014-05-28 21:22:11 +02:00
contentString += '<li><b>' + datereadable + ' </b>' + ' <i>'+ orderStorage[i].user +'</i><br/> '+orderStorage[i].message+'</li>';
2014-04-28 23:49:38 +02:00
}
document.getElementById( 'inbox' ).innerHTML = contentString;
}
function onMessageDownload( msg, filename ) {
if ( localStorage.getItem( filename ) === null ) {
localStorage.setItem( filename, msg );
}
updateInboxView();
}
function onIndex( index ) {
var lines = index.split( /\n/ );
2014-05-28 11:09:01 +02:00
for(var k in localStorage){
var l = 1;
for ( var i in lines ) {
var f = lines[i];
if (f == k){ l = 0; }
2014-05-28 11:09:01 +02:00
}
if (l == 1){
localStorage.removeItem(k);
}
}
updateInboxView();
2014-04-28 23:49:38 +02:00
for ( var i in lines ) {
var fname = lines[i];
if ( localStorage.getItem( fname ) === null ) {
//localStorage.setItem( ts, lines[i].substr(lines[i].indexOf(' ')) );
downloadMessage( fname );
}
2014-05-28 11:09:01 +02:00
2014-04-28 23:49:38 +02:00
}
2014-05-28 11:09:01 +02:00
2014-04-28 23:49:38 +02:00
}
function downloadMessage(filename) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200){
onMessageDownload( xhr.responseText, filename );
}
}
xhr.open( "GET", 'msg/'+filename, true);
xhr.send();
}
function checkInbox() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200){
onIndex( xhr.responseText );
}
}
xhr.open( "GET", 'index', true);
xhr.send();
}
/*
* INIT
*/
updateInboxView();
updateOutboxView();
window.setInterval( function(){
checkInbox();
checkOutbox();
2014-05-28 11:09:01 +02:00
}, 3000 );
2014-04-28 23:49:38 +02:00
</script>
</body>
</html>