Skip to content

Commit

Permalink
use playwright as library
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 9, 2023
1 parent f28637d commit e05a09d
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 139 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start": "node src/index.js",
"serve": "open https://127.0.0.1/ && http-server -p 443 -P https://127.0.0.1/ -S",
"test": "f(){ if [ -z \"$CI\" ]; then jest --onlyChanged $*; else jest $*; fi }; NODE_OPTIONS=--experimental-vm-modules f",
"lint": "eslint src && tsc && playwright test",
"lint": "eslint src && tsc",
"prepare": "husky install"
},
"dependencies": {
Expand Down
12 changes: 0 additions & 12 deletions playwright.config.ts

This file was deleted.

14 changes: 7 additions & 7 deletions src/2023/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
</header>
<main>
<style>
.calendar .calendar-color-l { color:#ccccff; }
.calendar .calendar-color-n { color:#9b715b; }
.calendar .calendar-color-y { color:#ffff66; text-shadow:0 0 5px #ffff66, 0 0 10px #ffff66; }
.calendar .calendar-color-g { color:#00cc00; }
.calendar .calendar-color-m { color:#d4dde4; }
.calendar .calendar-color-w { color:#ffffff; }
.calendar .calendar-color-b { color:#5555bb; }
.calendar .calendar-color-k { color:#6b4d3b; }
.calendar .calendar-color-w { color:#ffffff; }
.calendar .calendar-color-n { color:#9b715b; }
.calendar .calendar-color-m { color:#d4dde4; }
.calendar .calendar-color-s { color:#e3b585; }
.calendar .calendar-color-l { color:#ccccff; }
.calendar .calendar-color-y { color:#ffff66; text-shadow:0 0 5px #ffff66, 0 0 10px #ffff66; }
.calendar .calendar-color-g { color:#00cc00; }
</style>
<pre class="calendar"><span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
Expand All @@ -53,7 +53,7 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
(function(){
var countdown = document.getElementById("calendar-countdown");
if (!countdown) return;
var server_eta = 84026;
var server_eta = 50046;
var key = "2023-10-"+server_eta;
var now = Math.floor(new Date().getTime()/1000);
var target = server_eta + now;
Expand Down
343 changes: 245 additions & 98 deletions src/2023/leaderboard.html

Large diffs are not rendered by default.

Binary file modified src/static/solver-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion src/utils/solver.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import { fileURLToPath, resolve } from 'node:url';
import { performance } from 'node:perf_hooks';
import { existsSync, readdirSync } from 'node:fs';

import ProgressBar from 'progress';
import { chromium } from 'playwright';
import readInput from './read-input.js';
import { dayName } from './day-name.js';
import {
Expand Down Expand Up @@ -61,6 +62,24 @@ function getDays(year) {
}
}

async function takeScreenshots() {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(resolve(import.meta.url, '../2023/events.html'));
await page.waitForTimeout(1000);
await page.screenshot({
path: 'src/static/events-screenshot.png',
clip: { x: 0, y: 0, width: 1030, height: 420 },
});
await page.goto(resolve(import.meta.url, '../2023/solver.html'));
await page.waitForTimeout(1000);
await page.screenshot({
path: 'src/static/solver-screenshot.png',
clip: { x: 0, y: 0, width: 1030, height: 420 },
});
await browser.close();
}

export default async function solveAll(year, day, run = true) {
if (day) {
tempLeaderboard(year);
Expand All @@ -84,6 +103,7 @@ export default async function solveAll(year, day, run = true) {
await downloadInput(year, day);
bar.tick();
}
await takeScreenshots();
console.log('');

if (run) {
Expand Down
20 changes: 0 additions & 20 deletions tests/screenshot.spec.ts

This file was deleted.

0 comments on commit e05a09d

Please sign in to comment.