From a697fb65e3c57fc1bbe34a926bc8f5fa3fc0a3b8 Mon Sep 17 00:00:00 2001
From: Shane <6071159+smashedr@users.noreply.github.com>
Date: Mon, 27 Nov 2023 22:49:26 -0800
Subject: [PATCH 1/4] Update Context Menu
---
 manifest.json            | 2 +-
 src/js/service-worker.js | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/manifest.json b/manifest.json
index 40b4103..22a1681 100644
--- a/manifest.json
+++ b/manifest.json
@@ -3,7 +3,7 @@
   "description": "SMWC.world Web Extension and Browser Addon to Easily Patch and Play SMW ROMs.",
   "homepage_url": "https://smwc.world",
   "author": "Shane",
-  "version": "0.0.2",
+  "version": "0.0.3",
   "manifest_version": 3,
   "commands": {
     "_execute_action": {
diff --git a/src/js/service-worker.js b/src/js/service-worker.js
index ebaf739..93f35f7 100644
--- a/src/js/service-worker.js
+++ b/src/js/service-worker.js
@@ -126,10 +126,10 @@ function onChanged(changes, namespace) {
  */
 function createContextMenus() {
     console.log('createContextMenus')
-    const ctx = ['all']
+    const ctx = ['link']
     const contexts = [
-        [['link'], 'rom_patch', 'normal', 'Patch ROM'],
-        [['link'], 'rom_play', 'normal', 'Play ROM'],
+        [ctx, 'rom_patch', 'normal', 'Patch ROM'],
+        [ctx, 'rom_play', 'normal', 'Play ROM'],
         [ctx, 'separator-1', 'separator', 'separator'],
         [ctx, 'options', 'normal', 'Open Options'],
     ]
From 10e6cf34d7ca1022776cb19086510a235b364f2f Mon Sep 17 00:00:00 2001
From: Shane <6071159+smashedr@users.noreply.github.com>
Date: Fri, 1 Dec 2023 23:46:13 -0800
Subject: [PATCH 2/4] Improve popLinks and Options
---
 src/html/popup.html      |  4 ++--
 src/js/popup.js          | 38 +++++++++++++++++++-------------------
 src/js/service-worker.js |  6 ++----
 3 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/src/html/popup.html b/src/html/popup.html
index 761883c..1a0ea82 100644
--- a/src/html/popup.html
+++ b/src/html/popup.html
@@ -50,14 +50,14 @@
         
         
     
-    
     
     
          v
+           data-href="homepage">SMWC Web Extension v
          v
+           data-href="homepage">SMWC Web Extension v
     
 
 
diff --git a/src/js/popup.js b/src/js/popup.js
index 36bb300..29998f1 100644
--- a/src/js/popup.js
+++ b/src/js/popup.js
@@ -5,7 +5,7 @@ import { patchRom, saveOptions, updateOptions } from './exports.js'
 document.addEventListener('DOMContentLoaded', initPopup)
 
 const buttons = document.querySelectorAll('.popup-click')
-buttons.forEach((el) => el.addEventListener('click', popupClick))
+buttons.forEach((el) => el.addEventListener('click', popLinks))
 
 const formInputs = document.querySelectorAll('.pop-options')
 formInputs.forEach((el) => el.addEventListener('change', saveOptions))
@@ -37,30 +37,30 @@ async function initPopup() {
 }
 
 /**
- * Handle Popup Clicks
- * @function popupClick
+ * Handle Popup Link Clicks
+ * @function popLinks
  * @param {MouseEvent} event
  */
-async function popupClick(event) {
-    console.log('popupClick:', event)
+async function popLinks(event) {
+    console.log('popLinks:', event)
     event.preventDefault()
-    let url
     const anchor = event.target.closest('a')
-    if (anchor?.dataset?.href) {
-        if (anchor.dataset.href === 'homepage_url') {
-            url = chrome.runtime.getManifest().homepage_url
-        } else if (anchor.dataset.href.startsWith('http')) {
-            url = anchor.dataset.href
-        } else {
-            url = chrome.runtime.getURL(anchor.dataset.href)
-        }
+    let url
+    if (anchor?.dataset?.href.startsWith('http')) {
+        url = anchor.dataset.href
+    } else if (anchor?.dataset?.href === 'homepage') {
+        url = chrome.runtime.getManifest().homepage_url
+    } else if (anchor?.dataset?.href === 'options') {
+        chrome.runtime.openOptionsPage()
+        return window.close()
+    } else if (anchor?.dataset?.href) {
+        url = chrome.runtime.getURL(anchor.dataset.href)
     }
-    console.log(`url: ${url}`)
-    if (url) {
-        await chrome.tabs.create({ active: true, url })
-    } else {
-        console.warn('No dataset.href for anchor:', anchor)
+    console.log('url:', url)
+    if (!url) {
+        return console.warn('No dataset.href for anchor:', anchor)
     }
+    await chrome.tabs.create({ active: true, url })
     return window.close()
 }
 
diff --git a/src/js/service-worker.js b/src/js/service-worker.js
index 93f35f7..50ec04d 100644
--- a/src/js/service-worker.js
+++ b/src/js/service-worker.js
@@ -30,8 +30,7 @@ async function onInstalled(details) {
         createContextMenus()
     }
     if (details.reason === 'install') {
-        const url = chrome.runtime.getURL('/html/options.html')
-        await chrome.tabs.create({ active: true, url })
+        chrome.runtime.openOptionsPage()
     } else if (options.showUpdate && details.reason === 'update') {
         const manifest = chrome.runtime.getManifest()
         if (manifest.version !== details.previousVersion) {
@@ -64,8 +63,7 @@ async function onClicked(ctx, tab) {
         }
     }
     if (ctx.menuItemId === 'options') {
-        const url = chrome.runtime.getURL('/html/options.html')
-        await chrome.tabs.create({ active: true, url })
+        chrome.runtime.openOptionsPage()
     } else if (ctx.menuItemId === 'rom_patch') {
         patchRom(ctx.linkUrl, 'download', callback)
     } else if (ctx.menuItemId === 'rom_play') {
From 744485c5cd5c5d5d6014556e7465c0f8ab52418b Mon Sep 17 00:00:00 2001
From: Shane <6071159+smashedr@users.noreply.github.com>
Date: Sat, 2 Dec 2023 00:21:33 -0800
Subject: [PATCH 3/4] Update popLinks
---
 src/html/popup.html | 10 +++++-----
 src/js/popup.js     |  9 +++++----
 2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/html/popup.html b/src/html/popup.html
index 1a0ea82..e0f09ee 100644
--- a/src/html/popup.html
+++ b/src/html/popup.html
@@ -12,10 +12,10 @@
 
diff --git a/src/js/popup.js b/src/js/popup.js
index 29998f1..fe29b1a 100644
--- a/src/js/popup.js
+++ b/src/js/popup.js
@@ -4,8 +4,8 @@ import { patchRom, saveOptions, updateOptions } from './exports.js'
 
 document.addEventListener('DOMContentLoaded', initPopup)
 
-const buttons = document.querySelectorAll('.popup-click')
-buttons.forEach((el) => el.addEventListener('click', popLinks))
+const popupLinks = document.querySelectorAll('[data-href]')
+popupLinks.forEach((el) => el.addEventListener('click', popLinks))
 
 const formInputs = document.querySelectorAll('.pop-options')
 formInputs.forEach((el) => el.addEventListener('change', saveOptions))
@@ -37,7 +37,8 @@ async function initPopup() {
 }
 
 /**
- * Handle Popup Link Clicks
+ * Popup Links Click Callback
+ * Firefox requires a call to window.close()
  * @function popLinks
  * @param {MouseEvent} event
  */
@@ -58,7 +59,7 @@ async function popLinks(event) {
     }
     console.log('url:', url)
     if (!url) {
-        return console.warn('No dataset.href for anchor:', anchor)
+        return console.error('No dataset.href for anchor:', anchor)
     }
     await chrome.tabs.create({ active: true, url })
     return window.close()
From 5909eaf81cfb17b9d166c48e941143765c03d51a Mon Sep 17 00:00:00 2001
From: Shane <6071159+smashedr@users.noreply.github.com>
Date: Sat, 2 Dec 2023 00:47:34 -0800
Subject: [PATCH 4/4] Update Options
---
 src/html/options.html | 6 +++---
 src/html/popup.html   | 4 ++--
 src/js/options.js     | 2 +-
 src/js/popup.js       | 9 +++------
 4 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/html/options.html b/src/html/options.html
index 7153b27..d70bfb5 100644
--- a/src/html/options.html
+++ b/src/html/options.html
@@ -33,11 +33,11 @@ SMWC Web Extension
                     
                     
@@ -56,7 +56,7 @@ SMWC Web Extension
 
 
 
-
+
 
 
 
diff --git a/src/html/popup.html b/src/html/popup.html
index e0f09ee..e2f566c 100644
--- a/src/html/popup.html
+++ b/src/html/popup.html
@@ -43,11 +43,11 @@
     
     
     
-        
+        
         
     
     
-        
+        
         
     
     
diff --git a/src/js/options.js b/src/js/options.js
index d03c972..af84168 100644
--- a/src/js/options.js
+++ b/src/js/options.js
@@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', initOptions)
 
 chrome.storage.onChanged.addListener(onChanged)
 
-const formInputs = document.querySelectorAll('.form-control')
+const formInputs = document.querySelectorAll('.options')
 formInputs.forEach((el) => el.addEventListener('change', saveOptions))
 
 // document.getElementById('advanced').addEventListener('submit', saveAdvanced)
diff --git a/src/js/popup.js b/src/js/popup.js
index fe29b1a..3372553 100644
--- a/src/js/popup.js
+++ b/src/js/popup.js
@@ -7,12 +7,11 @@ document.addEventListener('DOMContentLoaded', initPopup)
 const popupLinks = document.querySelectorAll('[data-href]')
 popupLinks.forEach((el) => el.addEventListener('click', popLinks))
 
-const formInputs = document.querySelectorAll('.pop-options')
+const formInputs = document.querySelectorAll('.options')
 formInputs.forEach((el) => el.addEventListener('change', saveOptions))
 
-document.getElementsByName('searchType').forEach((el) => {
-    el.addEventListener('change', updateSearchType)
-})
+const searchTypes = document.getElementsByName('searchType')
+searchTypes.forEach((el) => el.addEventListener('change', updateSearchType))
 
 document.getElementById('patch-form').addEventListener('submit', patchForm)
 
@@ -25,13 +24,11 @@ async function initPopup() {
     document.getElementById('patch-input').focus()
     document.getElementById('version').textContent =
         chrome.runtime.getManifest().version
-
     const { options, popup } = await chrome.storage.sync.get([
         'options',
         'popup',
     ])
     console.log('options, popup:', options, popup)
-
     document.getElementById(popup.searchType).checked = true
     updateOptions(options)
 }