Revisions

gist: 212625 Download_button fork
public
Public Clone URL: git://gist.github.com/212625.git
Embed All Files: show embed
ldr_icons.user.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// ==UserScript==
// @name LDR icons
// @namespace http://d.hatena.ne.jp/Constellation
// @description add icons to LDR
// @include http://reader.livedoor.com/reader/
// ==/UserScript==
// by
// http://gist.github.com/77088
// http://d.hatena.ne.jp/gan2/20080430/1209538698
 
let filters = {
  'GitHub & CodeRepos' : {
    pattern : /(?:^https?:\/\/coderepos.org\/share\/$|^https?:\/\/github\.com)/,
    filter : function(feed){
      feed.items.forEach(function(item){
        if(!/^<img class="ldrcodeicon"/(item.body)){
          let img_url = 'http://usericons.relucks.org/github/' + item.author;
          new Image().src = img_url;
          item.body = '<img class="ldrcodeicon" src="' +
            img_url + '" style="float:left;margin-right:5px;width:48px;height:48px;" /> ' +
            item.body + '<br style="clear:left;" />';
        }
      });
    }
  },
  'BitBucket' : {
    pattern : /^https?:\/\/bitbucket\.org/,
    filter : function(feed){
      feed.items.forEach(function(item){
        if(!/^<img class="ldrcodeicon"/(item.body)){
          let author = item.title.match(/^\s*([^\s]+)/)[1];
          let img_url = 'http://usericons.relucks.org/github/' + author;
          new Image().src = img_url;
          item.body = '<img class="ldrcodeicon" src="' +
            img_url + '" style="float:left;margin-right:5px;width:48px;height:48px;" /> ' +
            item.body + '<br style="clear:left;" />';
        }
      });
    }
  }
};
unsafeWindow.register_hook('before_printfeed', function(feed){
  for each(let {pattern, filter} in filters) pattern(feed.channel.link || feed.channel.feedlink) && filter(feed)
});