Federation-widget/federation-widget.js

2 lines
2.4 KiB
JavaScript

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<e.length;a++)"avatar"==e[a].getAttribute("rel")&&(img=e[a].getAttribute("href"));else img=t.getElementsByTagName("logo")[0].firstChild.data}catch(t){img=""}try{profile=userinfo.getElementsByTagName("uri")[0].firstChild.data}catch(t){profile=""}try{displayname=userinfo.getElementsByTagNameNS("http://portablecontacts.net/spec/1.0","displayName")[0].firstChild.data}catch(t){displayname=""}content='<div id="federation_widget"><header>',""!=img&&(content+='<a target= "_blank" href="'+profile+'"><img src="'+img+'" title="Avatar"/></a>'),content+=' <p><a target= "_blank" href="'+profile+'">'+displayname+"</a></p></header>";for(var r=t.getElementsByTagName("entry"),n=max-1,l=0;l<r.length;l++){try{var i="",s="",o="",m="";if("group"==type){s=r[l].getElementsByTagName("author")[0].getElementsByTagNameNS("http://portablecontacts.net/spec/1.0","displayName")[0].firstChild.data;var g=r[l].getElementsByTagName("link");for(a=0;a<g.length;a++)if("avatar"==g[a].getAttribute("rel"))o=g[a].getAttribute("href");i='<span class="groupmember"><a class="tooltip" target= "_blank" href="'+(m=r[l].getElementsByTagName("uri")[0].firstChild.data)+'"><img style="max-width:50px;" alt="Profile" align="left" src="'+o+'" />'+s+" <span>"+m+"</span> </a> </span>"}}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='<span class="tooltip">&#x231B;<span>'+posttime_label+" "+d+"</span> </span>"}catch(t){d=""}content+="<article>"+i+d+"<br />"+p+"</article>",n<r.length&&l==n&&(l=r.length)}content+="<footer></footer></div>",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;