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/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 761883c..e2f566c 100644 --- a/src/html/popup.html +++ b/src/html/popup.html @@ -12,10 +12,10 @@
- + SMW Central Rom Hacks
@@ -43,21 +43,21 @@
- +
- +
- + Open Options

SMWC Web Extension - SMWC Web Extension v + SMWC Web Extension v

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 36bb300..3372553 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -4,15 +4,14 @@ import { patchRom, saveOptions, updateOptions } from './exports.js' document.addEventListener('DOMContentLoaded', initPopup) -const buttons = document.querySelectorAll('.popup-click') -buttons.forEach((el) => el.addEventListener('click', popupClick)) +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,42 +24,41 @@ 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) } /** - * Handle Popup Clicks - * @function popupClick + * Popup Links Click Callback + * Firefox requires a call to window.close() + * @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.error('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 ebaf739..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') { @@ -126,10 +124,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'], ]