-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (33 loc) · 1.17 KB
/
background.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
console.log("backgroundjs")
chrome.runtime.onMessage.addListener(function(message, sender, callback) {
console.log("onMessage", message, sender, callback)
if (message.command === 'loadYTApi') {
//chrome.tabs.query( {active: true }, function(tabs) {
console.log("tab", arguments);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = "https://www.youtube.com/iframe_api";
ga.addEventListener('load', function() {
console.log('YT', arguments, YT)
})
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();/*
fetch("https://www.youtube.com/iframe_api", { mode: 'no-cors', headers: { 'Content-Type': 'text/javascript' } }).then(function(result) {
result.text().then(function(script) {
console.log("script", result, callback, tabs[0].id)
chrome.tabs.executeScript(tabs[0].id, {code: script});
callback(script);
});
});*/
//});
return true;
}
});
function onYouTubeIframeAPIReady() {
chrome.tabs.query( {active: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { command: "loadYTiframes", YT: YT });
});
}