fixed first-run contextmenu not shown bug

master
and94x 2 years ago
parent 09e788a37e
commit 470ae7e8d0

@ -1,51 +1,51 @@
chrome.contextMenus.onClicked.addListener(addToStammTV); chrome.contextMenus.onClicked.addListener(addToStammTV);
let WEBSOCKET_URL = ""; let WEBSOCKET_URL;
let websocket; let websocket;
const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST"; const CONTEXT_MENU_ID = "STAMMTV_ADD_URL_TO_PLAYLIST";
chrome.storage.local.get('firstRun', function (result) { chrome.runtime.onInstalled.addListener(function (details) {
if (result.firstRun === false) { if (details.reason === "install") {
chrome.storage.local.set({'firstRun': false}, function (result) {
chrome.runtime.openOptionsPage(); chrome.runtime.openOptionsPage();
}); } else if (details.reason === "update") {
} else {
chrome.storage.local.get(['baseURL', 'wssURL'], function (items) { chrome.storage.local.get(['baseURL', 'wssURL'], function (items) {
if (items.wssURL !== undefined && items.wssURL.startsWith('wss://')) { if (items.wssURL !== undefined && items.wssURL.startsWith('wss://')) {
WEBSOCKET_URL = items.wssURL;
init();
} else { } else {
chrome.runtime.openOptionsPage(); chrome.runtime.openOptionsPage();
} }
}); });
} }
}); })
function init() { 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"],
id: CONTEXT_MENU_ID id: CONTEXT_MENU_ID
}); });
}); });
}
function parseYoutubeURL(url) { function parseYoutubeURL(url) {
const YOUTUBE_URL_REGEX = /^(?:https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)){1}([^#&?]*)(?:[?&]t=\d+)?.*/; const YOUTUBE_URL_REGEX = /^https?:\/\/(?:www\.)?youtu(?:\.be\/|be\.com\/watch\?v=|be\.com\/shorts\/)([^#&?]*)(?:[?&]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) {
if (websocket === undefined if (websocket === undefined
|| websocket.readyState !== WebSocket.OPEN) { || 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); websocket = new WebSocket(WEBSOCKET_URL);
console.log('websocket created'); console.log('websocket created');
} else { } else {

@ -46,6 +46,5 @@
<script src="/i18n.js"></script> <script src="/i18n.js"></script>
<script src="settings.js"></script> <script src="settings.js"></script>
<script src="/script.js"></script>
</body> </body>
</html> </html>

@ -28,7 +28,6 @@ function validateAndSave() {
if (valid) { if (valid) {
save(); save();
init();
} else { } else {
console.log('Failed to save settings - form validation was not successful.') console.log('Failed to save settings - form validation was not successful.')
saveButton.classList.replace('btn-primary', 'btn-danger'); saveButton.classList.replace('btn-primary', 'btn-danger');

Loading…
Cancel
Save