commit 5a212bffde3ba2d92325edf04ad18d10a38453fd Author: LubuWest Date: Sun May 13 16:28:58 2018 +0200 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..09869d3 --- /dev/null +++ b/README.md @@ -0,0 +1,163 @@ +# Federation widget + +## About + +This is a javascript widget that shows the public timeline of an account in the Federation (Diaspora, Friendica, Hubzilla) and Mastodon. Currently onlytested with Friendica. + +This works for a user or a group. It is loosely based on the [ELI widget](https://github.com/blankoworld/eli) for GNU Social. + + +![User Timeline](federation-user.png) ![Group Timeline](federation_group.png) + + +The server has to support [Cross-Origin Resource Sharing](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing). The .htaccess file in the server directory should include the following code for this: + +``` + Access-Control-Allow-Origin: * + Access-Control-Allow-Methods: GET + +``` + +## License + +This program is licensed under the [WTF Public License](http://sam.zoy.org/wtfpl/COPYING 'Read more about the WTF Public License'). + +## Installation + +Just: + + * copy the federation-widget.js in your website directory + * add this code in your page: + +```html +
+

Timeline activity...

+
+``` + +Then add this code **at the end of your page before the `` tag**: + +```html + +``` + +Adapt domain, user, and servertype content to your account in the Federation. For an example: **https://forum.friendi.ca**. + +In order Federation widget to be more beautiful, add this in your CSS file or in **`` tag**: + +```css + +#federation_widget { +font-size: 0.7em; +margin-top: 20px; +height: 350px; +width: 230px; +padding: 0; +border-radius: 5px; +background-color: #FcFcFc; +overflow-y: auto; +} + +#federation_widget header { +padding-bottom: 8px; +text-align: left; +font-size: 1.5em; +border-bottom: 3px solid #EEEEEE; +background-color: #FcFcFc; +border-top-left-radius: 5px; +border-top-right-radius: 5px; +} + +#federation_widget header a { +text-decoration: none; +color:black +} + +#federation_widget header img { +margin: 5px; +background-color: #ffffff; +border-radius: 5px; +float: left; +max-width: 50px; +} + +#federation_widget header p { +margin: 0px; +line-height: 60px; +} + +#federation_widget article { +display: block; +margin-bottom: 5px; +padding: 5px; +border-bottom: thin solid #eeeeee; +overflow: hidden; /* For too long link: hide but enable click on it */ +} + +#federation_widget article img { +margin: 5px; +max-width: 230px; +} + +#federation_widget article p { +margin-top: 0px; +} + +.groupmember img { +border-radius: 5px; +} + +.tooltip {position: relative;} +.tooltip span {display: none;} +.tooltip:hover span { +display: block; +position: absolute; +left: 0; top: 10%; +margin: 20px 0 0; +width: 200px; +font-size: 0.7em; +color: #4D4D4C; +border: thin solid #eeeeee; +padding: 4px; +background: white; +} + + +``` + +An example is available on **minimal.html** page. You can also see a more complete version on **index.html** page. + +## Configuration + +You probably want to change these variables: + + * type: Add here **user** OR **group** if you want to follow a user OR a group + * user: Add here the nickname of the user (or the group) you want to follow + * max: Add here the number of statuses you want to display. By default StatusNet seems to only give 20 statuses. + * tag: The name of the tag we should change to display all statuses. In the previous example, the div with ID equal to *content* would be changed. But you can add another ID. + * domain: The URL of your server Instance. + * servertype: type of server (friendica, hubzilla, diaspora, mastodon) + * posttime_label: Change the label name that appears when you have the time the entry was posted. + +## Read code + +**federation-widget.js** is a minimal version of Federation Widget. To have a more readable version, with more options, you can open **federation-widget.max.js** file. + +### Howto minify federation-widget.max.js + + * Go to http://javascript-minifier.com/ + * Copy/paste the content of federation-widget.max.js + * Delete the license, the first lines ```var loadForm``` and the loadConfig() function + * Click on **Minify** + * Copy the result into eli.js file + +## Contact + +You can contact me at the given address: olivier+eli [AT] dossmann [DOT] net diff --git a/federation-widget.js b/federation-widget.js new file mode 100644 index 0000000..a4f4876 --- /dev/null +++ b/federation-widget.js @@ -0,0 +1 @@ +function getAtom(){window.XMLHttpRequest?xmlhttp=new XMLHttpRequest:xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"),xmlhttp.open("GET",url,!0),xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState===XMLHttpRequest.DONE)try{(xmlhttp.status=200)&&updateWidget(xmlhttp.responseXML)}catch(t){}},xmlhttp.send()}function updateWidget(t){"hubzilla"==servertype?userinfo=t.getElementsByTagNameNS("http://purl.org/zot","owner")[0]:userinfo=t.getElementsByTagName("author")[0];try{if("hubzilla"==servertype)for(var e=userinfo.getElementsByTagName("link"),a=0;a
',""!=img&&(content+=''),content+='

