diff --git a/js/background.js b/js/background.js index 81038fe..df7b684 100644 --- a/js/background.js +++ b/js/background.js @@ -7,15 +7,18 @@ chrome.runtime.onInstalled.addListener(function (details) { type: 'basic', iconUrl: chrome.runtime.getURL('img/icon_x128.png'), title: 'Share to Mastodon ' + chrome.runtime.getManifest().version + ' installed!', - buttons: [ + message: "Click here to see what's new in this version." + } + // Firefox doesn't support buttons in notifications + if (!window.navigator.userAgent.includes('Firefox')) { + notification.buttons = [ { title: 'Open Settings' }, { title: 'Join Discord' } - ], - message: "Click here to see what's new in this version." + ] } // Send notification chrome.notifications.create(notification, () => { @@ -24,14 +27,16 @@ chrome.runtime.onInstalled.addListener(function (details) { chrome.tabs.create({ url: 'https://corbin.io/introducing-share-to-mastodon/' }) }) // Handle notification button clicks - chrome.notifications.onButtonClicked.addListener(function (_, buttonIndex) { - if (buttonIndex === 0) { - chrome.runtime.openOptionsPage() - } else if (buttonIndex === 1) { - // Open Discord - chrome.tabs.create({ url: 'https://discord.com/invite/59wfy5cNHw' }) - } - }) + if (!window.navigator.userAgent.includes('Firefox')) { + chrome.notifications.onButtonClicked.addListener(function (_, buttonIndex) { + if (buttonIndex === 0) { + chrome.runtime.openOptionsPage() + } else if (buttonIndex === 1) { + // Open Discord + chrome.tabs.create({ url: 'https://discord.com/invite/59wfy5cNHw' }) + } + }) + } }) } // Initialize context menu @@ -43,7 +48,7 @@ chrome.runtime.onInstalled.addListener(function (details) { // Function for migrating data from version 1.0 async function migrateOldData() { // Chrome/Edge version saved a single server in a "userServer" string in chrome.storage.sync - // Firefox version saved it in "userServer" string but in chrome.local.sync + // Firefox version saved it in the same "userServer" string, but in chrome.local.sync if (window.navigator.userAgent.includes('Firefox')) { var data = await chrome.storage.local.get() } else { @@ -134,7 +139,7 @@ function createPopup(serverUrl, shareLink, shareText, tab) { var popupHeight = 500 var y = Math.round((tab.height / 2) - (popupHeight / 2)) var x = Math.round((tab.width / 2) - (popupWidth / 2)) - console.log(popupWidth, popupHeight, y, x) + console.log('Popup dimensions:', popupWidth, popupHeight, y, x) chrome.windows.create({ url: popupPage, width: popupWidth, diff --git a/js/settings.js b/js/settings.js index 9a9a304..8793b83 100644 --- a/js/settings.js +++ b/js/settings.js @@ -51,7 +51,13 @@ document.querySelector('#server-remove-btn').addEventListener('click', function // Open keyboard shortcut document.querySelector('#mastodon-keyboard-shortcut').addEventListener('click', function () { - chrome.tabs.create({ url: 'chrome://extensions/shortcuts#:~:text=Share%20to%20Mastodon' }) + // Firefox cannot automatically navigate to the keyboard shortcut configuration page + if (window.navigator.userAgent.includes('Firefox')) { + const bsCollapse = new bootstrap.Collapse('#firefoxShortcutCollapse').show() + } else { + chrome.tabs.create({ url: 'chrome://extensions/shortcuts#:~:text=Share%20to%20Mastodon' }) + } + }) loadSettings() \ No newline at end of file diff --git a/settings.html b/settings.html index 1c09d66..dd95807 100644 --- a/settings.html +++ b/settings.html @@ -36,6 +36,11 @@
If you find Share to Mastodon useful, please donate to support continued development. It would mean a lot!