Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/html/links.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
</head>
<body>

<div id="loading-spinner" class="text-center position-absolute end-50 mt-4">
<i class="fa-solid fa-sync fa-spin fa-3x"></i>
<h3 class="fa-fade mt-2">Processing</h3>
</div>

<div id="floating-links" class="position-fixed top-0 end-0 mt-1 me-2 user-select-none">
<div class="row g-1 links d-none">
<div class="col">
Expand All @@ -37,7 +42,6 @@
</div> <!-- floating-links -->

<div class="container-fluid p-3">
<h2 id="loading-message" class="user-select-none d-none">Loading...</h2>
<div class="links d-none">
<div class="user-select-none">
<h2 id="links">Links <span class="badge bg-success-subtle"><span id="links-count">0</span>/<span id="links-total"></span></span></h2>
Expand Down
30 changes: 26 additions & 4 deletions src/js/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,36 @@ export async function injectTab({
return
}

// Inject extract.js which listens for messages
// // Inject extract.js which listens for messages
// for (const tab of tabIds) {
// console.debug(`injecting tab.id: ${tab}`)
// await chrome.scripting.executeScript({
// target: { tabId: tab, allFrames: true },
// files: ['/js/extract.js'],
// })
// }

// TODO: The only way to support frames without extra permissions is to either:
// Extract the frame data at injection time, or
// Extract the links at injection time (requires refactoring)...
const tabs = []
for (const tab of tabIds) {
console.debug(`injecting tab.id: ${tab}`)
await chrome.scripting.executeScript({
target: { tabId: tab },
const results = await chrome.scripting.executeScript({
target: { tabId: tab, allFrames: true },
files: ['/js/extract.js'],
})
console.debug('results:', results)
const frameIds = results.map((item) => item.frameId)
console.debug('frameIds:', frameIds)
frameIds.shift()
if (frameIds.length) {
tabs.push(`${tab}-${frameIds.join('-')}`)
} else {
tabs.push(tab)
}
}
console.debug('tabs:', tabs)

// Create URL to links.html if open
if (!open) {
Expand All @@ -70,7 +92,7 @@ export async function injectTab({
}
const url = new URL(chrome.runtime.getURL('/html/links.html'))
// Set URL searchParams
url.searchParams.set('tabs', tabIds.join(','))
url.searchParams.set('tabs', tabs.join(','))
if (filter) {
url.searchParams.set('filter', filter)
}
Expand Down
57 changes: 48 additions & 9 deletions src/js/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,32 @@ async function initLinks() {
try {
const tabIds = urlParams.get('tabs')
const tabs = tabIds?.split(',')
const selection = urlParams.has('selection')
const action = urlParams.has('selection') ? 'selection' : 'all'

// TODO: See the TODO in export.js for injectTab()
// This is a temporary fix being tested...
const allLinks = []
if (tabs?.length) {
console.debug('tabs:', tabs)
for (const tabId of tabs) {
const action = selection ? 'selection' : 'all'
for (const tab of tabs) {
const frames = tab.split('-')
const tabId = frames.shift()
console.debug('tabId:', tabId)
const links = await chrome.tabs.sendMessage(
parseInt(tabId),
action
action,
{ frameId: 0 }
)
allLinks.push(...links)
for (const frame of frames) {
console.debug('frame:', frame)
const links = await chrome.tabs.sendMessage(
parseInt(tabId),
action,
{ frameId: parseInt(frame) }
)
allLinks.push(...links)
}
}
} else {
const { links } = await chrome.storage.local.get(['links'])
Expand All @@ -181,8 +195,17 @@ async function initLinks() {
await processLinks(allLinks)
} catch (e) {
console.warn('error:', e)
alert('Error Processing Results. See Console for More Details...')
window.close()
// document.getElementById('loading-spinner')?.classList?.add('d-none')
document.getElementById('loading-spinner')?.remove()

// TODO: Consider showing a custom alert here since alert is blocking...
setTimeout(() => {
alert('Error Processing Results. See Console for More Details...')
window.close()
}, 0)

// alert('Error Processing Results. See Console for More Details...')
// window.close()
}

const collapse = localStorage.getItem('findCollapse')
Expand Down Expand Up @@ -282,8 +305,22 @@ async function processLinks(links) {

// If no items, alert and return
if (!links.length) {
alert('No Results')
return window.close()
//document.getElementById('loading-spinner')?.classList?.add('d-none')
document.getElementById('loading-spinner')?.remove()

// TODO: Consider showing a custom alert here since alert is blocking...
setTimeout(() => {
alert('No Results')
window.close()
}, 0)

// requestAnimationFrame(() => {
// alert('No Results')
// window.close()
// })

// alert('No Results')
// return window.close()
}

// Update links if onlyDomains is not set
Expand Down Expand Up @@ -319,7 +356,9 @@ async function processLinks(links) {
}

// Hide Loading message
document.getElementById('loading-message').classList.add('d-none')
// document.getElementById('loading-message').classList.add('d-none')
// document.getElementById('loading-spinner')?.classList?.add('d-none')
document.getElementById('loading-spinner')?.remove()

// Modifications for Android
const platform = await chrome.runtime.getPlatformInfo()
Expand Down