added build script for ff, fixed a bug and did some more shit

master
and94x 2 years ago
parent 2a3b3fd495
commit c7bb0b8956

@ -1,5 +1,5 @@
<component name="ArtifactManager"> <component name="ArtifactManager">
<artifact name="chrome"> <artifact build-on-make="true" name="chrome">
<output-path>$PROJECT_DIR$/out/artifacts/chrome</output-path> <output-path>$PROJECT_DIR$/out/artifacts/chrome</output-path>
<root id="root"> <root id="root">
<element id="dir-copy" path="$PROJECT_DIR$/base" /> <element id="dir-copy" path="$PROJECT_DIR$/base" />

@ -1,9 +0,0 @@
<component name="ArtifactManager">
<artifact name="firefox">
<output-path>$PROJECT_DIR$/out/artifacts/firefox</output-path>
<root id="root">
<element id="dir-copy" path="$PROJECT_DIR$/base" />
<element id="dir-copy" path="$PROJECT_DIR$/firefox" />
</root>
</artifact>
</component>

@ -1,5 +1,9 @@
## Build ## Build
```shell
cd base; find base -type f -exec zip out/artifacts/firefox/extension.crx {} +
find firefox -type f -exec zip out/artifacts/firefox/extension.crx {} +
zip -r out/artifacts/firefox/extension.crx base/* firefox/*
```
## Prerequisites ## Prerequisites
- Chromium based Browser (Chrome, Edge, ..) - Chromium based Browser (Chrome, Edge, ..)

@ -4,8 +4,9 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Popup</title> <title>Popup</title>
</head> </head>
<body style="min-width: 10rem; min-height: 5rem; display: flex; justify-content: center; align-items: center;"> <body style="min-width: 10rem; min-height: 5rem; display: grid; justify-content: center; align-items: center;">
<a href="" id="open-stammtv" target="_blank" style="font-weight: bold; color: #ff0000; border: 1px solid black">→ Take me to StammTV!</a> <a href="" id="open-stammtv" target="_blank" style="font-weight: bold; color: #ff0000; border: 2px solid black;">→ Take me to StammTV!</a>
<a href="/options/options.html" id="open-settings" target="_blank" style="font-weight: bold;">⚙ Settings</a>
<script src="popup.js"></script> <script src="popup.js"></script>
</body> </body>
</html> </html>

@ -1,45 +1,64 @@
let WEBSOCKET_URL = "";
let websocket;
const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST";
chrome.storage.local.get('firstRun', function (result) { chrome.storage.local.get('firstRun', function (result) {
console.log(result);
if (result.firstRun === false) { if (result.firstRun === false) {
firstRun(); chrome.storage.local.set({'firstRun': false}, function (result) {
openSettings();
});
} else {
chrome.storage.local.get(['baseURL', 'wssURL'], function (items) {
if (items.wssURL !== undefined && items.wssURL.startsWith('wss://')) {
WEBSOCKET_URL = items.wssURL;
handleValidityCheckResult(true)
}
});
} }
}); });
function firstRun(){ function openSettings() {
chrome.storage.local.set({'firstRun': false}, function (result) { chrome.tabs.create({
chrome.tabs.create active: true,
}); url: 'options/options.html'
}, null);
} }
const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST"; function handleValidityCheckResult(validSettings) {
const YOUTUBE_URL_REGEX = /^(?:https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)){1}([^#&?]*)(?:[?&]t=\d+)?.*/; if (validSettings) {
addContextMenuItem();
let WEBSOCKET_URL = ""; } else {
let websocket; openSettings();
}
}
chrome.storage.local.get('wssURL', function (result) {
WEBSOCKET_URL = result.wssURL;
});
chrome.contextMenus.create({ function addContextMenuItem() {
title: "Zu StammTV Playlist hinzufügen...", chrome.contextMenus.removeAll(function() {
contexts: ["link"], chrome.contextMenus.create({
id: CONTEXT_MENU_ID title: "Zu StammTV Playlist hinzufügen...",
}); contexts: ["link"],
id: CONTEXT_MENU_ID
});
});
chrome.contextMenus.onClicked.addListener(addToStammTV); chrome.contextMenus.onClicked.addListener(addToStammTV);
}
function parseYoutubeURL(url) { function parseYoutubeURL(url) {
const YOUTUBE_URL_REGEX = /^(?:https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)){1}([^#&?]*)(?:[?&]t=\d+)?.*/;
let match = url.match(YOUTUBE_URL_REGEX); let match = url.match(YOUTUBE_URL_REGEX);
return (match && match[1].length === 11) ? match[1] : false; return (match && match[1].length === 11) ? match[1] : false;
} }
function addToStammTV(info, tab) { function addToStammTV(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) let videoId = parseYoutubeURL(info.linkUrl)
if (videoId) { if (videoId) {
const playerReady = {"type":"playerReady"}; const playerReady = {"type": "playerReady"};
const setVideo = { const setVideo = {
type: "setVideo", type: "setVideo",
@ -69,4 +88,4 @@ function addToStammTV(info, tab) {
console.error('o(一︿一+)o not a valid videoId'); console.error('o(一︿一+)o not a valid videoId');
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

@ -0,0 +1,15 @@
#!/usr/bin/bash
PWD=$(pwd)
BASE_DIR=${PWD}/base
MANIFEST_DIR=${PWD}/firefox
OUT="../out/artifacts/firefox/extension.zip"
echo $BASE_DIR
echo $MANIFEST_DIR
echo $OUT
rm -f ${OUT}
cd "$BASE_DIR" || return
zip -r ${OUT} *
cd "${MANIFEST_DIR}" || return
zip -r ${OUT} manifest.json

@ -13,5 +13,10 @@
], ],
"action": { "action": {
"default_popup": "popup/popup.html" "default_popup": "popup/popup.html"
},
"icons": {
"16": "stammtv-bitty.png",
"48": "stammtv-small.png",
"128": "stammtv-large.png"
} }
} }

@ -4,7 +4,9 @@
"version": "1.0", "version": "1.0",
"manifest_version": 2, "manifest_version": 2,
"background": { "background": {
"scripts": ["script.js"] "scripts": [
"script.js"
]
}, },
"options_page": "options/options.html", "options_page": "options/options.html",
"permissions": [ "permissions": [
@ -13,5 +15,10 @@
], ],
"action": { "action": {
"default_popup": "popup/popup.html" "default_popup": "popup/popup.html"
},
"icons": {
"16": "icon-bitty.png",
"48": "icon-small.png",
"128": "icon-large.png"
} }
} }

@ -13,5 +13,10 @@
], ],
"action": { "action": {
"default_popup": "popup/popup.html" "default_popup": "popup/popup.html"
},
"icons": {
"16": "stammtv-bitty.png",
"48": "stammtv-small.png",
"128": "stammtv-large.png"
} }
} }

