diff --git a/.vscode/launch.json b/.vscode/launch.json index 6231a23..85dd442 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,14 +10,7 @@ "name": "Attach to side panel", "webRoot": "${workspaceFolder}/src/", "port": 9222, - "urlFilter": "chrome-extension://fmalpbpehdilmjhnanhpjmnkgbahopfj/*" - }, - { - "type": "msedge", - "request": "attach", - "name": "Attach to Amazon", - "port": 9222, - "urlFilter": "https://www.amazon.com/*" + "urlFilter": "chrome-extension://ajeifjaabhkjdiedhpagcpihkgjelhaa/*" } ] } diff --git a/package.json b/package.json index 9f8fd25..e0b0167 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "azon-seeker", "displayName": "Azon Seeker", - "version": "0.7.0", + "version": "0.7.1", "private": true, "description": "Starter modify by honestfox101", "scripts": { @@ -17,7 +17,7 @@ "build:background": "vite build --config vite.config.background.mts", "build:web": "vite build", "build:js": "vite build --config vite.config.content.mts", - "pack:7z": "rimraf --glob ./build/*.7z && 7z a ./build/extension.7z extension/* && 7z a ./build/extension-firefox.7z extension-firefox/*", + "pack:7z": "rimraf --glob ./build/*.7z && esno scripts/pack.ts", "start:chromium": "web-ext run --source-dir ./extension --target=chromium --chromium-binary 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'", "start:firefox": "web-ext run --source-dir ./extension-firefox --target=firefox-desktop", "clear": "rimraf --glob extension/dist extension/manifest.json extension.* ", @@ -26,6 +26,7 @@ "prepare": "husky" }, "devDependencies": { + "7zip-min": "^2.1.0", "@iconify/json": "^2.2.359", "@types/fs-extra": "^11.0.4", "@types/gulp-terser": "^1.2.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 27f9013..e5e98d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,9 @@ settings: importers: .: devDependencies: + 7zip-min: + specifier: ^2.1.0 + version: 2.1.0 '@iconify/json': specifier: ^2.2.359 version: 2.2.359 @@ -132,6 +135,18 @@ importers: version: 0.12.0 packages: + 7zip-bin@5.1.1: + resolution: + { + integrity: sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ==, + } + + 7zip-min@2.1.0: + resolution: + { + integrity: sha512-6uoMmPaasBQOyEuMIuNnASA6mF6ZfNmhsKdxJiEbtkHt9DkrJ0w1cZwyNdkDeOKjR2c5gOQAEkvMN3gyZ9MEBw==, + } + '@alova/shared@1.3.1': resolution: { @@ -6114,6 +6129,12 @@ packages: engines: { node: '>= 10' } snapshots: + 7zip-bin@5.1.1: {} + + 7zip-min@2.1.0: + dependencies: + 7zip-bin: 5.1.1 + '@alova/shared@1.3.1': {} '@ampproject/remapping@2.3.0': diff --git a/scripts/pack.ts b/scripts/pack.ts new file mode 100644 index 0000000..ef65341 --- /dev/null +++ b/scripts/pack.ts @@ -0,0 +1,17 @@ +import _7z from '7zip-min'; +import { basename } from 'path'; +import { r, log } from './utils'; +import packageJson from '../package.json'; + +const scriptPath = ['extension', 'extension-firefox']; + +scriptPath.forEach(async (src) => { + const srcPath = r(src); + const distPath = r('build', `${basename(src)}-v${packageJson.version}.7z`); + try { + const output = await _7z.pack(srcPath, distPath); + log('Info', `stdout of the 7za command execution ${output}`); + } catch (err) { + log('Error', `${err}`); + } +}); diff --git a/src/page-worker/impls/homedepot.ts b/src/page-worker/impls/homedepot.ts index 661cbcb..6c1a452 100644 --- a/src/page-worker/impls/homedepot.ts +++ b/src/page-worker/impls/homedepot.ts @@ -51,9 +51,12 @@ class HomedepotWorkerImpl await injector.waitForReviewLoad(); let reviews = await injector.getReviews(); reviews.length > 0 && (await this.emit('review-collected', { OSMID, reviews })); - while ((await injector.tryJumpToNextPage()) && reviews.length > 0) { + let goOn = await injector.tryJumpToNextPage(); + while (goOn && reviews.length > 0) { + await injector.waitForReviewLoad(); reviews = await injector.getReviews(); reviews.length > 0 && (await this.emit('review-collected', { OSMID, reviews })); + goOn = await injector.tryJumpToNextPage(); } setTimeout(() => { browser.tabs.remove(tab.id!); diff --git a/src/page-worker/web-injectors/homedepot.ts b/src/page-worker/web-injectors/homedepot.ts index 0ea81e0..a6ff604 100644 --- a/src/page-worker/web-injectors/homedepot.ts +++ b/src/page-worker/web-injectors/homedepot.ts @@ -178,18 +178,29 @@ export class HomedepotDetailPageInjector extends BaseInjector { public tryJumpToNextPage() { return this.run(async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); + while (!document.querySelector('.pager__summary')) { + await new Promise((resolve) => setTimeout(resolve, 1000)); + } const final = document.querySelector( - '.pager__summary--bold:nth-last-of-type(2)', + '.pager__summary > span:nth-child(2)', )!.innerText; const anchor = document.querySelector( - '.pager__summary--bold + .pager__summary--bold', + '.pager__summary > span:nth-child(3)', )!.innerText; if (final === anchor) { return false; } - const button = document.querySelector('[data-testid="pagination-Next"]'); - button!.click(); + let button = document.querySelector( + '[data-testid="pagination"] li:last-of-type a', + ); + while (!button) { + await new Promise((resolve) => setTimeout(resolve, 500)); + button = document.querySelector( + '[data-testid="pagination"] li:last-of-type a', + ); + } + button.scrollIntoView({ behavior: 'smooth' }); + button.click(); while (true) { const newAnchor = document.querySelector( '.pager__summary--bold + .pager__summary--bold',