@jonandev/longbeard 0.11.2 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +4 -5
- package/CHANGELOG.md +72 -0
- package/README.md +64 -43
- package/beard.json +124 -28
- package/bin/long-beard.js +171 -36
- package/package.json +1 -1
- package/skills/design/SKILL.md +51 -126
- package/skills/design-brief/SKILL.md +146 -0
- package/skills/design-brief/references/graphic.md +59 -0
- package/skills/design-check/SKILL.md +27 -11
- package/skills/design-check/references/design-rules.md +21 -7
- package/skills/design-check/scripts/capture.mjs +121 -37
- package/skills/design-check/scripts/contrast.mjs +23 -9
- package/skills/design-check/scripts/rules.mjs +613 -0
- package/skills/design-check/scripts/screen-contrast.mjs +428 -0
- package/skills/design-check/scripts/tokens.mjs +346 -0
- package/skills/design-content/SKILL.md +118 -0
- package/skills/design-content/scripts/contact-sheet.mjs +259 -0
- package/skills/design-content/scripts/pictures.mjs +197 -0
- package/skills/design-direction/SKILL.md +115 -200
- package/skills/design-direction/references/controls.md +58 -0
- package/skills/{design → design-direction}/references/design-rules.md +21 -7
- package/skills/design-direction/references/five-second.md +47 -0
- package/skills/design-direction/references/full-build.md +19 -0
- package/skills/design-direction/references/graphic.md +35 -0
- package/skills/design-direction/references/grid.md +114 -0
- package/skills/design-direction/references/library.md +75 -0
- package/skills/design-direction/references/screen-template.html +233 -0
- package/skills/design-direction/references/subject.md +33 -0
- package/skills/design-direction/scripts/capture.mjs +121 -37
- package/skills/design-direction/scripts/contact-sheet.mjs +18 -7
- package/skills/design-direction/scripts/fonts.mjs +276 -0
- package/skills/design-direction/scripts/layout-diff.mjs +118 -0
- package/skills/design-direction/scripts/measure.mjs +1728 -0
- package/skills/design-direction/scripts/moodboard.mjs +123 -32
- package/skills/design-direction/scripts/picture-cast.mjs +270 -0
- package/skills/design-direction/scripts/pictures.mjs +197 -0
- package/skills/design-direction/scripts/screen-contrast.mjs +428 -0
- package/skills/design-direction/scripts/sheet.mjs +67 -0
- package/skills/design-direction/scripts/subject-colours.mjs +410 -0
- package/skills/design-families/SKILL.md +138 -0
- package/skills/design-families/scripts/contact-sheet.mjs +259 -0
- package/skills/design-families/scripts/families.mjs +606 -0
- package/skills/design-families/scripts/measure.mjs +1728 -0
- package/skills/design-families/scripts/moodboard.mjs +467 -0
- package/skills/design-families/scripts/tag.mjs +289 -0
- package/skills/design-figma/SKILL.md +69 -0
- package/skills/design-figma/references/graphic.md +26 -0
- package/skills/design-identity/SKILL.md +134 -0
- package/skills/design-identity/references/graphic.md +8 -0
- package/skills/design-identity/references/identity-board.html +140 -0
- package/skills/{design → design-identity}/scripts/capture.mjs +121 -37
- package/skills/design-identity/scripts/colours.mjs +213 -0
- package/skills/design-identity/scripts/contrast.mjs +41 -0
- package/skills/design-identity/scripts/fonts.mjs +276 -0
- package/skills/design-identity/scripts/measure.mjs +1728 -0
- package/skills/design-identity/scripts/sheet.mjs +67 -0
- package/skills/design-identity/scripts/subject-colours.mjs +410 -0
- package/skills/design-moodboard/SKILL.md +184 -0
- package/skills/design-moodboard/references/graphic.md +25 -0
- package/skills/{design-direction → design-moodboard}/references/sources.md +21 -11
- package/skills/design-moodboard/scripts/capture.mjs +893 -0
- package/skills/design-moodboard/scripts/contact-sheet.mjs +259 -0
- package/skills/design-moodboard/scripts/crops.mjs +256 -0
- package/skills/design-moodboard/scripts/dribbble-cards.mjs +418 -0
- package/skills/design-moodboard/scripts/families.mjs +606 -0
- package/skills/design-moodboard/scripts/group.mjs +221 -0
- package/skills/design-moodboard/scripts/measure.mjs +1728 -0
- package/skills/design-moodboard/scripts/moodboard.mjs +467 -0
- package/skills/{design-direction → design-moodboard}/scripts/picker.mjs +121 -20
- package/skills/design-moodboard/scripts/pictures.mjs +197 -0
- package/skills/design-moodboard/scripts/tag.mjs +289 -0
- package/skills/design-prototype/SKILL.md +149 -0
- package/skills/design-prototype/references/design-md-template.md +82 -0
- package/skills/design-prototype/references/design-rules.md +203 -0
- package/skills/design-prototype/references/five-second.md +47 -0
- package/skills/design-prototype/references/graphic.md +27 -0
- package/skills/design-prototype/scripts/capture.mjs +893 -0
- package/skills/design-prototype/scripts/contrast.mjs +41 -0
- package/skills/design-prototype/scripts/links.mjs +308 -0
- package/skills/design-prototype/scripts/pictures.mjs +197 -0
- package/skills/design-prototype/scripts/rules.mjs +613 -0
- package/skills/design-prototype/scripts/screen-contrast.mjs +428 -0
- package/skills/design-prototype/scripts/sheet.mjs +67 -0
- package/skills/design-prototype/scripts/tokens.mjs +346 -0
- package/skills/design-wordmark/SKILL.md +65 -0
- package/skills/design-wordmark/scripts/capture.mjs +893 -0
- package/skills/design-wordmark/scripts/sheet.mjs +67 -0
- package/skills/framework-skills/SKILL.md +71 -0
- package/skills/idea/SKILL.md +13 -7
- package/skills/idea/references/graphic.md +64 -0
- package/skills/design/references/design-md-template.md +0 -58
- package/skills/design/scripts/contrast.mjs +0 -27
- package/skills/design-direction/scripts/dribbble-cards.mjs +0 -356
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// List Dribbble search/popular cards from a listing URL.
|
|
3
|
+
// Headless Chrome; prints TSV: id-slug\tlikes\tviews\tdesigner\timageURL\ttitle
|
|
4
|
+
// It reads the listing a browser renders, as a person's browser would. When the
|
|
5
|
+
// site answers with a verification page or a limit instead, it stops and says
|
|
6
|
+
// so. It never retries around that.
|
|
7
|
+
// Counts come from the card's own stat elements. A column it cannot read
|
|
8
|
+
// stays empty. It never guesses a count from the title. A title is one line:
|
|
9
|
+
// tabs and line breaks become spaces, so a title cannot split a row.
|
|
10
|
+
//
|
|
11
|
+
// Dribbble's "popular" order mixes likes with recency, so page order is not
|
|
12
|
+
// quality. Rows come out sorted by likes, most first, and a card under
|
|
13
|
+
// --min-likes (default 100) is dropped. A card whose likes cannot be read
|
|
14
|
+
// is kept, last.
|
|
15
|
+
//
|
|
16
|
+
// The default drop list holds only what is never a screen for any product:
|
|
17
|
+
// merch, CVs, worksheets, seasonal cards, stickers, mockups. A look (a poster,
|
|
18
|
+
// an illustration, a logo) or a kind of product (a dashboard, a chatbot, an
|
|
19
|
+
// editor) is a candidate for some brief, so it is never in the list. When the
|
|
20
|
+
// brief rules one out, pass it with --drop. What is dropped, and how many,
|
|
21
|
+
// goes to stderr, so the person can judge the pool.
|
|
22
|
+
//
|
|
23
|
+
// node dribbble-cards.mjs "https://dribbble.com/search/shots/popular/product-design?q=text+editor+screen&timeframe=year" --scrolls 4
|
|
24
|
+
// node dribbble-cards.mjs "<url>" --drop "poster,illustration" --keep "mockup"
|
|
25
|
+
// node dribbble-cards.mjs "<url>" --min-likes 300 --scrolls 0
|
|
26
|
+
// node dribbble-cards.mjs "<url>" --picker >> candidates.tsv # rows for picker.mjs
|
|
27
|
+
import { spawn } from "node:child_process";
|
|
28
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
29
|
+
import { tmpdir } from "node:os";
|
|
30
|
+
import { join } from "node:path";
|
|
31
|
+
import { pathToFileURL } from "node:url";
|
|
32
|
+
|
|
33
|
+
// What is never a screen, whatever the product. These sell the word, not the
|
|
34
|
+
// form. A word that names a look or a kind of product does not belong here.
|
|
35
|
+
export const OFF_TOPIC = [
|
|
36
|
+
"t-shirt", "tshirt", "merch", "hoodie",
|
|
37
|
+
"resume", "cv", "cover letter",
|
|
38
|
+
"worksheet",
|
|
39
|
+
"halloween", "christmas", "valentine",
|
|
40
|
+
"sticker", "mockup",
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
export const words = (s) =>
|
|
44
|
+
String(s || "")
|
|
45
|
+
.toLowerCase()
|
|
46
|
+
.split(",")
|
|
47
|
+
.map((w) => w.trim())
|
|
48
|
+
.filter(Boolean);
|
|
49
|
+
|
|
50
|
+
// The words to drop: the default list less --keep, plus --drop.
|
|
51
|
+
export function dropList({ keep = "", drop = "" } = {}) {
|
|
52
|
+
const kept = words(keep);
|
|
53
|
+
return [...OFF_TOPIC.filter((w) => !kept.includes(w)), ...words(drop)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Whole words only, so "ai" does not swallow "detail" and "cv" does not
|
|
57
|
+
// swallow "cvs". A hyphen in a slug counts as a space.
|
|
58
|
+
export function offTopic(text, dropWords) {
|
|
59
|
+
const hay = ` ${String(text).toLowerCase().replace(/[^a-z0-9]+/g, " ").trim()} `;
|
|
60
|
+
return dropWords.find((word) => hay.includes(` ${word.replace(/[^a-z0-9]+/g, " ")} `)) || "";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// "15.7k" -> 15700. An unreadable count is NaN, never 0.
|
|
64
|
+
export function count(text) {
|
|
65
|
+
const m = String(text || "").replace(/,/g, "").match(/^([\d.]+)([kKmM]?)$/);
|
|
66
|
+
if (!m) return NaN;
|
|
67
|
+
const n = Number(m[1]) * ({ k: 1e3, m: 1e6 }[m[2].toLowerCase()] || 1);
|
|
68
|
+
return Number.isFinite(n) ? n : NaN;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// --scrolls 0 is a choice (the first screen only). Only a missing or unreadable value means 3.
|
|
72
|
+
export function scrollsOf(text) {
|
|
73
|
+
const n = Number(text);
|
|
74
|
+
return text === undefined || String(text).trim() === "" || !Number.isFinite(n) || n < 0 ? 3 : Math.floor(n);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// A field is one line of one column: a tab or a line break in a title would split the row.
|
|
78
|
+
export const oneLine = (text) => String(text ?? "").replace(/\s+/g, " ").trim();
|
|
79
|
+
|
|
80
|
+
// A card is { idSlug, likes, views, designer, imageURL, title }.
|
|
81
|
+
export function cardRow(card) {
|
|
82
|
+
return [card.idSlug, card.likes, card.views, card.designer, card.imageURL, card.title].map(oneLine).join("\t");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// picker.mjs's columns: title, thumbnail, shot page, source, meta.
|
|
86
|
+
export function pickerRow(card) {
|
|
87
|
+
const meta = [oneLine(card.designer), card.likes && `${oneLine(card.likes)} likes`].filter(Boolean).join(" · ");
|
|
88
|
+
return [
|
|
89
|
+
oneLine(card.title),
|
|
90
|
+
`${oneLine(card.imageURL)}?resize=400x300`,
|
|
91
|
+
`https://dribbble.com/shots/${oneLine(card.idSlug)}`,
|
|
92
|
+
"dribbble",
|
|
93
|
+
meta,
|
|
94
|
+
].join("\t");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// The cards that stay, and each card cut with the word that cut it.
|
|
98
|
+
export function cutOffTopic(cards, dropWords) {
|
|
99
|
+
const kept = [];
|
|
100
|
+
const cut = [];
|
|
101
|
+
for (const card of cards) {
|
|
102
|
+
const word = offTopic(`${card.idSlug} ${card.title}`, dropWords);
|
|
103
|
+
if (word) cut.push({ card, word });
|
|
104
|
+
else kept.push(card);
|
|
105
|
+
}
|
|
106
|
+
return { kept, cut };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Likes are the signal people valued a shot. Most first, and none under the
|
|
110
|
+
// floor. An unreadable count is kept, last, so a markup change shows as empty
|
|
111
|
+
// columns instead of an empty list.
|
|
112
|
+
export function rankByLikes(cards, minLikes) {
|
|
113
|
+
const likes = (card) => count(card.likes);
|
|
114
|
+
const strong = cards.filter((card) => !(likes(card) < minLikes));
|
|
115
|
+
strong.sort((a, b) => (likes(b) || -1) - (likes(a) || -1));
|
|
116
|
+
return { strong, weak: cards.length - strong.length };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// What a site shows instead of a listing: a check that you are a person, or a limit.
|
|
120
|
+
export const refused = (text) =>
|
|
121
|
+
/verify (that )?you are (a )?human|are you (a )?human|captcha|just a moment|access denied|too many requests|rate limit|unusual traffic|temporarily blocked/i.test(
|
|
122
|
+
String(text || ""),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
function findChrome() {
|
|
126
|
+
const env = process.env.CHROME_PATH;
|
|
127
|
+
// CHROME_PATH=none: run as if no browser were installed (a quick test run).
|
|
128
|
+
if (env === "none") return null;
|
|
129
|
+
if (env && existsSync(env)) return env;
|
|
130
|
+
const home = process.env.HOME || process.env.USERPROFILE || "";
|
|
131
|
+
const local = process.env.LOCALAPPDATA || "";
|
|
132
|
+
const pf = process.env.PROGRAMFILES || "C:\\Program Files";
|
|
133
|
+
const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
|
|
134
|
+
const candidates = [
|
|
135
|
+
join(pf, "Google/Chrome/Application/chrome.exe"),
|
|
136
|
+
join(pf86, "Google/Chrome/Application/chrome.exe"),
|
|
137
|
+
join(local, "Google/Chrome/Application/chrome.exe"),
|
|
138
|
+
join(pf, "Microsoft/Edge/Application/msedge.exe"),
|
|
139
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
140
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
141
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
142
|
+
join(home, "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
|
|
143
|
+
"/usr/bin/google-chrome",
|
|
144
|
+
"/usr/bin/google-chrome-stable",
|
|
145
|
+
"/usr/bin/chromium",
|
|
146
|
+
"/usr/bin/chromium-browser",
|
|
147
|
+
];
|
|
148
|
+
return candidates.find((path) => path && existsSync(path)) || null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
152
|
+
|
|
153
|
+
// The listing as the browser renders it: an array of cards, as JSON text.
|
|
154
|
+
const READ_CARDS = `(() => {
|
|
155
|
+
const cards = [];
|
|
156
|
+
const seen = new Set();
|
|
157
|
+
const tidy = (t) => (t || "").replace(/\\s+/g, "");
|
|
158
|
+
const isCount = (t) => /^[\\d][\\d.,]*[kKmM]?$/.test(t);
|
|
159
|
+
const hints = (el) =>
|
|
160
|
+
["aria-label", "title", "class", "data-type", "data-test"]
|
|
161
|
+
.map((name) => el.getAttribute(name) || "")
|
|
162
|
+
.join(" ");
|
|
163
|
+
// A counter labelled as likes or views: its own text, or the one
|
|
164
|
+
// descendant that is nothing but a count.
|
|
165
|
+
const labelled = (li, word) => {
|
|
166
|
+
const re = new RegExp(word, "i");
|
|
167
|
+
for (const el of li.querySelectorAll("*")) {
|
|
168
|
+
if (!re.test(hints(el))) continue;
|
|
169
|
+
const own = tidy(el.textContent);
|
|
170
|
+
if (isCount(own)) return own;
|
|
171
|
+
for (const kid of el.querySelectorAll("*")) {
|
|
172
|
+
const t = tidy(kid.textContent);
|
|
173
|
+
if (isCount(t)) return t;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return "";
|
|
177
|
+
};
|
|
178
|
+
// Fallback: leaf elements whose whole text is a count, in DOM order.
|
|
179
|
+
// Dribbble prints likes first, then views. Free text is never read.
|
|
180
|
+
const leafCounts = (li) => {
|
|
181
|
+
const out = [];
|
|
182
|
+
for (const el of li.querySelectorAll("*")) {
|
|
183
|
+
if (el.children.length) continue;
|
|
184
|
+
const t = tidy(el.textContent);
|
|
185
|
+
if (isCount(t)) out.push(t);
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
};
|
|
189
|
+
for (const li of document.querySelectorAll("li")) {
|
|
190
|
+
const a = li.querySelector('a[href*="/shots/"]');
|
|
191
|
+
if (!a) continue;
|
|
192
|
+
const m = (a.getAttribute("href") || "").match(/\\/shots\\/([^/?#]+)/);
|
|
193
|
+
if (!m) continue;
|
|
194
|
+
const idSlug = m[1];
|
|
195
|
+
if (seen.has(idSlug)) continue;
|
|
196
|
+
const img = li.querySelector("img");
|
|
197
|
+
if (!img) continue;
|
|
198
|
+
const raw = img.getAttribute("data-src") || img.currentSrc || img.src || "";
|
|
199
|
+
const imageURL = raw.replace(/\\?.*$/, "");
|
|
200
|
+
if (!imageURL) continue;
|
|
201
|
+
seen.add(idSlug);
|
|
202
|
+
let likes = labelled(li, "like");
|
|
203
|
+
let views = labelled(li, "view");
|
|
204
|
+
if (!likes && !views) {
|
|
205
|
+
const counts = leafCounts(li);
|
|
206
|
+
likes = counts[0] || "";
|
|
207
|
+
views = counts[1] || "";
|
|
208
|
+
}
|
|
209
|
+
// The profile handle, from the card's own designer link.
|
|
210
|
+
const who = li.querySelector('.user-information a[href^="/"]');
|
|
211
|
+
const designer = who ? (who.getAttribute("href") || "").replace(/^\\/|[?#].*$/g, "") : "";
|
|
212
|
+
const title = img.getAttribute("alt") || a.getAttribute("title") || idSlug;
|
|
213
|
+
cards.push({ idSlug, likes, views, designer, imageURL, title });
|
|
214
|
+
}
|
|
215
|
+
return JSON.stringify(cards);
|
|
216
|
+
})()`;
|
|
217
|
+
|
|
218
|
+
async function main() {
|
|
219
|
+
const args = process.argv.slice(2);
|
|
220
|
+
const flag = (name, def) => {
|
|
221
|
+
const i = args.indexOf(`--${name}`);
|
|
222
|
+
if (i === -1) return def;
|
|
223
|
+
const v = args[i + 1];
|
|
224
|
+
args.splice(i, 2);
|
|
225
|
+
return v;
|
|
226
|
+
};
|
|
227
|
+
const has = (name) => {
|
|
228
|
+
const i = args.indexOf(`--${name}`);
|
|
229
|
+
if (i === -1) return false;
|
|
230
|
+
args.splice(i, 1);
|
|
231
|
+
return true;
|
|
232
|
+
};
|
|
233
|
+
const url = args[0];
|
|
234
|
+
const scrolls = scrollsOf(flag("scrolls", undefined));
|
|
235
|
+
const noFilter = has("no-filter");
|
|
236
|
+
const forPicker = has("picker");
|
|
237
|
+
const minLikes = Math.max(0, Number(flag("min-likes", "100")) || 0);
|
|
238
|
+
const dropWords = dropList({ keep: flag("keep", ""), drop: flag("drop", "") });
|
|
239
|
+
if (!url || !/^https?:\/\/(www\.)?dribbble\.com\//i.test(url)) {
|
|
240
|
+
console.error(
|
|
241
|
+
'usage: node dribbble-cards.mjs "https://dribbble.com/search/..." [--scrolls 4] [--min-likes 100] [--drop "a,b"] [--keep "a,b"] [--no-filter] [--picker]',
|
|
242
|
+
);
|
|
243
|
+
process.exit(2);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const exe = findChrome();
|
|
247
|
+
if (!exe) {
|
|
248
|
+
console.error("No Chrome/Edge/Chromium found. Install one or set CHROME_PATH.");
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
if (typeof WebSocket === "undefined") {
|
|
252
|
+
console.error("Node 22+ is required.");
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const dir = mkdtempSync(join(tmpdir(), "hunt-dribbble-"));
|
|
257
|
+
let proc;
|
|
258
|
+
const drop = () => {
|
|
259
|
+
try {
|
|
260
|
+
if (proc?.pid) process.kill(proc.pid, "SIGKILL");
|
|
261
|
+
} catch {}
|
|
262
|
+
try {
|
|
263
|
+
rmSync(dir, { recursive: true, force: true });
|
|
264
|
+
} catch {}
|
|
265
|
+
};
|
|
266
|
+
process.once("exit", drop);
|
|
267
|
+
|
|
268
|
+
proc = spawn(
|
|
269
|
+
exe,
|
|
270
|
+
[
|
|
271
|
+
"--headless=new",
|
|
272
|
+
"--remote-debugging-port=0",
|
|
273
|
+
`--user-data-dir=${dir}`,
|
|
274
|
+
"--no-first-run",
|
|
275
|
+
"--hide-scrollbars",
|
|
276
|
+
"--mute-audio",
|
|
277
|
+
"--force-color-profile=srgb",
|
|
278
|
+
"--window-size=1440,900",
|
|
279
|
+
"about:blank",
|
|
280
|
+
],
|
|
281
|
+
{ stdio: ["ignore", "ignore", "pipe"] },
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
let buf = "";
|
|
285
|
+
const wsUrl = await new Promise((resolveWs, reject) => {
|
|
286
|
+
const t = setTimeout(() => reject(new Error("Chrome did not start")), 20000);
|
|
287
|
+
proc.stderr.on("data", (d) => {
|
|
288
|
+
buf += d.toString();
|
|
289
|
+
const m = buf.match(/DevTools listening on (ws:\/\/[^\s]+)/);
|
|
290
|
+
if (m) {
|
|
291
|
+
clearTimeout(t);
|
|
292
|
+
resolveWs(m[1]);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
proc.on("exit", (code) => {
|
|
296
|
+
clearTimeout(t);
|
|
297
|
+
reject(new Error(`Chrome exited ${code}`));
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const ws = new WebSocket(wsUrl);
|
|
302
|
+
await new Promise((res, rej) => {
|
|
303
|
+
ws.onopen = res;
|
|
304
|
+
ws.onerror = () => rej(new Error("CDP socket failed"));
|
|
305
|
+
});
|
|
306
|
+
let nextId = 1;
|
|
307
|
+
const pending = new Map();
|
|
308
|
+
ws.onmessage = (ev) => {
|
|
309
|
+
const msg = JSON.parse(typeof ev.data === "string" ? ev.data : Buffer.from(ev.data).toString());
|
|
310
|
+
if (msg.id && pending.has(msg.id)) {
|
|
311
|
+
const { resolve: ok, reject: bad } = pending.get(msg.id);
|
|
312
|
+
pending.delete(msg.id);
|
|
313
|
+
if (msg.error) bad(new Error(msg.error.message));
|
|
314
|
+
else ok(msg.result);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
const send = (method, params = {}, sessionId, timeoutMs = 30000) => {
|
|
318
|
+
const id = nextId++;
|
|
319
|
+
return new Promise((resolveSend, reject) => {
|
|
320
|
+
const timer = setTimeout(() => {
|
|
321
|
+
pending.delete(id);
|
|
322
|
+
reject(new Error(`CDP timeout: ${method}`));
|
|
323
|
+
}, timeoutMs);
|
|
324
|
+
pending.set(id, {
|
|
325
|
+
resolve: (v) => {
|
|
326
|
+
clearTimeout(timer);
|
|
327
|
+
resolveSend(v);
|
|
328
|
+
},
|
|
329
|
+
reject: (e) => {
|
|
330
|
+
clearTimeout(timer);
|
|
331
|
+
reject(e);
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
ws.send(JSON.stringify(sessionId ? { id, method, params, sessionId } : { id, method, params }));
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const { targetId } = await send("Target.createTarget", { url: "about:blank" });
|
|
339
|
+
const { sessionId } = await send("Target.attachToTarget", { targetId, flatten: true });
|
|
340
|
+
const page = (method, params, timeoutMs) => send(method, params, sessionId, timeoutMs);
|
|
341
|
+
|
|
342
|
+
await page("Page.enable");
|
|
343
|
+
await page("Runtime.enable");
|
|
344
|
+
await page("Emulation.setDeviceMetricsOverride", {
|
|
345
|
+
width: 1440,
|
|
346
|
+
height: 900,
|
|
347
|
+
deviceScaleFactor: 1,
|
|
348
|
+
mobile: false,
|
|
349
|
+
});
|
|
350
|
+
await page("Page.navigate", { url }, 40000);
|
|
351
|
+
await sleep(3000);
|
|
352
|
+
|
|
353
|
+
for (let i = 0; i < scrolls; i++) {
|
|
354
|
+
await page("Runtime.evaluate", {
|
|
355
|
+
expression: "window.scrollBy(0, Math.round(window.innerHeight * 0.9))",
|
|
356
|
+
returnByValue: true,
|
|
357
|
+
});
|
|
358
|
+
await sleep(900);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const { result } = await page("Runtime.evaluate", { expression: READ_CARDS, returnByValue: true });
|
|
362
|
+
let all = [];
|
|
363
|
+
try {
|
|
364
|
+
all = JSON.parse(result?.value || "[]");
|
|
365
|
+
} catch {}
|
|
366
|
+
if (!all.length) {
|
|
367
|
+
const { result: shown } = await page("Runtime.evaluate", {
|
|
368
|
+
expression: `(document.title + " " + ((document.body && document.body.innerText) || "").slice(0, 600))`,
|
|
369
|
+
returnByValue: true,
|
|
370
|
+
});
|
|
371
|
+
if (refused(shown?.value)) {
|
|
372
|
+
console.error(
|
|
373
|
+
"0 cards: the site answered with a verification page or a limit. Stopped, and not retried. Say so under Sources: and go on without Dribbble.",
|
|
374
|
+
);
|
|
375
|
+
} else {
|
|
376
|
+
console.error(
|
|
377
|
+
"0 cards (an empty listing, or a page this script cannot read). Do not retry around it: say so under Sources: as `<query>: 0 cards`.",
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
drop();
|
|
381
|
+
process.exit(1);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const { kept, cut } = noFilter ? { kept: all, cut: [] } : cutOffTopic(all, dropWords);
|
|
385
|
+
if (cut.length) {
|
|
386
|
+
const reasons = new Map();
|
|
387
|
+
for (const { word } of cut) reasons.set(word, (reasons.get(word) ?? 0) + 1);
|
|
388
|
+
const top = [...reasons.entries()]
|
|
389
|
+
.sort((a, b) => b[1] - a[1])
|
|
390
|
+
.slice(0, 6)
|
|
391
|
+
.map(([word, n]) => `${word} ${n}`)
|
|
392
|
+
.join(", ");
|
|
393
|
+
// The noise rate belongs under the board's drops. A high one means the
|
|
394
|
+
// query is wrong, not that there is more scrolling to do.
|
|
395
|
+
console.error(
|
|
396
|
+
`${kept.length} of ${all.length} cards kept, ${Math.round((cut.length / all.length) * 100)}% dropped by word (${top}); --keep "<word>" brings one back`,
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
if (!kept.length) {
|
|
400
|
+
console.error("every card was dropped by word: query the form, not the word (add \"ui\", \"screen\", or a category path), or --keep a word");
|
|
401
|
+
drop();
|
|
402
|
+
process.exit(1);
|
|
403
|
+
}
|
|
404
|
+
const { strong, weak } = rankByLikes(kept, minLikes);
|
|
405
|
+
if (weak > 0) {
|
|
406
|
+
console.error(`${weak} of ${kept.length} under ${minLikes} likes, dropped (lower it with --min-likes)`);
|
|
407
|
+
}
|
|
408
|
+
if (!strong.length) {
|
|
409
|
+
console.error("every card was under the likes floor: try a broader form or timeframe before lowering it");
|
|
410
|
+
drop();
|
|
411
|
+
process.exit(1);
|
|
412
|
+
}
|
|
413
|
+
console.log(strong.map(forPicker ? pickerRow : cardRow).join("\n"));
|
|
414
|
+
drop();
|
|
415
|
+
process.exit(0);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) await main();
|