'+displayname+"

";for(var r=t.getElementsByTagName("entry"),n=max-1,l=0;lProfile'+s+" "+m+" "}}catch(t){i="",o="",m=""}try{var p=r[l].getElementsByTagName("content")[0].firstChild.data}catch(t){p=""}try{var d="";d=new Date(r[l].getElementsByTagName("updated")[0].firstChild.data).toLocaleString(),d=''+posttime_label+" "+d+" "}catch(t){d=""}content+="
"+i+d+"
"+p+"
",n",document.getElementById(tag).innerHTML=content}"diaspora"==servertype?url=domain+"/public/"+user+".atom":"mastodon"==servertype?url=domain+"/@"+user+".atom":url=domain+"/feed/"+user,window.onload=getAtom; diff --git a/federation-widget.max.js b/federation-widget.max.js new file mode 100644 index 0000000..346f12f --- /dev/null +++ b/federation-widget.max.js @@ -0,0 +1,173 @@ +/* This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. */ + +var loadForm = document.getElementById('loadForm'); +loadForm.addEventListener('submit', function(e) { + e.preventDefault(); + loadConfig(); +}, true); + +// Change variables here. +var type = 'user'; // could be 'group' to follow a group +var servertype ='friendica'; +var user = 'marco'; +var max = 5; +var tag = 'federation-widget'; +var domain = 'https://freunde.ma-nic.de'; +var posttime_label = 'Post time:'; + +// Other variables +if (servertype=='diaspora'){ + url = domain+'/public/'+user+'.atom' +} +else if (servertype=='mastodon'){ + url = domain+'/@'+user+'.atom' +} +else { + url = domain+'/feed/'+user; +} + +function loadConfig() +{ + domain = document.getElementById('profile_domain').value; + servertype = document.getElementById('server_type').value; + user = document.getElementById('profile_name').value; + profile_type = document.getElementById('profile_type'); + type = profile_type.options[profile_type.selectedIndex].value; + if (servertype=='diaspora'){ + url = domain+'/public/'+user+'.atom' + } + else if (servertype=='mastodon'){ + url = domain+'/@'+user+'.atom' + } + else { + url = domain+'/feed/'+user; + } + getAtom(); +} + +function getAtom() +{ + if (window.XMLHttpRequest) + {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else + {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.open("GET",url,true); + xmlhttp.onreadystatechange = function() { + if(xmlhttp.readyState === XMLHttpRequest.DONE) { + try{if (xmlhttp.status=200){updateWidget(xmlhttp.responseXML)}} + catch (e){} + } + } + xmlhttp.send(); +} + +function updateWidget(xmlDoc){; + + if (servertype=='hubzilla'){ + userinfo=xmlDoc.getElementsByTagNameNS('http://purl.org/zot','owner')[0]; + } else{ + userinfo=xmlDoc.getElementsByTagName('author')[0]; + } + + try { + if (servertype=='hubzilla'){ + var imagelinks=userinfo.getElementsByTagName('link'); + for (var i=0;i< imagelinks.length;i++) { + if (imagelinks[i].getAttribute('rel')=='avatar'){ + img=imagelinks[i].getAttribute('href') + }; + } + } else{ + img = xmlDoc.getElementsByTagName('logo')[0].firstChild.data; + } + } + catch (e) { + img = ''; + } + + try { + profile = userinfo.getElementsByTagName('uri')[0].firstChild.data; + } + catch (e) { + profile = ''; + } + + try { + displayname = userinfo.getElementsByTagNameNS('http://portablecontacts.net/spec/1.0','displayName')[0].firstChild.data + } + catch (e) { + displayname = ''; + } + + //Header + content = '
'; + if (img != '') { + content += ''; + } + content += '

'+displayname+ '