@ -4,8 +4,9 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Popup</title> <title>Popup</title>
</head> </head>
<body style="min-width: 10rem; min-height: 5rem; display: flex; justify-content: center; align-items: center;"> <body style="min-width: 10rem; min-height: 5rem; display: grid; justify-content: center; align-items: center;">
<a href="" id="open-stammtv" target="_blank" style="font-weight: bold; color: #ff0000; border: 1px solid black">→ Take me to StammTV!</a> <a href="" id="open-stammtv" target="_blank" style="font-weight: bold; color: #ff0000; border: 2px solid black;">→ Take me to StammTV!</a>
<a href="/options/options.html" id="open-settings" target="_blank" style="font-weight: bold;">⚙ Settings</a>
<script src="popup.js"></script> <script src="popup.js"></script>
</body> </body>
</html> </html>

@ -1,31 +1,64 @@
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_URL = "";
let websocket; let websocket;
const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST";
chrome.storage.local.get('wssURL', function (result) { chrome.storage.local.get('firstRun', function (result) {
WEBSOCKET_URL = result.wssURL; console.log(result);
if (result.firstRun === false) {
chrome.storage.local.set({'firstRun': false}, function (result) {
openSettings();
});
} else {
chrome.storage.local.get(['baseURL', 'wssURL'], function (items) {
if (items.wssURL !== undefined && items.wssURL.startsWith('wss://')) {
WEBSOCKET_URL = items.wssURL;
handleValidityCheckResult(true)
}
});
}
}); });
chrome.contextMenus.create({ function openSettings() {
title: "Zu StammTV Playlist hinzufügen...", chrome.tabs.create({
contexts: ["link"], active: true,
id: CONTEXT_MENU_ID url: 'options/options.html'
}); }, null);
}
function handleValidityCheckResult(validSettings) {
if (validSettings) {
addContextMenuItem();
} else {
openSettings();
}
}
chrome.contextMenus.onClicked.addListener(addToStammTV); function addContextMenuItem() {
chrome.contextMenus.removeAll(function() {
chrome.contextMenus.create({
title: "Zu StammTV Playlist hinzufügen...",
contexts: ["link"],
id: CONTEXT_MENU_ID
});
});
chrome.contextMenus.onClicked.addListener(addToStammTV);
}
function parseYoutubeURL(url) { function parseYoutubeURL(url) {
const YOUTUBE_URL_REGEX = /^(?:https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)){1}([^#&?]*)(?:[?&]t=\d+)?.*/;
let match = url.match(YOUTUBE_URL_REGEX); let match = url.match(YOUTUBE_URL_REGEX);
return (match && match[1].length === 11) ? match[1] : false; return (match && match[1].length === 11) ? match[1] : false;
} }
function addToStammTV(info, tab) { function addToStammTV(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) let videoId = parseYoutubeURL(info.linkUrl)
if (videoId) { if (videoId) {
const playerReady = {"type":"playerReady"}; const playerReady = {"type": "playerReady"};
const setVideo = { const setVideo = {
type: "setVideo", type: "setVideo",
@ -55,4 +88,4 @@ function addToStammTV(info, tab) {
console.error('o(一︿一+)o not a valid videoId'); console.error('o(一︿一+)o not a valid videoId');
} }
} }
} }

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="GENERAL_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="GENERAL_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -1,17 +0,0 @@
{
"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"
}
}

@ -1,21 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Options for StammTV Chrome Extension</title>
</head>
<body>
<div style="display: grid;">
<label>
StammTV Base URL: <input type="url" id="stammtv-base-url" style="min-width: 20rem;">
</label>
<label>
StammTV WSS URL: <input type="url" id="stammtv-wss-url" style="min-width: 20rem;">
</label>
</div>
<div id="status" style="color: #259025"></div>
<button id="save">Save</button>
<script src="options.js"></script>
</body>
</html>

@ -1,32 +0,0 @@
// 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);

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Popup</title>
</head>
<body style="min-width: 10rem; min-height: 5rem; display: flex; justify-content: center; align-items: center;">
<a href="" id="open-stammtv" target="_blank" style="font-weight: bold; color: #ff0000; border: 1px solid black">→ Take me to StammTV!</a>
<script src="popup.js"></script>
</body>
</html>

@ -1,7 +0,0 @@
function restore_options() {
chrome.storage.local.get('baseURL', function (result) {
document.getElementById('open-stammtv').href = result.baseURL;
});
}
document.addEventListener('DOMContentLoaded', restore_options);

@ -1,58 +0,0 @@
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');
}
}
}
Loading…
Cancel
Save