Files
workbuddy_skills/draw-ui/scripts/collect_browser.js
T
admin 237a09a5b0 修:draw-ui / oil-motion 原被当子模块指针收录 ⇒ 改为正常文件入库(两份内容原先对别人是空的)
一、问题(本轮实测)
`draw-ui` 与 `oil-motion` 目录里**各自带一个内嵌 `.git`** ⇒ 上一次提交把它们记成了 **gitlink(子模块指针)**
⇒ 仓库里只存了一个不属于任何远端的 commit id,**别人克隆下来这两份是空的** ✗(`git status` 显示 ` m draw-ui` / ` m oil-motion` = 子模块内容有改动)。

二、处置(可回退)
· 把两处的 `.git` **挪走**(⛔ 不是删除)⇒ `归档/内嵌git-20261008/{draw-ui,oil-motion}.git`;
· `git rm --cached` 掉那两个 gitlink,再 `git add` 两个目录 ⇒ **按正常文件入库**(内容才真的进仓库)。

三、副作用(如实记)
挪走 `.git` 后,这两个技能**不能再原地 `git pull` 取上游更新**(要更新得重新拉一份覆盖);
如需恢复其本地仓库,把 `归档/内嵌git-20261008/` 里的 `.git` 挪回原处即可。
2026-10-08 22:29:52 +08:00

40 lines
2.4 KiB
JavaScript

/* 由 prepare_capture.py 绑定测量基线。只读取主文档,不导航、不操作页面。 */
(plan) => {
const elements = plan.targets.map(({name, selector}) => {
let matches;
try { matches = document.querySelectorAll(selector); }
catch { return {name, selector, status: 'invalid_selector', count: 0}; }
if (matches.length !== 1) return {name, selector, count: matches.length, status: matches.length ? 'ambiguous' : 'missing'};
const el = matches[0];
const rect = el.getBoundingClientRect();
const style = getComputedStyle(el);
let hidden = ['hidden', 'collapse'].includes(style.visibility);
for (let parent = el; parent; parent = parent.parentElement) {
const s = getComputedStyle(parent);
if (s.display === 'none' || Number(s.opacity) === 0) hidden = true;
}
const hasBox = el.getClientRects().length > 0 && rect.width > 0 && rect.height > 0;
const result = {
name, selector, count: 1,
status: hidden ? 'hidden' : hasBox ? 'measured' : 'unmeasurable',
box: [rect.left + scrollX, rect.top + scrollY, rect.width, rect.height],
text: (el.textContent || '').trim().slice(0, 300),
computed: {display: style.display, visibility: style.visibility, opacity: style.opacity, fontFamily: style.fontFamily, fontSize: style.fontSize, lineHeight: style.lineHeight, fontWeight: style.fontWeight, color: style.color, backgroundColor: style.backgroundColor},
viewport_intersects: rect.bottom > 0 && rect.right > 0 && rect.top < innerHeight && rect.left < innerWidth
};
if (el instanceof HTMLImageElement) result.asset = {src: el.currentSrc, natural_width: el.naturalWidth, natural_height: el.naturalHeight, version: el.dataset.version || null};
return result;
});
return {
measurement_sha256: plan.measurement_sha256,
url: location.href, title: document.title,
viewport: {width: innerWidth, height: innerHeight}, dpr: devicePixelRatio,
scroll: {x: scrollX, y: scrollY}, document_height: document.documentElement.scrollHeight,
fonts_ready: document.fonts.status === 'loaded',
images_ready: [...document.images].every(im => im.complete && im.naturalWidth > 0),
document_overflow_x: document.documentElement.scrollWidth > innerWidth,
captured_at: new Date().toISOString(), elements,
assets: Object.fromEntries(elements.filter(el => el.asset).map(el => [el.name, el.asset]))
};
}