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