2022-01-15 06:03:44 +00:00
|
|
|
/*
|
|
|
|
content script running on youtube.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
console.log("running script.js");
|
|
|
|
|
|
|
|
let browserType = getBrowser();
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
console.log("running setimeout")
|
2022-03-31 16:28:53 +00:00
|
|
|
sendUrl();
|
2022-01-15 06:03:44 +00:00
|
|
|
return false;
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
// boilerplate to dedect browser type api
|
|
|
|
function getBrowser() {
|
|
|
|
if (typeof chrome !== "undefined") {
|
|
|
|
if (typeof browser !== "undefined") {
|
|
|
|
console.log("detected firefox");
|
|
|
|
return browser;
|
|
|
|
} else {
|
|
|
|
console.log("detected chrome");
|
|
|
|
return chrome;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log("failed to dedect browser");
|
|
|
|
throw "browser detection error"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-31 16:28:53 +00:00
|
|
|
function sendUrl() {
|
|
|
|
console.log("run sendUrl from script.js");
|
2022-01-15 06:03:44 +00:00
|
|
|
|
|
|
|
let payload = {
|
2022-03-31 16:28:53 +00:00
|
|
|
"youtube": {
|
|
|
|
"url": document.URL,
|
|
|
|
"title": document.title
|
2022-01-15 06:03:44 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-31 16:28:53 +00:00
|
|
|
console.log(JSON.stringify(payload));
|
|
|
|
browserType.runtime.sendMessage(payload, function(response) {
|
|
|
|
console.log(response.farewell);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|