-
Notifications
You must be signed in to change notification settings - Fork 1
/
eli.js
1 lines (1 loc) · 4.12 KB
/
eli.js
1
var type="group",user="fsf",max=5,tag="elitimeline",domain="https://status.fsf.org",locationLabel="Location:",timeLabel="Post time:",api="/api/",user_api="users/show/",user_rss="statuses/user_timeline/",group_api="statusnet/groups/show/",group_rss="statusnet/groups/timeline/",api_url="",api_rss_url="",img_name="",template="",widget="",setConfig=function(e,t,a){api_url=e+api+user_api,api_rss_url=e+api+user_rss,img_name="profile_image_url","group"===a&&(api_url=e+api+group_api,api_rss_url=e+api+group_rss,img_name="stream_logo"),url=api_url+t+".xml"},getUrl=function(e,t){window.XMLHttpRequest?req=new XMLHttpRequest:req=new ActiveXObject("Microsoft.XMLHTTP"),req.open("GET",e),req.addEventListener("load",function(){req.status>=200&&req.status<400&&t(req.responseXML)}),req.send(null)},displayResult=function(){getUrl(url,createTimeline)},getTargetStatuses=function(e){for(var t=e.querySelector("statuses").getElementsByTagName("status"),a=0,r=0;r<t.length;r++){var n=t[r],i="",l="";try{l=n.querySelector("qvitter_delete_notice").textContent}catch(o){}if("true"!==l){var s=createMemberInfoBloc(n);try{i=n.getElementsByTagNameNS("*","html").item(0).firstChild.data,i=i.replace(i.slice(i.indexOf("<div"),i.indexOf("div>")+4),"")}catch(o){}var c="";try{var m=n.querySelector("attachments enclosure");if(["image/jpeg","image/gif","image/png","image/svg"].indexOf(m.getAttribute("mimetype"))>=0){var p=m.getAttribute("url");c=document.createElement("a"),c.target="_blank",c.href=p;var d=document.createElement("img");d.src=p,d.alt="Attachment",c.appendChild(d)}}catch(o){}var u="";try{var g=new Date(n.querySelector("created_at").textContent).toLocaleString();u=document.createElement("span"),u.className="tooltip";var h=document.createElement("span");h.appendChild(document.createTextNode(timeLabel+" "+g)),u.appendChild(document.createTextNode(" ⌛ ")),u.appendChild(h)}catch(o){}var _="";try{var f=n.querySelector("user location").textContent;_=document.createElement("span"),_.className="tooltip",_.appendChild(document.createTextNode(" ⌂ "));var v=document.createElement("span");v.textContent=locationLabel+" "+f,_.appendChild(v)}catch(o){}var C=document.createElement("article"),y="";""!==s&&(y+='<span class="groupmember">'+s.innerHTML+"</span>"),""!==u&&(y+='<span class="tooltip">'+u.innerHTML+"</span>"),""!==_&&(y+='<span class="tooltip">'+_.innerHTML+"</span>"),y+="<br>",y+=i,""!==c&&(y+=c.innerHTML),y+="",C.innerHTML=y,widget.insertBefore(C,templateFooter),a++}a===max&&(r=t.length)}},createTemplate=function(e){template=document.createElement("div"),template.id=tag,widget=document.createElement("div"),widget.id="eli_widget";var t=document.createElement("header");if(""!==e){var a=document.createElement("a");a.target="_blank",a.href=domain+"/"+user;var r=document.createElement("img");r.src=e,r.title="Avatar",r.alt=user,a.appendChild(r),t.appendChild(a)}var n=document.createElement("p");n.textContent=" "+user,t.appendChild(n),widget.appendChild(t),templateFooter=document.createElement("footer"),widget.appendChild(templateFooter)},createTimeline=function(e){var t=(e.getElementsByTagName(type),"");try{t=e.querySelector(img_name).textContent}catch(a){}try{targetId=e.querySelector("id").textContent}catch(a){throw new Error(alert("Can't fetch social network info."))}createTemplate(t),rss_url=api_rss_url+targetId+".xml",getUrl(rss_url,getTargetStatuses),template.appendChild(widget);var r=document.getElementById(tag);parent=r.parentNode,parent.replaceChild(template,r)},createMemberInfoBloc=function(e){var t="";if("group"===type)try{var a="@"+e.querySelector("screen_name").textContent,r=e.querySelector("name").textContent,n=e.querySelector("profile_image_url_https").textContent,i=e.getElementsByTagNameNS("*","profile_url").item(0).firstChild.data;t=document.createElement("span"),t.className="groupmember";var l=document.createElement("a");l.className="tooltip",l.target="_blank",l.href=i;var o=document.createElement("img");o.alt="Profile",o.align="left",o.src=n,l.appendChild(o),l.appendChild(document.createTextNode(a));var s=document.createElement("span");s.textContent=r,l.appendChild(s),t.appendChild(l)}catch(c){}return t};setConfig(domain,user,type),window.onload=displayResult;