root/lang/javascript/vimperator-plugins/trunk/ego_counter.js

Revision 35120, 1.3 kB (checked in by snaka, 12 months ago)

- エンコードを修正
- 任意のURIを渡せるように

Line 
1/*
2 * ステータスバーにはてブ数を表示
3 *
4 * Usage:
5 *   let g:ego_counter_uri = 'Your site URI'
6 *     or
7 *   js liberator.globalVariables.ego_counter_hatenaId = 'Your site URI'
8 *
9 *   ex.
10 *   let g:ego_counter_uri = 'http://d.hatena.ne.jp/snaka72'
11 *
12 */
13(function() {
14
15  const MY_SITE = liberator.globalVariables.ego_counter_uri || '';
16  let update = function(color) {
17    myHatebu.setAttribute(
18      'src',
19      <>http://b.hatena.ne.jp/bc/{color}/{MY_SITE}/</>.toSource()
20    );
21  };
22
23  let rotate = (function() {
24    var current;
25    var colors = "bl de dg gr pr br rd sp pk te lg lb wh li or".split(" ");
26
27    return function(next) {
28      if (!next) return current;
29
30      current = colors.shift();
31      colors.push(current);
32      return current;
33    };
34  })();
35
36  let myHatebu = document.getElementById('status-bar')
37                 .insertBefore(document.createElement('statusbarpanel'),
38                               document.getElementById('security-button')
39                               .nextSibling);
40  myHatebu.setAttribute('id', 'my-hatebu-count-icon');
41  myHatebu.setAttribute('class', 'statusbarpanel-iconic');
42  update(rotate(true));
43
44  setInterval(function() update(rotate(true)), 1000 * 60 * 10);
45  myHatebu.addEventListener("click", function(event){
46    update(rotate(true));
47  }, false);
48
49})()
Note: See TracBrowser for help on using the browser.