Commit ad20bb6f authored by Travis Fischer's avatar Travis Fischer

feat: make nopecha extension ID dynamic

parent cbfaed93
...@@ -269,26 +269,54 @@ export async function getBrowser( ...@@ -269,26 +269,54 @@ export async function getBrowser(
const page = (await browser.pages())[0] || (await browser.newPage()) const page = (await browser.pages())[0] || (await browser.newPage())
await page.goto(`https://nopecha.com/setup#${nopechaKey}`) await page.goto(`https://nopecha.com/setup#${nopechaKey}`)
await delay(1000) await delay(1000)
const page3 = await browser.newPage()
await page.close() try {
const page3 = await browser.newPage()
const extensionId = 'npgnhlnhpphdlkfdnggbdpbhoopefaai' await page.close()
const extensionUrl = `chrome-extension://${extensionId}/popup.html`
await page3.goto(extensionUrl, { waitUntil: 'networkidle2' }) // find the nopecha extension ID
await delay(500) const targets = browser.targets()
const extensionIds = (
const editKey = await page3.waitForSelector('#edit_key .clickable') await Promise.all(
await editKey.click() targets.map(async (target) => {
if (target.type() !== 'service_worker') {
const settingsInput = await page3.$('input.settings_text') return
await settingsInput.type(nopechaKey) }
await settingsInput.evaluate((el, value) => {
el.value = value // const titleL = title?.toLowerCase()
}, nopechaKey) // if (titleL?.includes('nopecha'))
await settingsInput.press('Enter') const url = new URL(target.url())
await delay(500) return url.hostname
await editKey.click() })
await delay(2000) )
).filter(Boolean)
const extensionId = extensionIds[0]
if (extensionId) {
const extensionUrl = `chrome-extension://${extensionId}/popup.html`
await page3.goto(extensionUrl, { waitUntil: 'networkidle2' })
await delay(500)
const editKey = await page3.waitForSelector('#edit_key .clickable')
await editKey.click()
const settingsInput = await page3.$('input.settings_text')
await settingsInput.type(nopechaKey)
await settingsInput.evaluate((el, value) => {
el.value = value
}, nopechaKey)
await settingsInput.press('Enter')
await delay(500)
await editKey.click()
await delay(2000)
} else {
console.error(
"error initializing nopecha extension; couldn't determine extension ID"
)
}
} catch (err) {
console.error('error initializing nopecha extension', err)
}
} }
return browser return browser
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment