Description

This commit is contained in:
Ian Gulliver
2026-07-25 08:42:24 -07:00
parent 9d0f570c85
commit 700b53d50c
3 changed files with 20 additions and 6 deletions
+14 -5
View File
@@ -191,6 +191,7 @@ func (c *Client) Login(ctx context.Context, email, password string) error {
// SpoolInfo is the current state of a spool, read from its edit dialog.
type SpoolInfo struct {
Location string // location label, e.g. "H" (empty if unset)
Description string // brand/material/type/color, e.g. "Bambu Lab ABS GF - Black (41101)"
TotalGrams float64 // weight including the spool (what the scale reads)
RemainingGrams float64 // remaining filament the site tracks
EmptySpoolGrams float64 // empty-spool weight used to derive remaining
@@ -252,23 +253,31 @@ func (c *Client) SpoolInfo(ctx context.Context, spoolID string) (SpoolInfo, erro
const js = `(() => {
const val = id => { const e = document.getElementById(id); return e ? e.value : ''; };
const ph = id => { const e = document.getElementById(id); return e ? e.placeholder : ''; };
const dialog = document.getElementById('weight_with_spool').closest('[role="dialog"]') || document.body;
// The dialog header reads "Edit Spool" then a descriptor line like
// "Bambu Lab ABS GF - Black (41101)" (brand, material, type, color).
const lines = dialog.innerText.split('\n').map(s => s.trim());
const i = lines.indexOf('Edit Spool');
const desc = i >= 0 ? (lines.slice(i + 1).find(s => s.length) || '') : '';
return JSON.stringify({
location: val('location_label'),
total: val('weight_with_spool'),
remaining: val('remaining_grams'),
empty: val('empty_spool_weight') || ph('empty_spool_weight'),
location: val('location_label'),
total: val('weight_with_spool'),
remaining: val('remaining_grams'),
empty: val('empty_spool_weight') || ph('empty_spool_weight'),
description: desc,
});
})()`
var out string
if err := c.run(ctx, 10*time.Second, chromedp.Evaluate(js, &out)); err != nil {
return SpoolInfo{}, err
}
var raw struct{ Location, Total, Remaining, Empty string }
var raw struct{ Location, Total, Remaining, Empty, Description string }
if err := json.Unmarshal([]byte(out), &raw); err != nil {
return SpoolInfo{}, fmt.Errorf("parse spool fields: %w", err)
}
return SpoolInfo{
Location: strings.TrimSpace(raw.Location),
Description: strings.TrimSpace(raw.Description),
TotalGrams: parseGrams(raw.Total),
RemainingGrams: parseGrams(raw.Remaining),
EmptySpoolGrams: parseGrams(raw.Empty),