Author link. Autolink

This commit is contained in:
Denis Zheleztsov 2017-12-05 13:50:04 +03:00
parent 3f5394cd2a
commit 603083b705
6 changed files with 261 additions and 92 deletions

View File

@ -7,6 +7,7 @@
<link rel="stylesheet" href="css/style.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/script.js"></script>
<script src="js/autolink.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
@ -17,6 +18,7 @@
<a href="filter.html">Настроить фильтр</a>
<a href="" onclick="clearFilter()">Сбросить фильтр</a>
<a href="lessmorefaq.html">FAQ</a>
<a href="stats.html">Статистика</a>
</div>
<a href = "" style="text-decoration: none; color: #babdb6;"><u>dynamic</u> | <u>less</u></a>
</div>

35
js/autolink.js Normal file
View File

@ -0,0 +1,35 @@
// Generated by CoffeeScript 1.10.0
(function() {
var autoLink,
slice = [].slice;
autoLink = function() {
var callback, k, linkAttributes, option, options, pattern, v;
options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
pattern = /(^|[\s\n]|<[A-Za-z]*\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi;
if (!(options.length > 0)) {
return this.replace(pattern, "$1<a href='$2'>$2</a>");
}
option = options[0];
callback = option["callback"];
linkAttributes = ((function() {
var results;
results = [];
for (k in option) {
v = option[k];
if (k !== 'callback') {
results.push(" " + k + "='" + v + "'");
}
}
return results;
})()).join('');
return this.replace(pattern, function(match, space, url) {
var link;
link = (typeof callback === "function" ? callback(url) : void 0) || ("<a href='" + url + "'" + linkAttributes + ">" + url + "</a>");
return "" + space + link;
});
};
String.prototype['autoLink'] = autoLink;
}).call(this);

View File

@ -1,7 +1,10 @@
// Copyright 2016-2017 Sudnitsyna Anna lessmore.pw
// Licensed under GPLv3
var html = '';
var options = '';
var checks = '';
var echo = '';
var author = '';
var this_page = 1;
var show_rows = 5;
var from = 0;
@ -14,102 +17,117 @@ var echo = document.cookie;
$(function() {
//extentions
$.ajax({
url:"https://dynamic.lessmore.pw/idec/x/features",
success:function(data) {
$("#extentions").html("<b>" + data.replace("\n","<br>") + "</b>");
}
})
//initial load
if (echo != '') { requestEcho();
} else {
requestEmptyEcho();
}
//create echoes list
//extentions
$.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']){
var msg = messages['aggregations']['my_fields']['buckets'][i]['key'];
var doc_count = messages['aggregations']['my_fields']['buckets'][i]['doc_count'];
url:"https://dynamic.lessmore.pw/idec/x/features",
success:function(data) {
$("#extentions").html("<b>" + data.replace("\n","<br>") + "</b>");
}
})
msg_test = msg + " ";
echo_test = echo + " ";
if((echo_test).indexOf(msg_test) > -1 && echo != '') {
//initial load
if (echo != '') {
requestEcho();
} else {
requestEmptyEcho();
}
//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']){
var msg = messages['aggregations']['my_fields']['buckets'][i]['key'];
var doc_count = messages['aggregations']['my_fields']['buckets'][i]['doc_count'];
msg_test = msg + " ";
echo_test = echo + " ";
if((echo_test).indexOf(msg_test) > -1 && echo != '') {
options += '<option value="' + msg + '" selected>' + msg + " (<b>" + doc_count + "</b>)</option>";
checks += '<span class="row"><input type="checkbox" class="echoes" name="ec" value="' + msg + '" checked><label>'
+ msg
+ '</label> <span style="color:#838784">('+ doc_count
+ ')</span><br></span>';
} else {
options += '<option value="' + msg + '" >' + msg + " (<b>" + doc_count + "</b>)</option>";
checks += '<span class="row"><input type="checkbox" class="echoes" name="ec" value="' + msg + '"><label>'
+ msg
+ '</label> <span style="color:#838784">('+ doc_count
+ ')</span><br></span>';}
}
+ msg
+ '</label> <span style="color:#838784">('+ doc_count
+ ')</span><br></span>';
} else {
options += '<option value="' + msg + '" >' + msg + " (<b>" + doc_count + "</b>)</option>";
checks += '<span class="row"><input type="checkbox" class="echoes" name="ec" value="' + msg + '"><label>'
+ msg
+ '</label> <span style="color:#838784">('+ doc_count
+ ')</span><br></span>';}
}
$('#echoSelected').html("Выбранные эхи: " + document.cookie);
$('#echoSelector').html(options);
$('#echoCheckBox').html(checks);}
$('#echoSelected').html("Выбранные эхи: " + document.cookie);
$('#echoSelector').html(options);
$('#echoCheckBox').html(checks);}
})
$('.echoes:checked').each(function() {
echo = '';
echo += $(this).val()[i] + " ";
});
$('.echoes:checked').each(function() {
echo = '';
echo += $(this).val()[i] + " ";
});
var boxes = $("input[type=checkbox]");
var boxes = $("input[type=checkbox]");
$("#echoCheckBox").on('change', function() {
echo = '';
for (var i=0; i<$("input[type=checkbox]:checked").length; i++) {
echo += $("input[type=checkbox]:checked")[i]["defaultValue"] + " ";}
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
$('#echoSelected').html("Выбранные эхи: " + echo);
});
$("#echoCheckBox").on('change', function() {
echo = '';
for (var i=0; i<$("input[type=checkbox]:checked").length; i++) {
echo += $("input[type=checkbox]:checked")[i]["defaultValue"] + " ";}
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
$('#echoSelected').html("Выбранные эхи: " + echo);
});
$('#echoSelector').on('change', function() {
echo = '';
html = '';
for (i in $(this).val()) {
echo += $(this).val()[i] + " ";
}
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
requestEcho();
$('#echoSelected').html("Выбранные эхи: " + echo)
$('#echoSelector').on('change', function() {
echo = '';
html = '';
for (i in $(this).val()) {
echo += $(this).val()[i] + " ";
}
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
requestEcho();
$('#echoSelected').html("Выбранные эхи: " + echo)
if (echo == "") requestEmptyEcho();
});
if (echo == "") requestEmptyEcho();
});
//scroll to show more messages
$(window).scroll(function() {
//scroll to show more messages
$(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());
}
});
});
}) //end of .ready() method
// Main AJAX function
function ajaxRequest(data) {
$.ajax({
url:"https://dynamic.lessmore.pw/search",
type:"POST",
data: data,
success:function(messages){
callback(messages);
$("#mes").html(html);
}
url:"https://dynamic.lessmore.pw/search",
type:"POST",
data: data,
success:function(messages){
console.log(messages);
callback(messages);
$("#mes").html(html);
}
})
}
// Cleanup AJAX function
function ajaxCleanupRequest(data) {
$.ajax({
url:"https://dynamic.lessmore.pw/search",
type:"POST",
data: data,
success:function(messages){
cleanupCallback(messages);
$("#mes").html(html);
}
})
}
function requestEmptyEcho() {
@ -122,59 +140,110 @@ function requestEcho() {
ajaxRequest(data);
}
function requestEmptyEchoOffset() {
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}],"size":'+ show_rows + ', "from":'+ from + '}';
ajaxRequest(data);
}
function requestEchoOffset() {
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["echo"], "query" :"' + echo + '"}}, "size":'+ show_rows + ', "from":'+ from + '}';
ajaxRequest(data);
}
function requestAuthorOffset() {
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["author"], "query" :"' + author + '"}}, "size":'+ show_rows + ', "from":'+ from + '}';
echo = '';
console.log("Author offset");
ajaxRequest(data);
}
function requestAuthorMessages(_author) {
author = _author;
var data = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["author"], "query" :"' + author + '"}}, "size": 5 }';
html = '';
echo = '';
console.log(author);
console.log(data);
ajaxRequest(data);
}
//show messages
function callback(messages) {
var msgArray = messages["hits"]["hits"];
console.log(msgArray);
for (hit in msgArray) {
var msgItem = msgArray[hit]['_source'];
var t = new Date(msgItem['date'] * 1000);
var t = new Date(msgItem['date'] * 1);
var t_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
msg = msgItem['message'].replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(new RegExp("\n",'g'), "<br>\n");
var to =
html += '<div class="msg"><p align="right">' + t_formatted + '</p> <p style="font: 1.5em Open Sans, sans-serif;">'
html += '<div class="msg"><p align="right">' + t_formatted + '</p> <p style="font: 1.5em Open Sans, sans-serif;">'
+ msgItem['subg'] + '</p><p>Echo: '
+ msgItem['echo'] + '<br>Author: ' + msgItem['author']
+ msgItem['echo'] + '<br>Author: ' + '<a href="#" onclick="requestAuthorMessages(\'' + msgItem['author'] + '\');">' + msgItem['author'] + '</a>'
+ '<br>To: ' + '<a href="#" onclick="requestAuthorMessages(\'' + msgItem['to'] + '\', true);">' + msgItem['to'] + '</a>'
+ '</p><p>' + msg.autoLink()
+ '</p><p align="right">'
+ msgItem['msgid'] + '</a>' + '</p></div>';
}
}
// Clenaup HTML and show messages
function cleanupCallback(messages) {
var msgArray = messages["hits"]["hits"];
console.log(msgArray);
for (hit in msgArray) {
var msgItem = msgArray[hit]['_source'];
var t = new Date(msgItem['date'] * 1);
var t_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
msg = msgItem['message'].replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(new RegExp("\n",'g'), "<br>\n");
html = '';
echo = '';
var to = '<div class="msg"><p align="right">' + t_formatted + '</p> <p style="font: 1.5em Open Sans, sans-serif;">'
+ msgItem['subg'] + '</p><p>Echo: '
+ msgItem['echo'] + '<br>Author: ' + '<a href="#" onclick="requestAuthorMessages(\'' + msgItem['author'] + '\');">' + msgItem['author'] + '</a>'
+ '<br>To: ' + msgItem['to']
+ '</p><p>' + msg
+ '</p><p align="right">' + msgItem['msgid'] + '</p></div>' ;
+ '</p><p align="right">'
+ msgItem['msgid'] + '</a>' + '</p></div>';
}
}
//show more messages
function showMore(){
console.log("Show more messages, please.");
console.log("Selected echo: " + echo);
console.log("Selected author: " + author);
this_page += 1;
from += show_rows;
var author = "(author:Difrex)";
if (echo != '') {
if (author != '') {
requestAuthorOffset();
} else if (echo != '') {
requestEchoOffset();
} else {
requestEmptyEcho();
requestEmptyEchoOffset();
}
}
function searchEcho() {
var input, filter, box, row;
input = $("#myInput").val();
input = input.toLowerCase();
var input, filter, box, row;
input = $("#myInput").val();
input = input.toLowerCase();
box = $("label");
row = $(".row");
box = $("label");
row = $(".row");
for (i = 0; i<box.length; i++) {
if (box[i].innerHTML.indexOf(input) > -1) {
row[i].style.display = "";
} else {
row[i].style.display = "none";
for (i = 0; i<box.length; i++) {
if (box[i].innerHTML.indexOf(input) > -1) {
row[i].style.display = "";
} else {
row[i].style.display = "none";
}
}
}
}

View File

@ -68,7 +68,7 @@
<h2>Куда писать про баги и хотелки?</h2>
<p>Лучше всего если вы будете писать в эху <b>dynamic.lessmore.pw</b>, только убедитесь, что ваша нода индексируется и эха есть в /list.txt.</p>
<p>Еще можно написать на <a href="mailto:difrex.punk@gmail.com">почту</a>.</p>
<p>Еще можно написать на <a href="mailto:difrex@lessmore.pw">почту</a>.</p>
<h2>Известные проблемы</h2>
<p>В индексе нет тегов и адреса. Это отколнение от стандарта и оно будет скоро исправленно.</p>

21
nodelist.json Normal file
View File

@ -0,0 +1,21 @@
[
{
"nodename": "dynamic",
"client": "https://dynamic.lessmore.pw/idec/",
"web": "https://dynamic.lessmore.pw",
"sysop": "difrex",
"contacts": {
"email": "difrex.punk@gmail.com",
"web": "https://github.com/Difrex"
},
"description": "IDEC network aggregator. Please email me for indexing your node.",
"uplinks": [
["http://ii-net.tk/ii/ii-point.php?q=/", "15m"],
["http://idec.spline-online.tk/", "15m"],
["http://spline.rooker.ru/ii/ii-point.php?q=/", "15m"],
["http://irk39.tk/ii-point.php?q=/", "15m"],
["http://ii.club.syscall.ru/", "15m"]
]
}
]

42
stats.html Normal file
View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dynamic | stats</title>
<meta name="viewport" content="width=device-width, initial-scale=0.7">
<link rel="stylesheet" href="css/style.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/script.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="lessmore">
<a id="menu" href="javascript:void(0)" onclick="showMenu()"><i class="fa fa-bars"></i></a>
<div id="dropdown-content">
<a href="/">На главную</a>
<a href="/filter.html">Настроить фильтр</a>
<a href="/" onclick="clearFilter()">Сбросить фильтр</a>
</div>
<a href = "/" style="text-decoration: none; color: #babdb6;"><u>dynamic</u> | <u>stats</u></a>
</div>
<div style="text-align: center;">
<h2 style="margin: 100px 0 0">Общий тренд</h2>
<img src="/img/stats/trend.png" width=800 height=600></img>
<h2>Колличество сообщений в эхах по авторам</h2>
<img src="/img/stats/echoes_by_author.png" width=800 height=600></img>
<h2>Топ 10</h2>
<img src="/img/stats/top_authors.png" width=800 height=600></img>
<h2>Распределение сообщений по дням недели</h2>
<img src="/img/stats/weekly_count.png" width=800 height=600></img>
<h2>Распределение сообщений в эхах по дням недели</h2>
<img src="/img/stats/weekly_echo.png" width=800 height=600></img>
</div>
<br>
<p> Поиск выполняется каждую ночь с такими условиями:
<pre>
-author: "Новостной_робот" -author: "RSS-bot" -author: "habrabot" -author:"RSS-бот"
</pre>
От текущего числа и на месяц назад.
</p>
</body>
</html>