-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetJQuery.js
More file actions
30 lines (27 loc) · 722 Bytes
/
getJQuery.js
File metadata and controls
30 lines (27 loc) · 722 Bytes
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
var _ajax=$.ajax,
sendData=function(data,name){
document.dispatchEvent(new CustomEvent(name, {'detail': data}));
},
idSuccess=function(id){
sendData(id,'idReturned');
},
idFailure=function(id){
sendData('nothing','idNotReturned');
};
var sendId = function(json) {
if (json && json.items && json.items.length) {
var youtubeId = json.items[0].id.videoId;
idSuccess(youtubeId);
} else {
idFailure();
}
};
$.ajax = function(argHsh) {
if(argHsh.url.match(/www.googleapis.com\/youtube\/v3\/search/)) {
argHsh.success=sendId;
_ajax.apply($,[argHsh]);
} else {
_ajax.apply($,arguments);
}
}
// chrome.storage.sync.set({'mp3IDs': this.ids.join(' ')})