var html = ''; var options = ''; var echo = ''; var this_page = 1; var show_rows = 5; var from = 0; var date = new Date(new Date().getTime() + 60 * 1000); var echo = document.cookie; console.log("echoes: "+ echo ); $(function() { //initial load if (echo != '') { $.ajax({ url:"https://dynamic.lessmore.pw/search", type:"POST", data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["echo"], "query" :"' + echo + '"}}, "size":'+ 5 + '}', //data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}],"size":5}', success:function(messages){callback(messages);$("#mes").html(html);} }) } else { $.ajax({ url:"https://dynamic.lessmore.pw/search", type:"POST", //data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["echo"], "query" :"' + echo + '"}}, "size":'+ 5 + '}', data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}],"size":5}', success:function(messages){callback(messages);$("#mes").html(html);} }) } //create echoes list $.ajax({ url:"https://dynamic.lessmore.pw/search", type:"POST", data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}],"aggs": {"my_fields": { "terms": { "field": "echo","size": 1000}}}}}', success:function(messages){for (i in messages['aggregations']['my_fields']['buckets']){options += ''}$ $('#echoSelector').html(options);} }) //show msgs when echo is selected $('#echoSelector').on('change', function() { echo = ''; for (i in $(this).val()) {echo += $(this).val()[i] + " "}; console.log(echo); document.cookie = echo +"; path=/; expires=" + date.toUTCString(); $.ajax({ url:"https://dynamic.lessmore.pw/search", type:"POST", data:'{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["echo"], "query" :"' + echo + '"}}, "size":5}', success:function(messages){html = ''; callback(messages);$("#mes").html(html); } }); }); //scroll $(window).scroll(function() { console.log($(document).height() - $(window).height()-$(window).scrollTop()); if ($(document).height() - $(window).height() - $(window).scrollTop() < 1.5) { showMore(); //console.log($(document).height() - $(window).height() - $(window).scrollTop()); } }); }) //show more messages function showMore(){ this_page += 1; from += show_rows; var author = "(author:Difrex)"; if (echo != '') { console.log("im here"); $.ajax({ url:"https://dynamic.lessmore.pw/search", type:"POST", data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["echo"], "query" :"' + echo + '"}}, "size":'+ show_rows + ', "from":'+ from + '}', success:function(messages){callback(messages); $("#mes").html(html);} }) } else { $.ajax({ url:"https://dynamic.lessmore.pw/search", type:"POST", data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}],"size":'+ show_rows + ', "from":'+ from + '}', success:function(messages){callback(messages); $("#mes").html(html);} }) } } //show messages function callback(messages) { var huinya = 'wtf??'; console.log(messages); for (hit in messages["hits"]["hits"]) { var t = new Date(messages['hits']['hits'][hit]['_source']['date'] * 1000); var t_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds(); // Replace new line with
msg = messages['hits']['hits'][hit]['_source']['message'].replace(new RegExp("\n",'g'), "
\n"); html += '

' + t_formatted + '

' + messages['hits']['hits'][hit]['_source']['subg'] + '

Echo: ' + messages['hits']['hits'][hit]['_source']['echo'] + '
Author: ' + messages['hits']['hits'][hit]['_source']['author'] + '
To: ' + messages['hits']['hits'][hit]['_source']['to'] + '

' + msg // + messages['hits']['hits'][hit]['_source']['message'] + '
Msgid: ' + messages['hits']['hits'][hit]['_source']['msgid'] + '

' ; } } //not used /* function filterByEcho() { console.log('func'); var author = "(echo:develop.16)"; var from = 0; $.ajax({ url:"https://dynamic.lessmore.pw/search", type:"POST", data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["author"], "query" : "Andrew Lobanov"}}, "size":5}', success:function(messages){html=''; callback(messages); $("#mes").html(html); } }) } */