@@ -158,26 +158,29 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
158
158
159
159
chrome . browserAction . onClicked . addListener ( function ( e ) {
160
160
var lastPlayingTabId = parseInt ( DataStorage . get ( 'lastPlayingTabId' ) ) ,
161
+ lastPlayingFrameId = parseInt ( DataStorage . get ( 'lastPlayingFrameId' ) ) || 0 ,
161
162
lastPausedTabId = parseInt ( DataStorage . get ( 'lastPausedTabId' ) ) ,
163
+ lastPausedFrameId = parseInt ( DataStorage . get ( 'lastPausedFrameId' ) ) || 0 ,
162
164
status = DataStorage . get ( 'status' ) ;
163
165
164
166
switch ( status ) {
165
167
case "playing" :
166
168
if ( lastPlayingTabId ) {
167
- chrome . tabs . sendMessage ( lastPlayingTabId , { action : 'pause' } ) ;
169
+ chrome . tabs . sendMessage ( lastPlayingTabId , { action : 'pause' } , { frameId : lastPlayingFrameId } ) ;
168
170
}
169
171
break ;
170
172
171
173
case "paused" :
172
174
if ( lastPlayingTabId ) {
173
- chrome . tabs . sendMessage ( lastPlayingTabId , { action : 'play' } ) ;
175
+ chrome . tabs . sendMessage ( lastPausedTabId , { action : 'play' } , { frameId : lastPausedFrameId } ) ;
174
176
}
175
177
break ;
176
178
}
177
179
} )
178
180
179
181
chrome . runtime . onMessage . addListener ( function ( request , sender , sendResponse ) {
180
182
var lastPlayingTabId = parseInt ( DataStorage . get ( 'lastPlayingTabId' ) ) ,
183
+ lastPlayingFrameId = parseInt ( DataStorage . get ( 'lastPlayingFrameId' ) ) || 0 ,
181
184
lastPausedTabId = parseInt ( DataStorage . get ( 'lastPausedTabId' ) ) ,
182
185
status = DataStorage . get ( 'status' ) ;
183
186
@@ -191,23 +194,24 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
191
194
break ;
192
195
193
196
case 'started' :
194
- if ( lastPlayingTabId && sender . tab . id != lastPlayingTabId ) {
195
- chrome . tabs . sendMessage ( lastPlayingTabId , { action : 'pause' } ) ;
197
+ var isFrameIdChanged = ( lastPlayingTabId && sender . frameId != lastPlayingFrameId ) ;
198
+ if ( lastPlayingTabId && sender . tab . id != lastPlayingTabId || isFrameIdChanged ) {
199
+ chrome . tabs . sendMessage ( lastPlayingTabId , { action : 'pause' } , { frameId : lastPlayingFrameId } ) ;
196
200
}
197
201
DataStorage . set ( 'lastPlayingTabId' , sender . tab . id ) ;
202
+ DataStorage . set ( 'lastPlayingFrameId' , sender . frameId ) ;
198
203
DataStorage . set ( 'status' , 'playing' ) ;
199
204
chrome . browserAction . setIcon ( { path : STOP_ICON } ) ;
200
-
201
205
if ( request . title ) {
202
206
chrome . browserAction . setTitle ( { title : "Playing: " + request . title } ) ;
203
207
} else {
204
208
chrome . browserAction . setTitle ( { title : "Playing: " + sender . tab . title } ) ;
205
209
}
206
-
207
210
break ;
208
211
209
212
case 'paused' :
210
213
DataStorage . set ( 'lastPausedTabId' , sender . tab . id ) ;
214
+ DataStorage . set ( 'lastPausedFrameId' , sender . frameId ) ;
211
215
DataStorage . set ( 'status' , 'paused' ) ;
212
216
chrome . browserAction . setIcon ( { path : PLAY_ICON } ) ;
213
217
chrome . browserAction . setTitle ( { title : "StoPlay" } ) ;
@@ -226,20 +230,22 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
226
230
chrome . commands . onCommand . addListener ( function ( command ) {
227
231
var lastPlayingTabId = parseInt ( DataStorage . get ( 'lastPlayingTabId' ) ) ,
228
232
lastPausedTabId = parseInt ( DataStorage . get ( 'lastPausedTabId' ) ) ,
233
+ lastPausedFrameId = parseInt ( DataStorage . get ( 'lastPausedFrameId' ) ) || 0 ,
229
234
status = DataStorage . get ( 'status' ) ;
230
235
if ( lastPlayingTabId ) {
231
236
var action = ( status == 'playing' ) ? 'pause' : 'play' ;
232
- chrome . tabs . sendMessage ( lastPlayingTabId , { action : action } ) ;
237
+ chrome . tabs . sendMessage ( lastPlayingTabId , { action : action } , { frameId : lastPausedFrameId } ) ;
233
238
}
234
239
} ) ;
235
240
chrome . tabs . onRemoved . addListener ( function ( tabId ) {
236
241
var lastPlayingTabId = parseInt ( DataStorage . get ( 'lastPlayingTabId' ) ) ,
237
- lastPausedTabId = parseInt ( DataStorage . get ( 'lastPausedTabId' ) ) ;
238
-
242
+ lastPausedTabId = parseInt ( DataStorage . get ( 'lastPausedTabId' ) ) ,
243
+ lastPausedFrameId = parseInt ( DataStorage . get ( 'lastPausedFrameId' ) ) || 0 ;
239
244
if ( tabId == lastPlayingTabId ) {
240
245
DataStorage . set ( 'lastPlayingTabId' , null ) ;
241
246
if ( lastPausedTabId != tabId ) {
242
- chrome . tabs . sendMessage ( lastPausedTabId , { action : 'play' } ) ;
247
+ chrome . tabs . sendMessage ( lastPausedTabId , { action : 'play' } , { frameId : lastPausedFrameId } ) ;
243
248
}
244
249
}
245
250
} ) ;
251
+
0 commit comments