Skip to content

Commit e05cde2

Browse files
authored
Minor Updates and Improvements (#2)
* Update Context Menu * Improve popLinks and Options * Update popLinks * Update Options
1 parent bd8c53f commit e05cde2

File tree

6 files changed

+42
-46
lines changed

6 files changed

+42
-46
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "SMWC.world Web Extension and Browser Addon to Easily Patch and Play SMW ROMs.",
44
"homepage_url": "https://smwc.world",
55
"author": "Shane",
6-
"version": "0.0.2",
6+
"version": "0.0.3",
77
"manifest_version": 3,
88
"commands": {
99
"_execute_action": {

src/html/options.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ <h1 class="align-middle">SMWC Web Extension</h1>
3333
<hr>
3434
<form id="options">
3535
<div class="form-check form-switch">
36-
<input class="form-check-input form-control" type="checkbox" role="switch" id="contextMenu">
36+
<input class="form-check-input options" type="checkbox" role="switch" id="contextMenu">
3737
<label class="form-check-label" for="contextMenu" aria-describedby="contextMenuHelp">Enable Right Click Menu</label>
3838
</div>
3939
<div class="form-check form-switch mb-3">
40-
<input class="form-check-input form-control" type="checkbox" role="switch" id="showUpdate">
40+
<input class="form-check-input options" type="checkbox" role="switch" id="showUpdate">
4141
<label class="form-check-label" for="showUpdate" aria-describedby="showUpdateHelp">Show Release Notes on Update</label>
4242
</div>
4343
</form>
@@ -56,7 +56,7 @@ <h1 class="align-middle">SMWC Web Extension</h1>
5656
<!-- <form id="advanced" class="">-->
5757
<!-- <label for="url" class="form-label">SMWC.world URL</label>-->
5858
<!-- <a id="reset-default" class="float-end align-bottom small" role="button">Reset to Default</a>-->
59-
<!-- <input type="text" id="url" class="form-control" aria-describedby="urlHelp">-->
59+
<!-- <input type="text" id="url" class="options" aria-describedby="urlHelp">-->
6060
<!-- <div id="urlInvalid" class="invalid-feedback">Invalid Hostname.</div>-->
6161
<!-- <div id="urlHelp" class="form-text mb-3">-->
6262
<!-- URL to SMWC.world Instance. Only used for testing!-->

src/html/popup.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<div class="container-fluid p-3">
1313
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
1414
<div class="btn-group btn-group-sm" role="group" aria-label="SMWC.world">
15-
<a role="button" class="btn btn-outline-info popup-click" data-href="https://smwc.world/patcher/">Patcher</a>
16-
<a role="button" class="btn btn-outline-info popup-click" data-href="https://smwc.world/play/">Player</a>
15+
<a role="button" class="btn btn-outline-info" data-href="https://smwc.world/patcher/">Patcher</a>
16+
<a role="button" class="btn btn-outline-info" data-href="https://smwc.world/play/">Player</a>
1717
</div>
18-
<a class="btn btn-success btn-sm popup-click w-100" role="button" data-href="https://www.smwcentral.net/?p=section&s=smwhacks">
18+
<a class="btn btn-success btn-sm w-100" role="button" data-href="https://www.smwcentral.net/?p=section&s=smwhacks">
1919
SMW Central Rom Hacks
2020
</a>
2121
<form id="patch-form">
@@ -43,21 +43,21 @@
4343
<div id="popup-alert" class="alert alert-warning mt-2 visually-hidden" role="alert"></div>
4444
<hr class="my-2">
4545
<div class="form-check form-switch">
46-
<input class="form-check-input form-control pop-options" type="checkbox" role="switch" id="contextMenu">
46+
<input class="form-check-input options" type="checkbox" role="switch" id="contextMenu">
4747
<label class="form-check-label" for="contextMenu">Enable Right Click Menu</label>
4848
</div>
4949
<div class="form-check form-switch">
50-
<input class="form-check-input form-control pop-options" type="checkbox" role="switch" id="showUpdate">
50+
<input class="form-check-input options" type="checkbox" role="switch" id="showUpdate">
5151
<label class="form-check-label" for="showUpdate" aria-describedby="showUpdateHelp">Show Release Notes on Update</label>
5252
</div>
53-
<a class="btn btn-outline-primary btn-sm popup-click w-100 mt-3" role="button" data-href="html/options.html">
53+
<a class="btn btn-outline-primary btn-sm w-100 mt-3" role="button" data-href="options">
5454
Open Options
5555
</a>
5656
<hr>
5757
<p class="text-center small mb-0">
5858
<img src="../images/logo16.png" alt="SMWC Web Extension" class="me-1">
59-
<a class="link-offset-2 link-underline link-underline-opacity-0 link-underline-opacity-75-hover popup-click" type="button" rel="noopener"
60-
data-href="homepage_url">SMWC Web Extension</a> v<span id="version"></span>
59+
<a class="link-offset-2 link-underline link-underline-opacity-0 link-underline-opacity-75-hover" type="button" rel="noopener"
60+
data-href="homepage">SMWC Web Extension</a> v<span id="version"></span>
6161
</p>
6262
</div>
6363

src/js/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', initOptions)
66

77
chrome.storage.onChanged.addListener(onChanged)
88

9-
const formInputs = document.querySelectorAll('.form-control')
9+
const formInputs = document.querySelectorAll('.options')
1010
formInputs.forEach((el) => el.addEventListener('change', saveOptions))
1111

1212
// document.getElementById('advanced').addEventListener('submit', saveAdvanced)

src/js/popup.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import { patchRom, saveOptions, updateOptions } from './exports.js'
44

55
document.addEventListener('DOMContentLoaded', initPopup)
66

7-
const buttons = document.querySelectorAll('.popup-click')
8-
buttons.forEach((el) => el.addEventListener('click', popupClick))
7+
const popupLinks = document.querySelectorAll('[data-href]')
8+
popupLinks.forEach((el) => el.addEventListener('click', popLinks))
99

10-
const formInputs = document.querySelectorAll('.pop-options')
10+
const formInputs = document.querySelectorAll('.options')
1111
formInputs.forEach((el) => el.addEventListener('change', saveOptions))
1212

13-
document.getElementsByName('searchType').forEach((el) => {
14-
el.addEventListener('change', updateSearchType)
15-
})
13+
const searchTypes = document.getElementsByName('searchType')
14+
searchTypes.forEach((el) => el.addEventListener('change', updateSearchType))
1615

1716
document.getElementById('patch-form').addEventListener('submit', patchForm)
1817

@@ -25,42 +24,41 @@ async function initPopup() {
2524
document.getElementById('patch-input').focus()
2625
document.getElementById('version').textContent =
2726
chrome.runtime.getManifest().version
28-
2927
const { options, popup } = await chrome.storage.sync.get([
3028
'options',
3129
'popup',
3230
])
3331
console.log('options, popup:', options, popup)
34-
3532
document.getElementById(popup.searchType).checked = true
3633
updateOptions(options)
3734
}
3835

3936
/**
40-
* Handle Popup Clicks
41-
* @function popupClick
37+
* Popup Links Click Callback
38+
* Firefox requires a call to window.close()
39+
* @function popLinks
4240
* @param {MouseEvent} event
4341
*/
44-
async function popupClick(event) {
45-
console.log('popupClick:', event)
42+
async function popLinks(event) {
43+
console.log('popLinks:', event)
4644
event.preventDefault()
47-
let url
4845
const anchor = event.target.closest('a')
49-
if (anchor?.dataset?.href) {
50-
if (anchor.dataset.href === 'homepage_url') {
51-
url = chrome.runtime.getManifest().homepage_url
52-
} else if (anchor.dataset.href.startsWith('http')) {
53-
url = anchor.dataset.href
54-
} else {
55-
url = chrome.runtime.getURL(anchor.dataset.href)
56-
}
46+
let url
47+
if (anchor?.dataset?.href.startsWith('http')) {
48+
url = anchor.dataset.href
49+
} else if (anchor?.dataset?.href === 'homepage') {
50+
url = chrome.runtime.getManifest().homepage_url
51+
} else if (anchor?.dataset?.href === 'options') {
52+
chrome.runtime.openOptionsPage()
53+
return window.close()
54+
} else if (anchor?.dataset?.href) {
55+
url = chrome.runtime.getURL(anchor.dataset.href)
5756
}
58-
console.log(`url: ${url}`)
59-
if (url) {
60-
await chrome.tabs.create({ active: true, url })
61-
} else {
62-
console.warn('No dataset.href for anchor:', anchor)
57+
console.log('url:', url)
58+
if (!url) {
59+
return console.error('No dataset.href for anchor:', anchor)
6360
}
61+
await chrome.tabs.create({ active: true, url })
6462
return window.close()
6563
}
6664

src/js/service-worker.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ async function onInstalled(details) {
3030
createContextMenus()
3131
}
3232
if (details.reason === 'install') {
33-
const url = chrome.runtime.getURL('/html/options.html')
34-
await chrome.tabs.create({ active: true, url })
33+
chrome.runtime.openOptionsPage()
3534
} else if (options.showUpdate && details.reason === 'update') {
3635
const manifest = chrome.runtime.getManifest()
3736
if (manifest.version !== details.previousVersion) {
@@ -64,8 +63,7 @@ async function onClicked(ctx, tab) {
6463
}
6564
}
6665
if (ctx.menuItemId === 'options') {
67-
const url = chrome.runtime.getURL('/html/options.html')
68-
await chrome.tabs.create({ active: true, url })
66+
chrome.runtime.openOptionsPage()
6967
} else if (ctx.menuItemId === 'rom_patch') {
7068
patchRom(ctx.linkUrl, 'download', callback)
7169
} else if (ctx.menuItemId === 'rom_play') {
@@ -126,10 +124,10 @@ function onChanged(changes, namespace) {
126124
*/
127125
function createContextMenus() {
128126
console.log('createContextMenus')
129-
const ctx = ['all']
127+
const ctx = ['link']
130128
const contexts = [
131-
[['link'], 'rom_patch', 'normal', 'Patch ROM'],
132-
[['link'], 'rom_play', 'normal', 'Play ROM'],
129+
[ctx, 'rom_patch', 'normal', 'Patch ROM'],
130+
[ctx, 'rom_play', 'normal', 'Play ROM'],
133131
[ctx, 'separator-1', 'separator', 'separator'],
134132
[ctx, 'options', 'normal', 'Open Options'],
135133
]

0 commit comments

Comments
 (0)