PageSourceSearch

https://www.foxtrotgps.org/~rozzin/statusnet-group-badge.js

js foxtrotgps.org collected 2026-10-02 05:00:01 UTC 14,088 bytes, 294 lines download raw bytes

1// identica badge -- updated to work with the native API, 12-4-2008
2// Modified 2012-06-15 by Joshua Judson Rosen <[email protected]>
3// to source StatusNet groups rather than friend-feeds.
4// copyright Kent Brewster 2008
5// see http://kentbrewster.com/identica-badge for info
6( function() { 
7   var trueName = '';
8   for (var i = 0; i < 16; i++) { 
9      trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97); 
10   }
11   window[trueName] = {};
12   var $ = window[trueName];
13   $.f = function() {
14      return { 
15         runFunction : [],
16         init : function(target) {
17            var theScripts = document.getElementsByTagName('SCRIPT');
18            for (var i = 0; i < theScripts.length; i++) {
19               if (theScripts[i].src.match(target)) {
20                  $.a = {};
21                  if (theScripts[i].innerHTML) {
22                     $.a = $.f.parseJson(theScripts[i].innerHTML);
23                  }
24                  if ($.a.err) {
25                     alert('bad json!');
26                  }
27                  $.f.loadDefaults();
28                  $.f.buildStructure();
29                  $.f.buildPresentation();
30                  theScripts[i].parentNode.insertBefore($.s, theScripts[i]);
31                  theScripts[i].parentNode.removeChild(theScripts[i]);
32                  break;
33               }
34            }         
35         },
36         parseJson : function(json) {
37            this.parseJson.data = json;
38            if ( typeof json !== 'string') {
39               return {"err":"trying to parse a non-string JSON object"};
40            }
41            try {
42               var f = Function(['var document,top,self,window,parent,Number,Date,Object,Function,',
43                  'Array,String,Math,RegExp,Image,ActiveXObject;',
44                  'return (' , json.replace(/<\!--.+-->/gim,'').replace(/\bfunction\b/g,'function&shy;') , ');'].join(''));
45               return f();
46            } catch (e) {
47               return {"err":"trouble parsing JSON object"};
48            }
49         },
50         loadDefaults : function() {
51            $.d = { 
52               "group":"statusnet",
53               "headerText" : "",
54               "height" : 350,
55               "width" : 300,
56               "background" : "#193441",
57               "border" : "1px solid black",
58               "userFontSize" : "inherit",
59               "userColor" : "inherit",
60               "headerBackground" : "transparent", 
61               "headerColor" : "white",
62               "evenBackground" : "#fff",
63               "oddBackground" : "#eee",
64               "thumbnailBorder" : "1px solid black",
65               "thumbnailSize" : 24,
66               "padding" : 3,
67               "server" : "identi.ca"
68            };
69            for (var k in $.d) { if ($.a[k] === undefined) { $.a[k] = $.d[k]; } }
70         },
71          buildPresentation : function () {
72            var ns = document.createElement('style');
73            document.getElementsByTagName('head')[0].appendChild(ns);
74            if (!window.createPopup) {
75               ns.appendChild(document.createTextNode(''));
76               ns.setAttribute("type", "text/css");
77            }
78            var s = document.styleSheets[document.styleSheets.length - 1];
79            var rules = {
80               "" : "{zoom:1;margin:0;padding:0;width:" + $.a.width + "px;background:" + $.a.background + ";border:" + $.a.border + ";font:13px/1.2em tahoma, veranda, arial, helvetica, clean, sans-serif;*font-size:small;*font:x-small;}",
81               "a" : "{cursor:pointer;text-decoration:none;}",
82               "a:hover" : "{text-decoration:underline;}",
83               "cite" : "{font-weight:bold;margin:0 0 0 4px;padding:0;display:block;font-style:normal;line-height:" + ($.a.thumbnailSize/2) + "px;}",
84               "cite a" : "{color:#C15D42;}",
85               "date":"{font-size:87%;margin:0 0 0 4px;padding:0;display:block;font-style:normal;line-height:" + ($.a.thumbnailSize/2) + "px;}",
86               "date:after" : "{clear:both; content:\".\"; display:block; height:0; visibility:hidden; }",
87               "date a" : "{color:#676;}",
88               "h3" : "{margin:0;padding:" + $.a.padding + "px;font-weight:bold;
88background:" + $.a.headerBackground + " url('https://" + $.a.server + "/favicon.ico') " + $.a.padding + "px 50% no-repeat;text-indent:" + ($.a.padding + 16) + "px;}",
89               "h3.loading" : "{background-image:url('http://l.yimg.com/us.yimg.com/i/us/my/mw/anim_loading_sm.gif');}",
90               "h3 a" : "{font-size:92%; color:" + $.a.headerColor + ";}",
91               "h4" : "{font-weight:normal; background:" + $.a.headerBackground + ";text-align:right;margin:0;padding:" + $.a.padding + "px;}",
92               "h4 a" : "{font-size:92%; color:" + $.a.headerColor + ";}",
93               "img":"{float:left; height:" + $.a.thumbnailSize + "px;width:" + $.a.thumbnailSize + "px;border:" + $.a.thumbnailBorder + ";margin-right:" + $.a.padding + "px;}",
94               "p" : "{margin:0; padding:0;width:" + ($.a.width - 22) + "px;overflow:hidden;font-size:87%;}",
95               "p a" : "{color:#C15D42;}",
96               "ul":"{margin:0; padding:0; height:" + $.a.height + "px;width:" + $.a.width + "px;overflow:auto;}",
97               "ul li":"{background:" + $.a.evenBackground + ";margin:0;padding:" + $.a.padding + "px;list-style:none;width:" + ($.a.width - 22) + "px;overflow:hidden;border-bottom:1px solid #D8E2D7;}",
98               "ul li:hover":"{background:#f3f8ea;}"
99            };
100            var ieRules = "";
101            // brute-force each and every style rule here to !important
102            // sometimes you have to take off and nuke the site from orbit; it's the only way to be sure
103            for (var z in rules) {
104               var selector = '.' + trueName + ' ' + z;
105               var rule = rules[z];
106               if (typeof rule === 'string') {
107                  var important = rule.replace(/;/gi, '!important;');
108                  if (!window.createPopup) {
109                     var theRule = document.createTextNode(selector + important);
110                     ns.appendChild(theRule);
111                  } else {
112                     ieRules += selector + important;
113                  }
114               }
115            }
116            if (window.createPopup) { s.cssText = ieRules; }
117         },
118         buildStructure : function() {
119            $.s = document.createElement('DIV');
120            $.s.className = trueName;         
121            $.s.h = document.createElement('H3');
122            $.s.h.a = document.createElement('A');
123            $.s.h.a.target = '_laconica';
124            $.s.h.appendChild($.s.h.a);
125            $.s.appendChild($.s.h);
126            $.s.r = document.createElement('UL');
127            $.s.appendChild($.s.r);
128            $.s.f = document.createElement('H4');
129            var a = document.createElement('A');
130            a.innerHTML = 'get this';
131            a.target = '_blank';
132            a.href = 'https://www.hackerposse.com/~rozzin/statusnet-group-badge.js';
133            $.s.f.appendChild(a);
134            $.s.appendChild($.s.f);
135            $.f.getUser();
136         },
137         getUser : function() {
138            if (!$.f.runFunction) { $.f.runFunction = []; }
139            var n = $.f.runFunction.length;
140            var id = trueName + '.f.runFunction[' + n + ']';
141            $.f.runFunction[n] = function(r) {
142               delete($.f.runFunction[n]);
143               var a = document.createElement('A');
144               a.rel = $.a.group;
145               a.rev = r.fullname; 
146               a.id = r.nickname;
147               $.f.removeScript(id);
148               $.f.changeUserTo(a);
149            };
150            var url = 'https://' + $.a.server + '/api/statusnet/groups/show/' + $.a.group + '.json?callback=' + id;
151            $.f.runScript(url, id);
152         },
153         changeUserTo : function(el) {
154            $.a.user = el.rel;
155            $.s.h.a.innerHTML = el.rev + $.a.headerText;
156            $.s.h.a.href = 'https://' + $.a.server + '/group/' + el.id;
157            $.f.runSearch(); 
158         },
159         runSearch : function() {
160            $.s.h.className = 'loading';
161            $.s.r.innerHTML = '';
162            if (!$.f.runFunction) { $.f.runFunction = []; }
163            var n = $.f.runFunction.length;
164            var id = trueName + '.f.runFunction[' + n + ']';
165            $.f.runFunction[n] = function(r) {
166               delete($.f.runFunction[n]);
167               $.f.removeScript(id);
168               $.f.renderResult(r); 
169            };
170            var url = 'https://' + $.a.server + '/api/statusnet/groups/timeline/' + $.a.group + '.json?callback=' + id;
171            $.f.runScript(url, id);
172         },
173         renderResult: function(r) { 
174            for (var i = 0; i < r.length; i++) {
175               if (!r[i]) {
176                  r.splice(i, 1);
177               } else {
178                  r[i].id = parseInt(r[i].id);
179               }
180            }
181            r = $.f.sortArray(r, "id", true);
182            $.s.h.className = '';
183            for (var i = 0; i < r.length; i++) {
184               var li = document.createElement('LI');
185               var icon = document.createElement('A');
186               if (r[i].user && r[i].user.url) {
187                  icon.href = r[i].user.url;
188                  icon.target = '_laconica'; 
189                  icon.title = 'Visit ' + r[i].user.screen_name + ' at ' + r[i].user.url;
190               } else {
191                  icon.href = 'https://' + $.a.server + '/' + r[i].user.screen_name;
192                  icon.target = '_laconica'; 
193                  icon.title = 'Visit ' + r[i].user.screen_name + ' at https://' + $.a.server + '/' + r[i].user.screen_name;
194               }
195
196               var img = document.createElement('IMG');
197               img.src = r[i].user.profile_image_url;
198               icon.appendChild(img);
199               li.appendChild(icon); 
200               
201               var user = document.createElement('CITE');
202               var a = document.createElement('A');
203               a.rel = r[i].user.id;
204               a.rev = r[i].user.name;
205               a.id = r[i].user.screen_name;
206               a.innerHTML = r[i].user.name; 
207               if (r[i].user.statusnet_profile_url) {
208                 a.href = r[i].user.statusnet_profile_url;
209               } else {
210                 a.href = 'https://' + $.a.server + '/' + r[i].screen_name;
211               }
212               a.target = '_laconica';
213               user.appendChild(a);
214               li.appendChild(user);
215               var updated = document.createElement('DATE');
216               if (r[i] && r[i].created_at) {
217                  var date_link = document.createElement('A');
218                  date_link.innerHTML = r[i].created_at.split(/\+/)[0];
219                  date_link.href = 'https://' + $.a.server + '/notice/' + r[i].id;
220                  date_link.target = '_laconica';
221                  updated.appendChild(date_link);
222                  if (r[i].in_reply_to_status_id) {
223                     updated.appendChild(document.createTextNode(' in reply to '));
224                     var in_reply_to = document.createElement('A');
225                     in_reply_to.innerHTML = r[i].in_reply_to_status_id;
226                     in_reply_to.href = 'https://' + $.a.server + '/conversation/' + r[i].statusnet_conversation_id + '#notice-' + r[i].in_reply_to_status_id;
227                     in_reply_to.target = '_laconica';
228                     updated.appendChild(in_reply_to);
229                  }
230               } else {
231                  updated.innerHTML = 'has not updated yet';
232               }
233               li.appendChild(updated);
234               var p = document.createElement('P');
235               if (r[i] && r[i].statusnet_html) {
236                  p.innerHTML = r[i].statusnet_html;
237               }
238               li.appendChild(p);
239//               var reply_link = document.createElement('A');
240//               reply_link.innerHTML = '[reply]';
241//               reply_link.href = 'https://' + $.a.server + '/notice/new?replyto='+r[i].user.screen_name + '&inreplyto=' + r[i].id + '&status=@' + r[i].user.screen_name
242//               li.appendChild(reply_link);
243               var a = p.getElementsByTagName('A');
244               for (var j = 0; j < a.length; j++) {
245                  if (a[j].className == 'changeUserTo') {
246                     a[j].className = '';
247                     a[j].href = 'https://' + $.a.server + '/' + a[j].innerHTML;
248                     a[j].rel = a[j].innerHTML;
249                     a[j].onclick = function() { 
250                        $.f.changeUserTo(this); 
251                        return false;
252                     } 
253                  }
254               }
255               $.s.r.appendChild(li);
256            }         
257         },
258         sortArray : function(r, k, x) {
259            if (window.createPopup) { 
260               return r; 
261            }
262            function s(a, b) {
263               if (x === true) {
264                   return b[k] - a[k];
265               } else {
266                   return a[k] - b[k];
267               }
268            }
269            r = r.sort(s);
270            return r;
271         },         
272         runScript : function(url, id) {
273            var s = document.createElement('script');
274            s.id = id;
275            s.type ='text/javascript';
276            s.src = url;
277            document.getElementsByTagName('body')[0].appendChild(s);
278         },
279         removeScript : function(id) {
280            if (document.getElementById(id)) {
281               var s = document.getElementById(id);
282               s.parentNode.removeChild(s);
283            }
284         }         
285      };
286   }();
287//   var thisScript = /^https?:\/\/[^\/]*r8ar.com\/identica-badge.js$/;
288   var thisScript = /statusnet-group-badge.js$/;
289   if(typeof window.addEventListener !== 'undefined') {
290      window.addEventListener('load', function() { $.f.init(thisScript); }, false);
291   } else if(typeof window.attachEvent !== 'undefined') {
292      window.attachEvent('onload', function() { $.f.init(thisScript); });
293   }
294} )()

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.