Initial version

This commit is contained in:
LubuWest 2015-05-25 17:50:36 +02:00
parent b9bda51b65
commit 87afc8e6ab
3 changed files with 107 additions and 2 deletions

View File

@ -1,2 +1,35 @@
# friendica-comment
Show comments from friendica in your blog
## friendica-comment#
Script shows comments from your friendica server in your (static website) blog. Possible replacement for disqus.
## Requirements ##
# CORS #
[CORS] (http://enable-cors.org) (Cross Site Scripting) must be activated:
in .htaccess:
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET"
In apache module headers must be activated:
a2enmod headers
# Friendica #
RSS of your blog must be in your contacts and configured as 'remote_self' (articles are shown in your public friendica timeline).
# Blog #
In blog html:
friendica_domain must be set
<script type="text/javascript"><!--
var friendica_domain = "http://friendica_instance.com"
//--></script>
Name of the blog entry is in <article><h1> article </h1></article>
Placeholder for comments: <div id ="comments"></div>
## TODO ##
* connection to friendica via https
* CSS for <a href class="contact-photo-link">, <div class="wall-item-actions-author">, <div class="wall-item-content">

49
friendica_comments.js Normal file
View File

@ -0,0 +1,49 @@
var article = document.getElementsByTagName("article")[0].innerHTML;
var article_name= article.substring(article.indexOf('<h1')+4,article.indexOf('</h1>'));
var search = friendica_domain + "/search?search=" + article_name.replace(/ /gi,'+');
var http, http2 = null;
var ergebnis = "";
http = new XMLHttpRequest();
if (http !== null) {
http.open("GET", search, true);
http.onreadystatechange = SearchFriendica;
http.send(null);
}
function SearchFriendica() {
if (http.readyState == 4 && http.status==200) {
var SearchResult= http.responseText;
var start = SearchResult.indexOf('<div class=\"\">');
var start2 = SearchResult.indexOf('a href',start);
var end = SearchResult.indexOf('id',start);
ergebnis = SearchResult.substring(start2+8,end-2);
}
http2 = new XMLHttpRequest();
if (http2 !== null) {
http2.open("GET", ergebnis, true);
http2.onreadystatechange = SearchComments;
http2.send(null);
}
function SearchComments() {
if (http.readyState == 4 && http.status == 200) {
var CommentsResult = http2.responseText;
var ergebnisse = ("");
var arr = new Array();
arr = CommentsResult.split("wall-item-container comment");
for (i=1;i<arr.length;i++){
// var start = arr[i].indexOf('wall-item-container comment');
var photo = arr[i].substring(arr[i].indexOf('<a href'),arr[i].indexOf('</a>')+4);
var start = arr[i].indexOf('<div class=\"wall-item-actions-author\">');
var end = arr[i].indexOf('<div class=\"wall-item-bottom\">',start);
var comment = arr[i].substring(start,end-1);
var endcomment = comment.slice(comment.indexOf('onmouseover'),comment.indexOf('<a href')-1);
ergebnisse = ergebnisse + photo + comment;
}
document.getElementById("comments").innerHTML = ergebnisse;
}
}
}

23
test.html Normal file
View File

@ -0,0 +1,23 @@
<!doctype html>
<html lang="">
<head>
<link rel="stylesheet" href="./main.css" type="text/css" />
<script type="text/javascript"><!--
var friendica_domain = "http://ixsm07yclq3gsdgw.myfritz.net"
//--></script>
</head>
<article>
<h1>Test</h1>
<p>test text</p>
</article>
<script language="JavaScript" src="./friendica_comments.js">
</script>
<div id ="comments">
</div>
</body>
</html>