Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Popup Links #8

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@

<div class="container-fluid p-3">
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
<div class="btn-group btn-group-sm" role="group" aria-label="SMWC.world">
<a role="button" class="btn btn-outline-info" href="https://smwc.world/patcher/">
<div class="btn-group " role="group" aria-label="SMWC.world">
<a role="button" class="btn btn-outline-success" href="https://smwc.world/patcher/">
<i class="fa-solid fa-hard-drive me-1"></i> Patcher</a>
<a role="button" class="btn btn-outline-info" href="https://smwc.world/play/">
<a role="button" class="btn btn-outline-success" href="https://smwc.world/play/">
<i class="fa-solid fa-gamepad me-1"></i> Player</a>
</div>
<a class="btn btn-success btn-sm w-100" role="button" href="https://www.smwcentral.net/?p=section&s=smwhacks">
SMW Central Rom Hacks</a>
<form id="patch-form">
<label for="patch-input" class="visually-hidden">Patch URL</label>
<div class="input-group">
<input id="patch-input" type="text" class="form-control form-control-sm" placeholder="Quick Patch/Play URL" aria-label="Patch URL" aria-describedby="patch-rom" required>
<input id="patch-input" type="text" class="form-control form-control-sm" placeholder="Quick Patch/Play URL"
aria-label="Patch URL" aria-describedby="patch-rom" required>
<button class="btn btn-outline-secondary" type="submit" id="patch-rom">Go</button>
</div>
</form>
Expand Down Expand Up @@ -65,7 +66,7 @@
</label>
</div>
</form>
<a class="btn btn-outline-primary btn-sm w-100" role="button" href="../html/options.html">
<a class="btn btn-outline-info btn-sm w-100" role="button" href="../html/options.html">
<i class="fa-solid fa-sliders me-1"></i> Open Options</a>
<hr>
<div class="justify-content-center align-items-center d-flex text-center small">
Expand Down
15 changes: 8 additions & 7 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ document

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

const patchRomBtn = document.getElementById('patch-rom')

/**
* Initialize Popup
* @function initPopup
Expand Down Expand Up @@ -51,17 +53,11 @@ async function popupLinks(event) {
event.preventDefault()
const anchor = event.target.closest('a')
console.log(`anchor.href: ${anchor.href}`)
let url
if (anchor.href.endsWith('html/options.html')) {
chrome.runtime.openOptionsPage()
return window.close()
} else if (anchor.href.startsWith('http')) {
url = anchor.href
} else {
url = chrome.runtime.getURL(anchor.href)
await chrome.tabs.create({ active: true, url: anchor.href })
}
console.log('url:', url)
await chrome.tabs.create({ active: true, url })
return window.close()
}

Expand Down Expand Up @@ -90,12 +86,17 @@ async function updateSearchType(event) {
async function patchForm(event) {
console.log('linksForm:', event)
event.preventDefault()
if (patchRomBtn.classList.contains('disabled')) {
return console.log('Duplicate Click Detected!')
}
patchRomBtn.classList.add('disabled')
const value = document.getElementById('patch-input').value
console.log('value:', value)
const key = document.querySelector('input[name="searchType"]:checked').value
console.log('key:', key)
const callback = (result, key) => {
console.log('popup callback:', result)
patchRomBtn.classList.remove('disabled')
if (result[key]) {
chrome.tabs.create({ active: true, url: result[key] }).then()
window.close()
Expand Down