From 2a3b3fd4951f9210072915c62416d06a58eb82a2 Mon Sep 17 00:00:00 2001 From: and94x Date: Fri, 12 Aug 2022 19:48:56 +0200 Subject: [PATCH] init --- .idea/.gitignore | 8 +++ .idea/artifacts/chrome.xml | 9 +++ .idea/artifacts/firefox.xml | 9 +++ .idea/misc.xml | 6 ++ .idea/modules.xml | 11 ++++ README.md | 5 ++ base/base.iml | 8 +++ base/options/options.html | 21 +++++++ base/options/options.js | 32 ++++++++++ base/popup/popup.html | 11 ++++ base/popup/popup.js | 7 +++ base/script.js | 72 ++++++++++++++++++++++ chrome/chrome.iml | 8 +++ chrome/manifest.json | 17 +++++ firefox/firefox.iml | 8 +++ firefox/manifest.json | 17 +++++ out/artifacts/chrome/base.iml | 8 +++ out/artifacts/chrome/chrome.iml | 8 +++ out/artifacts/chrome/manifest.json | 17 +++++ out/artifacts/chrome/options/options.html | 21 +++++++ out/artifacts/chrome/options/options.js | 32 ++++++++++ out/artifacts/chrome/popup/popup.html | 11 ++++ out/artifacts/chrome/popup/popup.js | 7 +++ out/artifacts/chrome/script.js | 58 +++++++++++++++++ out/artifacts/firefox/base.iml | 8 +++ out/artifacts/firefox/firefox.iml | 8 +++ out/artifacts/firefox/manifest.json | 17 +++++ out/artifacts/firefox/options/options.html | 21 +++++++ out/artifacts/firefox/options/options.js | 32 ++++++++++ out/artifacts/firefox/popup/popup.html | 11 ++++ out/artifacts/firefox/popup/popup.js | 7 +++ out/artifacts/firefox/script.js | 58 +++++++++++++++++ stammtv-browserext.iml | 8 +++ 33 files changed, 581 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/artifacts/chrome.xml create mode 100644 .idea/artifacts/firefox.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 README.md create mode 100644 base/base.iml create mode 100644 base/options/options.html create mode 100644 base/options/options.js create mode 100644 base/popup/popup.html create mode 100644 base/popup/popup.js create mode 100644 base/script.js create mode 100644 chrome/chrome.iml create mode 100644 chrome/manifest.json create mode 100644 firefox/firefox.iml create mode 100644 firefox/manifest.json create mode 100644 out/artifacts/chrome/base.iml create mode 100644 out/artifacts/chrome/chrome.iml create mode 100644 out/artifacts/chrome/manifest.json create mode 100644 out/artifacts/chrome/options/options.html create mode 100644 out/artifacts/chrome/options/options.js create mode 100644 out/artifacts/chrome/popup/popup.html create mode 100644 out/artifacts/chrome/popup/popup.js create mode 100644 out/artifacts/chrome/script.js create mode 100644 out/artifacts/firefox/base.iml create mode 100644 out/artifacts/firefox/firefox.iml create mode 100644 out/artifacts/firefox/manifest.json create mode 100644 out/artifacts/firefox/options/options.html create mode 100644 out/artifacts/firefox/options/options.js create mode 100644 out/artifacts/firefox/popup/popup.html create mode 100644 out/artifacts/firefox/popup/popup.js create mode 100644 out/artifacts/firefox/script.js create mode 100644 stammtv-browserext.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/artifacts/chrome.xml b/.idea/artifacts/chrome.xml new file mode 100644 index 0000000..791b24b --- /dev/null +++ b/.idea/artifacts/chrome.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/chrome + + + + + + \ No newline at end of file diff --git a/.idea/artifacts/firefox.xml b/.idea/artifacts/firefox.xml new file mode 100644 index 0000000..d7e47f3 --- /dev/null +++ b/.idea/artifacts/firefox.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/firefox + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..076afbc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ace007 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +## Build + + +## Prerequisites +- Chromium based Browser (Chrome, Edge, ..) diff --git a/base/base.iml b/base/base.iml new file mode 100644 index 0000000..183c2ef --- /dev/null +++ b/base/base.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/base/options/options.html b/base/options/options.html new file mode 100644 index 0000000..bf4fdab --- /dev/null +++ b/base/options/options.html @@ -0,0 +1,21 @@ + + + + Options for StammTV Chrome Extension + + +
+ + +
+ +
+ + + + + \ No newline at end of file diff --git a/base/options/options.js b/base/options/options.js new file mode 100644 index 0000000..7ef8389 --- /dev/null +++ b/base/options/options.js @@ -0,0 +1,32 @@ +// Saves options to chrome.storage +function save_options() { + var stammTVBaseUrl = document.getElementById('stammtv-base-url').value;; + var stammTVWSSUrl = document.getElementById('stammtv-wss-url').value;; + chrome.storage.local.set({ + baseURL: stammTVBaseUrl, + wssURL: stammTVWSSUrl + }, function () { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Saved.'; + status.style.color = '00FF00'; + setTimeout(function () { + status.textContent = ''; + }, 1500); + }); +} + +// Restores select box and checkbox state using the preferences +// stored in chrome.storage. +function restore_options() { + chrome.storage.local.get({ + baseURL: 'Please fill in.', + wssURL: 'Please fill in.' + }, function (items) { + document.getElementById('stammtv-base-url').value = items.baseURL; + document.getElementById('stammtv-wss-url').value = items.wssURL; + }); +} + +document.addEventListener('DOMContentLoaded', restore_options); +document.getElementById('save').addEventListener('click', save_options); \ No newline at end of file diff --git a/base/popup/popup.html b/base/popup/popup.html new file mode 100644 index 0000000..281016f --- /dev/null +++ b/base/popup/popup.html @@ -0,0 +1,11 @@ + + + + + Popup + + +→ Take me to StammTV! + + + \ No newline at end of file diff --git a/base/popup/popup.js b/base/popup/popup.js new file mode 100644 index 0000000..857c049 --- /dev/null +++ b/base/popup/popup.js @@ -0,0 +1,7 @@ +function restore_options() { + chrome.storage.local.get('baseURL', function (result) { + document.getElementById('open-stammtv').href = result.baseURL; + }); +} + +document.addEventListener('DOMContentLoaded', restore_options); diff --git a/base/script.js b/base/script.js new file mode 100644 index 0000000..5a13e93 --- /dev/null +++ b/base/script.js @@ -0,0 +1,72 @@ +chrome.storage.local.get('firstRun', function (result) { + if (result.firstRun === false) { + firstRun(); + } +}); + +function firstRun(){ + chrome.storage.local.set({'firstRun': false}, function (result) { + chrome.tabs.create + }); + +} + +const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST"; +const YOUTUBE_URL_REGEX = /^(?:https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)){1}([^#&?]*)(?:[?&]t=\d+)?.*/; + +let WEBSOCKET_URL = ""; +let websocket; + + +chrome.storage.local.get('wssURL', function (result) { + WEBSOCKET_URL = result.wssURL; +}); + +chrome.contextMenus.create({ + title: "Zu StammTV Playlist hinzufügen...", + contexts: ["link"], + id: CONTEXT_MENU_ID +}); + +chrome.contextMenus.onClicked.addListener(addToStammTV); + +function parseYoutubeURL(url) { + let match = url.match(YOUTUBE_URL_REGEX); + return (match && match[1].length === 11) ? match[1] : false; +} + +function addToStammTV(info, tab) { + if (info.menuItemId === CONTEXT_MENU_ID) { //if OUR menu item was clicked + let videoId = parseYoutubeURL(info.linkUrl) + if (videoId) { + const playerReady = {"type":"playerReady"}; + + const setVideo = { + type: "setVideo", + video: videoId, + }; + + console.log(websocket); + if (websocket === undefined + || websocket.readyState !== WebSocket.OPEN) { + websocket = new WebSocket(WEBSOCKET_URL); + console.log('websocket created'); + } + + websocket.onopen = function () { + console.log('websocket ready'); + websocket.send(JSON.stringify(playerReady)); + websocket.send(JSON.stringify(setVideo)); + console.log(setVideo); + }; + + setTimeout(function () { + websocket.close(); + console.log('websocket closed'); + }, 1000); + + } else { + console.error('o(一︿一+)o not a valid videoId'); + } + } +} \ No newline at end of file diff --git a/chrome/chrome.iml b/chrome/chrome.iml new file mode 100644 index 0000000..183c2ef --- /dev/null +++ b/chrome/chrome.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/chrome/manifest.json b/chrome/manifest.json new file mode 100644 index 0000000..df26515 --- /dev/null +++ b/chrome/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "StammTV Chrome Extension", + "description": "Adds a context-menu option to send URLs to StammTV", + "version": "1.0", + "manifest_version": 3, + "background": { + "service_worker": "script.js" + }, + "options_page": "options/options.html", + "permissions": [ + "storage", + "contextMenus" + ], + "action": { + "default_popup": "popup/popup.html" + } +} \ No newline at end of file diff --git a/firefox/firefox.iml b/firefox/firefox.iml new file mode 100644 index 0000000..183c2ef --- /dev/null +++ b/firefox/firefox.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/firefox/manifest.json b/firefox/manifest.json new file mode 100644 index 0000000..bcaa621 --- /dev/null +++ b/firefox/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "StammTV Firefox Extension", + "description": "Adds a context-menu option to send URLs to StammTV", + "version": "1.0", + "manifest_version": 2, + "background": { + "scripts": ["script.js"] + }, + "options_page": "options/options.html", + "permissions": [ + "storage", + "contextMenus" + ], + "action": { + "default_popup": "popup/popup.html" + } +} \ No newline at end of file diff --git a/out/artifacts/chrome/base.iml b/out/artifacts/chrome/base.iml new file mode 100644 index 0000000..183c2ef --- /dev/null +++ b/out/artifacts/chrome/base.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/artifacts/chrome/chrome.iml b/out/artifacts/chrome/chrome.iml new file mode 100644 index 0000000..183c2ef --- /dev/null +++ b/out/artifacts/chrome/chrome.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/artifacts/chrome/manifest.json b/out/artifacts/chrome/manifest.json new file mode 100644 index 0000000..df26515 --- /dev/null +++ b/out/artifacts/chrome/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "StammTV Chrome Extension", + "description": "Adds a context-menu option to send URLs to StammTV", + "version": "1.0", + "manifest_version": 3, + "background": { + "service_worker": "script.js" + }, + "options_page": "options/options.html", + "permissions": [ + "storage", + "contextMenus" + ], + "action": { + "default_popup": "popup/popup.html" + } +} \ No newline at end of file diff --git a/out/artifacts/chrome/options/options.html b/out/artifacts/chrome/options/options.html new file mode 100644 index 0000000..bf4fdab --- /dev/null +++ b/out/artifacts/chrome/options/options.html @@ -0,0 +1,21 @@ + + + + Options for StammTV Chrome Extension + + +
+ + +
+ +
+ + + + + \ No newline at end of file diff --git a/out/artifacts/chrome/options/options.js b/out/artifacts/chrome/options/options.js new file mode 100644 index 0000000..7ef8389 --- /dev/null +++ b/out/artifacts/chrome/options/options.js @@ -0,0 +1,32 @@ +// Saves options to chrome.storage +function save_options() { + var stammTVBaseUrl = document.getElementById('stammtv-base-url').value;; + var stammTVWSSUrl = document.getElementById('stammtv-wss-url').value;; + chrome.storage.local.set({ + baseURL: stammTVBaseUrl, + wssURL: stammTVWSSUrl + }, function () { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Saved.'; + status.style.color = '00FF00'; + setTimeout(function () { + status.textContent = ''; + }, 1500); + }); +} + +// Restores select box and checkbox state using the preferences +// stored in chrome.storage. +function restore_options() { + chrome.storage.local.get({ + baseURL: 'Please fill in.', + wssURL: 'Please fill in.' + }, function (items) { + document.getElementById('stammtv-base-url').value = items.baseURL; + document.getElementById('stammtv-wss-url').value = items.wssURL; + }); +} + +document.addEventListener('DOMContentLoaded', restore_options); +document.getElementById('save').addEventListener('click', save_options); \ No newline at end of file diff --git a/out/artifacts/chrome/popup/popup.html b/out/artifacts/chrome/popup/popup.html new file mode 100644 index 0000000..281016f --- /dev/null +++ b/out/artifacts/chrome/popup/popup.html @@ -0,0 +1,11 @@ + + + + + Popup + + +→ Take me to StammTV! + + + \ No newline at end of file diff --git a/out/artifacts/chrome/popup/popup.js b/out/artifacts/chrome/popup/popup.js new file mode 100644 index 0000000..857c049 --- /dev/null +++ b/out/artifacts/chrome/popup/popup.js @@ -0,0 +1,7 @@ +function restore_options() { + chrome.storage.local.get('baseURL', function (result) { + document.getElementById('open-stammtv').href = result.baseURL; + }); +} + +document.addEventListener('DOMContentLoaded', restore_options); diff --git a/out/artifacts/chrome/script.js b/out/artifacts/chrome/script.js new file mode 100644 index 0000000..343fe03 --- /dev/null +++ b/out/artifacts/chrome/script.js @@ -0,0 +1,58 @@ +const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST"; +const YOUTUBE_URL_REGEX = /^(?:https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)){1}([^#&?]*)(?:[?&]t=\d+)?.*/; +let WEBSOCKET_URL = ""; + +let websocket; + +chrome.storage.local.get('wssURL', function (result) { + WEBSOCKET_URL = result.wssURL; +}); + +chrome.contextMenus.create({ + title: "Zu StammTV Playlist hinzufügen...", + contexts: ["link"], + id: CONTEXT_MENU_ID +}); + +chrome.contextMenus.onClicked.addListener(addToStammTV); + +function parseYoutubeURL(url) { + let match = url.match(YOUTUBE_URL_REGEX); + return (match && match[1].length === 11) ? match[1] : false; +} + +function addToStammTV(info, tab) { + if (info.menuItemId === CONTEXT_MENU_ID) { //if OUR menu item was clicked + let videoId = parseYoutubeURL(info.linkUrl) + if (videoId) { + const playerReady = {"type":"playerReady"}; + + const setVideo = { + type: "setVideo", + video: videoId, + }; + + console.log(websocket); + if (websocket === undefined + || websocket.readyState !== WebSocket.OPEN) { + websocket = new WebSocket(WEBSOCKET_URL); + console.log('websocket created'); + } + + websocket.onopen = function () { + console.log('websocket ready'); + websocket.send(JSON.stringify(playerReady)); + websocket.send(JSON.stringify(setVideo)); + console.log(setVideo); + }; + + setTimeout(function () { + websocket.close(); + console.log('websocket closed'); + }, 1000); + + } else { + console.error('o(一︿一+)o not a valid videoId'); + } + } +} \ No newline at end of file diff --git a/out/artifacts/firefox/base.iml b/out/artifacts/firefox/base.iml new file mode 100644 index 0000000..183c2ef --- /dev/null +++ b/out/artifacts/firefox/base.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/artifacts/firefox/firefox.iml b/out/artifacts/firefox/firefox.iml new file mode 100644 index 0000000..183c2ef --- /dev/null +++ b/out/artifacts/firefox/firefox.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/artifacts/firefox/manifest.json b/out/artifacts/firefox/manifest.json new file mode 100644 index 0000000..bcaa621 --- /dev/null +++ b/out/artifacts/firefox/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "StammTV Firefox Extension", + "description": "Adds a context-menu option to send URLs to StammTV", + "version": "1.0", + "manifest_version": 2, + "background": { + "scripts": ["script.js"] + }, + "options_page": "options/options.html", + "permissions": [ + "storage", + "contextMenus" + ], + "action": { + "default_popup": "popup/popup.html" + } +} \ No newline at end of file diff --git a/out/artifacts/firefox/options/options.html b/out/artifacts/firefox/options/options.html new file mode 100644 index 0000000..bf4fdab --- /dev/null +++ b/out/artifacts/firefox/options/options.html @@ -0,0 +1,21 @@ + + + + Options for StammTV Chrome Extension + + +
+ + +
+ +
+ + + + + \ No newline at end of file diff --git a/out/artifacts/firefox/options/options.js b/out/artifacts/firefox/options/options.js new file mode 100644 index 0000000..7ef8389 --- /dev/null +++ b/out/artifacts/firefox/options/options.js @@ -0,0 +1,32 @@ +// Saves options to chrome.storage +function save_options() { + var stammTVBaseUrl = document.getElementById('stammtv-base-url').value;; + var stammTVWSSUrl = document.getElementById('stammtv-wss-url').value;; + chrome.storage.local.set({ + baseURL: stammTVBaseUrl, + wssURL: stammTVWSSUrl + }, function () { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Saved.'; + status.style.color = '00FF00'; + setTimeout(function () { + status.textContent = ''; + }, 1500); + }); +} + +// Restores select box and checkbox state using the preferences +// stored in chrome.storage. +function restore_options() { + chrome.storage.local.get({ + baseURL: 'Please fill in.', + wssURL: 'Please fill in.' + }, function (items) { + document.getElementById('stammtv-base-url').value = items.baseURL; + document.getElementById('stammtv-wss-url').value = items.wssURL; + }); +} + +document.addEventListener('DOMContentLoaded', restore_options); +document.getElementById('save').addEventListener('click', save_options); \ No newline at end of file diff --git a/out/artifacts/firefox/popup/popup.html b/out/artifacts/firefox/popup/popup.html new file mode 100644 index 0000000..281016f --- /dev/null +++ b/out/artifacts/firefox/popup/popup.html @@ -0,0 +1,11 @@ + + + + + Popup + + +→ Take me to StammTV! + + + \ No newline at end of file diff --git a/out/artifacts/firefox/popup/popup.js b/out/artifacts/firefox/popup/popup.js new file mode 100644 index 0000000..857c049 --- /dev/null +++ b/out/artifacts/firefox/popup/popup.js @@ -0,0 +1,7 @@ +function restore_options() { + chrome.storage.local.get('baseURL', function (result) { + document.getElementById('open-stammtv').href = result.baseURL; + }); +} + +document.addEventListener('DOMContentLoaded', restore_options); diff --git a/out/artifacts/firefox/script.js b/out/artifacts/firefox/script.js new file mode 100644 index 0000000..343fe03 --- /dev/null +++ b/out/artifacts/firefox/script.js @@ -0,0 +1,58 @@ +const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST"; +const YOUTUBE_URL_REGEX = /^(?:https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)){1}([^#&?]*)(?:[?&]t=\d+)?.*/; +let WEBSOCKET_URL = ""; + +let websocket; + +chrome.storage.local.get('wssURL', function (result) { + WEBSOCKET_URL = result.wssURL; +}); + +chrome.contextMenus.create({ + title: "Zu StammTV Playlist hinzufügen...", + contexts: ["link"], + id: CONTEXT_MENU_ID +}); + +chrome.contextMenus.onClicked.addListener(addToStammTV); + +function parseYoutubeURL(url) { + let match = url.match(YOUTUBE_URL_REGEX); + return (match && match[1].length === 11) ? match[1] : false; +} + +function addToStammTV(info, tab) { + if (info.menuItemId === CONTEXT_MENU_ID) { //if OUR menu item was clicked + let videoId = parseYoutubeURL(info.linkUrl) + if (videoId) { + const playerReady = {"type":"playerReady"}; + + const setVideo = { + type: "setVideo", + video: videoId, + }; + + console.log(websocket); + if (websocket === undefined + || websocket.readyState !== WebSocket.OPEN) { + websocket = new WebSocket(WEBSOCKET_URL); + console.log('websocket created'); + } + + websocket.onopen = function () { + console.log('websocket ready'); + websocket.send(JSON.stringify(playerReady)); + websocket.send(JSON.stringify(setVideo)); + console.log(setVideo); + }; + + setTimeout(function () { + websocket.close(); + console.log('websocket closed'); + }, 1000); + + } else { + console.error('o(一︿一+)o not a valid videoId'); + } + } +} \ No newline at end of file diff --git a/stammtv-browserext.iml b/stammtv-browserext.iml new file mode 100644 index 0000000..9a5cfce --- /dev/null +++ b/stammtv-browserext.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file