'; + + //Statuses in Array + var items = xmlDoc.getElementsByTagName('entry'); + var max_item = max - 1 + + //Read item from array + for (var n=0; n < items.length; n++) { + try {//Images, names and link for Group member + var item_groupmember="",item_groupmember_screen_name="",item_groupmember_name="", item_groupmember_image="",item_groupmember_link=""; + if (type=='group'){ + var item_groupmember_screen_name = items[n].getElementsByTagName('author')[0].getElementsByTagNameNS('http://portablecontacts.net/spec/1.0','displayName')[0].firstChild.data; + var authorlinks=items[n].getElementsByTagName('link'); + for (var i=0;i< authorlinks.length;i++) { + if (authorlinks[i].getAttribute('rel')=='avatar'){ + var item_groupmember_image=authorlinks[i].getAttribute('href') + }; + } + + var item_groupmember_link = items[n].getElementsByTagName('uri')[0].firstChild.data; + var item_groupmember = '\"Profile\"' + item_groupmember_screen_name + ' ' + item_groupmember_link +' '; + }; + } + catch (e) { + var item_groupmember='',item_groupmember_name='',item_groupmember_image='',item_groupmember_link=''; + } + + try {//Get Status Html + var item_content = items[n].getElementsByTagName('content')[0].firstChild.data; + } + catch (e) { + var item_content = ''; + } + + + try {//Get Create Time from status + var item_time = ''; + item_time = new Date( items[n].getElementsByTagName('updated')[0].firstChild.data).toLocaleString(); + item_time= "⌛\;" + posttime_label + " " + item_time +" "; + } + catch (e) { + var item_time = ''; + } + + //Build status string and add to timeline + content += '
'+item_groupmember+item_time+"
" +item_content+'
' + + + if ((max_item < items.length) && (n==max_item)) + { + n = items.length; + } + } + + content += '
'; + document.getElementById(tag).innerHTML = content; +} + +window.onload = getAtom; diff --git a/federation_group.png b/federation_group.png new file mode 100644 index 0000000..080ec7f Binary files /dev/null and b/federation_group.png differ diff --git a/federation_user.png b/federation_user.png new file mode 100644 index 0000000..0b7930f Binary files /dev/null and b/federation_user.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..914e4aa --- /dev/null +++ b/index.html @@ -0,0 +1,53 @@ + + + + + Federation Widget + + + + +

Federation Widget

+

The Federation widget parses the Atom output of your account. It shows the timeline from the personal or forum account on your personal blog or website. It works only if CORS is enabled on the server. Friendica and Hubzilla accounts are currently supported. You have to give the type of the account as the XML is different for the services (hooray for standards!).
+It makes most sense for static website generators like Pelican. You only have to include the Javascript file, the CSS part and a placeholder in your website template.

+

You can test the output with this file.

+
+
+

+ +

+

+ +

+

+ + +

+

+ +

+

+ +

+
+ +
+

Timeline activity...

+
+ + + +
+

Get the code at Federation Widget at Github

+ + + diff --git a/minimal.html b/minimal.html new file mode 100644 index 0000000..589e06e --- /dev/null +++ b/minimal.html @@ -0,0 +1,32 @@ + + + + + Federation Widget + + + + + + + +

Federation Widget

+ +
+

Timeline activity...

+
+ + + +
+

Get the sources of the Federation widget at Federation widget on Github

+ + diff --git a/style.css b/style.css new file mode 100644 index 0000000..e4a464a --- /dev/null +++ b/style.css @@ -0,0 +1,98 @@ +body, html { +background-color: #999999; +color: #ffffff; +} + +html { +margin: 0em; +padding: 1em 3%; +background-color: #999999; +color: #ffffff; +} + +body { +padding: 1em; +color: #112233; +background-color: #ffffff; +font-family: Georgia, Palatina, serif; +box-shadow: 1px 1px 12px #000000; +} + +h1 { +text-align: center; +} + +#federation_widget { +font-size: 0.7em; +margin-top: 20px; +height: 350px; +width: 230px; +padding: 0; +border-radius: 5px; +background-color: #FcFcFc; +overflow-y: auto; +} + +#federation_widget header { +padding-bottom: 8px; +text-align: left; +font-size: 1.5em; +border-bottom: 3px solid #EEEEEE; +background-color: #FcFcFc; +border-top-left-radius: 5px; +border-top-right-radius: 5px; +} + +#federation_widget header a { +text-decoration: none; +color:black +} + +#federation_widget header img { +margin: 5px; +background-color: #ffffff; +border-radius: 5px; +float: left; +max-width: 50px; +} + +#federation_widget header p { +margin: 0px; +line-height: 60px; +} + +#federation_widget article { +display: block; +margin-bottom: 5px; +padding: 5px; +border-bottom: thin solid #eeeeee; +overflow: hidden; /* For too long link: hide but enable click on it */ +} + +#federation_widget article img { +margin: 5px; +max-width: 230px; +} + +#federation_widget article p { +margin-top: 0px; +} + +.groupmember img { +border-radius: 5px; +} + +.tooltip {position: relative;} +.tooltip span {display: none;} +.tooltip:hover span { +display: block; +position: absolute; +left: 0; top: 10%; +margin: 20px 0 0; +width: 200px; +font-size: 0.7em; +color: #4D4D4C; +border: thin solid #eeeeee; +padding: 4px; +background: white; +}