|
|
|
@ -1,8 +1,4 @@
|
|
|
|
|
chrome.contextMenus.onClicked.addListener(addToStammTV);
|
|
|
|
|
|
|
|
|
|
let WEBSOCKET_URL;
|
|
|
|
|
let websocket;
|
|
|
|
|
const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST";
|
|
|
|
|
chrome.contextMenus.onClicked.addListener(addToStammTVHandler);
|
|
|
|
|
|
|
|
|
|
chrome.runtime.onInstalled.addListener(function (details) {
|
|
|
|
|
if (details.reason === "install") {
|
|
|
|
@ -17,6 +13,8 @@ chrome.runtime.onInstalled.addListener(function (details) {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST";
|
|
|
|
|
|
|
|
|
|
chrome.contextMenus.removeAll(function () {
|
|
|
|
|
chrome.contextMenus.create({
|
|
|
|
|
title: "Zu StammTV Playlist hinzufügen...",
|
|
|
|
@ -33,47 +31,50 @@ function parseYoutubeURL(url) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addToStammTV(info, tab) {
|
|
|
|
|
function addToStammTVHandler(info, tab) {
|
|
|
|
|
if (info.menuItemId === CONTEXT_MENU_ID) { //if OUR menu item was clicked
|
|
|
|
|
let videoId = parseYoutubeURL(info.linkUrl)
|
|
|
|
|
console.log('clicked!');
|
|
|
|
|
|
|
|
|
|
let videoId = parseYoutubeURL(info.linkUrl);
|
|
|
|
|
if (videoId) {
|
|
|
|
|
if (websocket === undefined
|
|
|
|
|
|| websocket.readyState !== WebSocket.OPEN) {
|
|
|
|
|
chrome.storage.local.get('wssURL', function (result) {
|
|
|
|
|
if (result.wssURL) {
|
|
|
|
|
WEBSOCKET_URL = result.wssURL;
|
|
|
|
|
} else {
|
|
|
|
|
chrome.runtime.openOptionsPage();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
websocket = new WebSocket(WEBSOCKET_URL);
|
|
|
|
|
console.log('websocket created');
|
|
|
|
|
} else {
|
|
|
|
|
console.error('websocket undefined or not OPEN')
|
|
|
|
|
}
|
|
|
|
|
let websocket;
|
|
|
|
|
chrome.storage.local.get('wssURL', function (result) {
|
|
|
|
|
if (result.wssURL) {
|
|
|
|
|
websocket = new WebSocket(result.wssURL);
|
|
|
|
|
|
|
|
|
|
const playerReady = {"type": "playerReady"};
|
|
|
|
|
const setVideo = {type: "setVideo", video: videoId,};
|
|
|
|
|
|
|
|
|
|
websocket.onopen = function () {
|
|
|
|
|
console.log('websocket ready - sending');
|
|
|
|
|
websocket.onopen = function () {
|
|
|
|
|
console.log('[open] Connection established');
|
|
|
|
|
|
|
|
|
|
const playerReady = {"type": "playerReady"};
|
|
|
|
|
websocket.send(JSON.stringify(playerReady));
|
|
|
|
|
console.log(playerReady);
|
|
|
|
|
websocket.send(JSON.stringify(playerReady));
|
|
|
|
|
websocket.send(JSON.stringify(setVideo));
|
|
|
|
|
|
|
|
|
|
const setVideo = {
|
|
|
|
|
type: "setVideo",
|
|
|
|
|
video: videoId,
|
|
|
|
|
};
|
|
|
|
|
websocket.send(JSON.stringify(setVideo));
|
|
|
|
|
console.log(setVideo);
|
|
|
|
|
};
|
|
|
|
|
setTimeout(() => websocket.close(), 5000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
websocket.close();
|
|
|
|
|
console.log('websocket closed');
|
|
|
|
|
}, 1000);
|
|
|
|
|
websocket.onmessage = function (event) {
|
|
|
|
|
console.log(`[message] Data received from server: ${event.data}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
websocket.onclose = function (event) {
|
|
|
|
|
if (event.wasClean) {
|
|
|
|
|
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log('[close] Connection died');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
websocket.onerror = function (error) {
|
|
|
|
|
alert(`[error] ${error.message}`);
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
chrome.runtime.openOptionsPage();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.error('o(一︿一+)o not a valid videoId');
|
|
|
|
|
console.error('failed to add ' + info.linkurl + ': o(一︿一+)o not a valid link');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|