|
|
@ -18,32 +18,49 @@ 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...",
|
|
|
|
contexts: ["link"],
|
|
|
|
contexts: ["link", "video"],
|
|
|
|
id: CONTEXT_MENU_ID
|
|
|
|
id: CONTEXT_MENU_ID
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function parseYoutubeURL(url) {
|
|
|
|
function addToStammTVHandler(info, tab) {
|
|
|
|
const YOUTUBE_URL_REGEX = /^https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)([^#&?]*)(?:[?&]t=\d+)?.*/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let match = url.match(YOUTUBE_URL_REGEX);
|
|
|
|
const YOUTUBE_URL_REGEX = /^https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)([^#&?]*)(?:[?&]t=\d+)?.*/;
|
|
|
|
return (match && match[1].length === 11) ? match[1] : false;
|
|
|
|
const INVIDIOUS_API_REGEX = /^https:\/\/inv\.theresno.cloud\/latest_version\?.*id=([a-zA-Z0-9_/-]{11}).*/;
|
|
|
|
}
|
|
|
|
const INVIDIOUS_VIDEO_URL_REGEX = /^https:\/\/inv\.theresno.cloud\/watch\?v=([a-zA-Z0-9_/-]{11}).*/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function parseYoutubeURL(url) {
|
|
|
|
|
|
|
|
let ytMatch = url.match(YOUTUBE_URL_REGEX);
|
|
|
|
|
|
|
|
if (ytMatch && ytMatch[1].length === 11) {
|
|
|
|
|
|
|
|
return ytMatch[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let apiMatch = url.match(INVIDIOUS_API_REGEX);
|
|
|
|
|
|
|
|
if (apiMatch && apiMatch[1].length === 11) {
|
|
|
|
|
|
|
|
return apiMatch[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let invMatch = url.match(INVIDIOUS_VIDEO_URL_REGEX);
|
|
|
|
|
|
|
|
if (invMatch && invMatch[1].length === 11) {
|
|
|
|
|
|
|
|
return invMatch[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
console.log('clicked!');
|
|
|
|
console.log('clicked!');
|
|
|
|
|
|
|
|
|
|
|
|
let videoId = parseYoutubeURL(info.linkUrl);
|
|
|
|
let videoURL = info.linkUrl ? info.linkUrl : info.srcUrl;
|
|
|
|
if (videoId) {
|
|
|
|
if (videoURL) {
|
|
|
|
let websocket;
|
|
|
|
let websocket;
|
|
|
|
chrome.storage.local.get('wssURL', function (result) {
|
|
|
|
chrome.storage.local.get('wssURL', function (result) {
|
|
|
|
if (result.wssURL) {
|
|
|
|
if (result.wssURL) {
|
|
|
|
|
|
|
|
if (parseYoutubeURL(videoURL)) {
|
|
|
|
|
|
|
|
videoURL = 'https://inv.theresno.cloud/latest_version?id=' + parseYoutubeURL(videoURL)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
websocket = new WebSocket(result.wssURL);
|
|
|
|
websocket = new WebSocket(result.wssURL);
|
|
|
|
|
|
|
|
|
|
|
|
const playerReady = {"type": "playerReady"};
|
|
|
|
const playerReady = {"type": "playerReady"};
|
|
|
|
const setVideo = {type: "setVideo", video: videoId,};
|
|
|
|
const setVideo = {type: "setVideo", video: videoURL};
|
|
|
|
|
|
|
|
|
|
|
|
websocket.onopen = function () {
|
|
|
|
websocket.onopen = function () {
|
|
|
|
console.log('[open] Connection established');
|
|
|
|
console.log('[open] Connection established');
|
|
|
|