douban_fm_hotkey 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ea50a236e70efc8eadc2521d0d4b71dfc7958aa
4
- data.tar.gz: 89d8172e0e38078b13fb6ed39453f7dbb5fce28d
3
+ metadata.gz: d948984d0443ce13dc2b7e3ab74dceaf2cdad183
4
+ data.tar.gz: 5afbee5ee50c18eb1d04e2945b5d41b926c5e7c4
5
5
  SHA512:
6
- metadata.gz: 123341314c1668ff2c92edf3e7608f4379727d08ef22aeda1173da6be0e235312a389b88c8a0392a4ae4a664cc9751d53545dabf8e53beb94e707a1a0249a86c
7
- data.tar.gz: 70de7fe52097fb0854298c1b8c1d97eebf8203960e78f4365ff100a19268f8f0b3b870d83b146b338ce56a6fad566033e5fea43f8ca0235c8834861cecbb6268
6
+ metadata.gz: bd4003f2878db1f770bdecacfe12b0f3d0f3e2cffc1355ce2d118182b2d567a0a7be4c78be1045feae381366b87d8d6a01b6182b2dbea7664a44bf57b0df9e8e
7
+ data.tar.gz: 59615351cea6d2281c98b68869d66f604f8fb660b239ff1e3a16f149691f1bb95803fae853c205c1d7915e38f6f5b1c5d75eaac429c33e209c5bfbcd71f1d866
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- douban_fm_hotkey (1.0.2)
4
+ douban_fm_hotkey (1.1.0)
5
5
  faye
6
6
  sinatra
7
7
  thin
