-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
30 lines (29 loc) · 1.42 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// SPDX-FileCopyrightText: © 2024 Kevin Lu
/// SPDX-Licence-Identifier: AGPL-3.0-or-later
import { chromium, devices } from "playwright";
import { PlaywrightBlocker } from "@cliqz/adblocker-playwright";
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext(devices["Desktop Chrome"]);
const page = await context.newPage();
// Sometimes interferes with page rendering in automation
const blocker = await PlaywrightBlocker.fromPrebuiltAdsAndTracking();
await blocker.enableBlockingInPage(page);
await page.goto("https://ygoprodeck.com/tournaments/top-archetypes/");
// For screenshot backgrounds
await page.evaluate(() => document.body.style.background = "transparent");
async function screenshot(path) {
await page.locator(".piechart-slice").first().scrollIntoViewIfNeeded();
// omitBackground not supported in Firefox
await page.locator("#piechart-container").screenshot({ path, omitBackground: true });
}
await screenshot("_site/top-chart-tcg.png");
await page.getByLabel("Format Menu").click();
await page.getByLabel("Format Menu").selectOption("OCG");
await screenshot("_site/top-chart-ocg.png");
await page.getByLabel("Format Menu").click();
await page.getByLabel("Format Menu").selectOption("OCG-AE");
await screenshot("_site/top-chart-ocg-ae.png");
await context.close();
await browser.close();
})();