@@ -0,0 +1,100 @@
1
+ (function() {
2
+
3
+ var client = new Faye.Client('http://localhost:1988/faye');
4
+
5
+ client.subscribe('/hotkey', function(msg) {
6
+ var songInfo = getSongInfo();
7
+ if (msg.cmd == 'info') {
8
+ sendNotification(songInfo.song.coverUrl, songInfo.song.artistName, songInfo.song.songName);
9
+ } else {
10
+ window.DBR.act(msg.cmd);
11
+ if (msg.cmd == 'pause' || msg.cmd == 'love') {
12
+ publishSongInfo(songInfo);
13
+ if (msg.cmd == 'love') {
14
+ var img;
15
+ if (window.DBR.selected_like()) {
16
+ img = 'like.png'
17
+ } else {
18
+ img = 'unlike.png'
19
+ }
20
+ sendNotification('http://localhost:1988/' + img, songInfo.song.artistName, songInfo.song.songName);
21
+ }
22
+ }
23
+ }
24
+ });
25
+
26
+ client.subscribe('/get_info', function() {
27
+ publishSongInfo(getSongInfo());
28
+ });
29
+
30
+ var interval = window.setInterval(function() {
31
+ if (window.extStatusHandler) {
32
+ clearInterval(interval);
33
+ var originExtStatusHandler = window.extStatusHandler;
34
+ window.extStatusHandler = function(info) {
35
+ var parsedInfo = $.parseJSON(info);
36
+ if (parsedInfo.type == 'start') {
37
+ var songInfo = {
38
+ song: {
39
+ artistName: parsedInfo.song.artist,
40
+ channelName: getChannelName(parsedInfo.channel),
41
+ coverUrl: parsedInfo.song.picture,
42
+ songName: parsedInfo.song.title
43
+ },
44
+ radio: {
45
+ is_paused: false,
46
+ selected_like: parsedInfo.song.like
47
+ }
48
+ };
49
+ publishSongInfo(songInfo);
50
+ sendNotification(songInfo.song.coverUrl, songInfo.song.artistName, songInfo.song.songName);
51
+ }
52
+ originExtStatusHandler(info);
53
+ };
54
+ }
55
+ }, 100);
56
+
57
+ var getSongInfo = function() {
58
+ return {
59
+ song: window.FM.getCurrentSongInfo(),
60
+ radio: {
61
+ is_paused: window.DBR.is_paused(),
62
+ selected_like: window.DBR.selected_like()
63
+ }
64
+ };
65
+ };
66
+
67
+ var sendNotification = function(image, title, content) {
68
+ if (window.webkitNotifications.checkPermission() == 0) {
69
+ var notification = window.webkitNotifications.createNotification(
70
+ image, title, content
71
+ );
72
+ notification.onshow = function() {
73
+ setTimeout(function() {
74
+ notification.close()
75
+ }, 5000);
76
+ };
77
+ notification.show();
78
+ } else {
79
+ window.webkitNotifications.requestPermission();
80
+ }
81
+ };
82
+
83
+ var publishSongInfo = function(info) {
84
+ client.publish('/info', info);
85
+ };
86
+
87
+ var getChannelName = function(id) {
88
+ id = parseInt(id, 10);
89
+ if (id === 0 || id === -9) {
90
+ return "私人兆赫"
91
+ } else {
92
+ if (id === -3 || id === -8) {
93
+ return "红心兆赫"
94
+ } else {
95
+ return $("#fm-channel-list .channel[cid=" + id + "] .chl_name").first().text()
96
+ }
97
+ }
98
+ }
99
+
100
+ })();
@@ -2,7 +2,7 @@ $(function() {
2
2
 
3
3
  var client = new Faye.Client('/faye');
4
4
 
5
- client.subscribe('/state', function(message) {
5
+ client.subscribe('/info', function(message) {
6
6
  console.log(message);
7
7
  $pause_button = $('button.pause');
8
8
  $love_button = $('button.love');
@@ -22,7 +22,7 @@ $(function() {
22
22
  $('#song-name').html('歌名: ' + message.song.songName);
23
23
  });
24
24
 
25
- client.publish('/get_state', {ping: 1});
25
+ client.publish('/get_info', { get: 1 });
26
26
 
27
27
  $buttons = $('button');
28
28
  $buttons.click(function() {
@@ -5,7 +5,7 @@
5
5
  <title>Douban FM Hotkey</title>
6
6
  <script type="text/javascript" src="faye.js"></script>
7
7
  <script type="text/javascript" src="jquery.js"></script>
8
- <script type="text/javascript" src="app.js"></script>
8
+ <script type="text/javascript" src="server.js"></script>
9
9
  <link rel="stylesheet" href="style.css" />
10
10
  </head>
11
11
  <body>
@@ -34,7 +34,7 @@ module DoubanFMHotkey
34
34
  erb :index
35
35
  end
36
36
 
37
- %w{skip pause love ban}.each do |cmd|
37
+ %w{skip pause love ban info}.each do |cmd|
38
38
  get "/#{cmd}" do
39
39
  @client.publish('/hotkey', {cmd: cmd})
40
40
  end
@@ -1,3 +1,3 @@
1
1
  module DoubanFMHotkey
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: douban_fm_hotkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wei Zhu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-17 00:00:00.000000000 Z
11
+ date: 2013-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye
@@ -95,9 +95,12 @@ files:
95
95
  - bin/douban_fm_hotkey
96
96
  - douban_fm_hotkey.gemspec
97
97
  - lib/douban_fm_hotkey/server.rb
98
- - lib/douban_fm_hotkey/server/public/app.js
98
+ - lib/douban_fm_hotkey/server/public/client.js
99
99
  - lib/douban_fm_hotkey/server/public/jquery.js
100
+ - lib/douban_fm_hotkey/server/public/like.png
101
+ - lib/douban_fm_hotkey/server/public/server.js
100
102
  - lib/douban_fm_hotkey/server/public/style.css
103
+ - lib/douban_fm_hotkey/server/public/unlike.png
101
104
  - lib/douban_fm_hotkey/server/views/index.erb
102
105
  - lib/douban_fm_hotkey/server/views/layout.erb
103
106
  - lib/douban_fm_hotkey/version.rb