Files
magpie/internal/gui/assets/theme.js
T
yetone f463a8aaf7 gui: Settings has Loading bird, which keeps magpie's bird off skeletons and stops looking for them
Yayoi_no_yume on X, agreed by GymlinZhu: they run magpie on a 1-core,
1GB server and asked for a way to turn the loading bird off. The owner
wanted the bird, so it stays on by default. Settings -> General now has
"Loading bird" (Off / On), below Reduce motion.

- settings.json keeps noBird (omitted when the bird is on), and boot.js
  passes it. A POST that leaves it out keeps it, as with the other prefs.
  theme.js sets data-bird="off" on <html> before the first paint, and
  applyPrefs changes it.
- skelBird (app.js): with the bird off, nothing looks for skeletons at
  all. No 250ms interval and no observer run. Turning it off mid-hop ends
  the hops, and the bird flies off.
- With the bird on, the look is driven by events. Before, the 250ms
  setInterval ran forever, scanning the DOM for .skeleton whether or not
  one existed. Now a MutationObserver watches for an added node that is or
  holds a skeleton, the 250ms look runs only while one is in the page,
  and the look stops itself once none are left.
- The README's bird (plugins.js bounceLoader): with the bird off, the four
  lines stand straight with no bird, and the box goes when the README
  comes.
- Strings are in en, zh, zh-TW, ja and de. App.js is 1,294,016 bytes, under
  its budget, which is not raised.

Tests:
- skeleton-bird.test.cjs adds three tests:
  - with no skeleton left, the look stops, and a skeleton added later
    starts it again;
  - with the setting saved off, no bird, no dip and no look ever starts
    (setInterval is wrapped to count the look);
  - the Settings row shows On by default; Off posts noBird:true, stops a
    running look, and a skeleton added after that starts none; On posts
    false and the look starts again.
- plugin-readme-bird.test.cjs: with the setting off, the lines stay
  straight, no .sk-bird is drawn, and the box goes at once.
- settings-general: #birdSegs is in the list of bare rows.
- TestSettingsNoBird: off by default, kept by a POST that leaves it out,
  cleared by false, in settings.json and boot.js.

Run at this head (rebased on e15b2277c):
- mote: go test -run "Budget|TestSettings|TestBoot|TestI18n"
  ./internal/gui ./internal/settings: ok. GOOS=linux, windows and darwin
  go vet -tags nogui of both: clean (on the pre-rebase base aad6546cd,
  with no Go change between the two). gofmt -l: clean.
- wsl-run (Linux), both engines: skeleton-bird, plugin-readme-bird,
  settings-general, reduce-motion and i18n-keys: 43 of 44 pass. The one
  red is skeleton-bird's original hopping test in WebKit. It is red 2 of
  2 on origin/main e15b2277c in the same place, filed as #4176 (also one
  line of #4120).
- Before the rebase, on mote in Chromium, the same five files all passed.
- wsl-run Chromium: settings-groups, settings-lines-wrap, settings-search,
  settings-sections, settings-shortcut, settings-tabs-stick, text-size,
  menu-scroll and i18n-keys: 76 of 76 pass.

Broken by hand:
- With birdOff() always false, the three new off tests go red (README,
  skeletons, Settings row).
- With the look never stopping itself, "with no skeleton left" goes red.

Not tried:
- WebKit on mote. Playwright's WebKit never launched there (180s launch
  timeouts at load 65-300), so macOS WebKit wasn't run; WebKit ran only on
  Linux.
- The whole GUI suite (970 files), because mote was under heavy load.
- The real app on any OS, and a real 1c1g server. The CPU saved wasn't
  measured.
2026-10-29 13:12:36 +08:00

30 lines
1.6 KiB
JavaScript

// Apply the saved theme and text size (boot.js) before styles first apply.
// A theme requested by the page's address takes precedence. Waiting for
// app.js at the foot of the page let the header paint in the system theme
// and default size first, then change as the page loaded.
(function () {
var asked = new URLSearchParams(location.search).get("theme");
var prefs = window.bootPrefs;
var saved = prefs && prefs.theme;
var theme = asked || (saved && saved !== "system" ? saved : "");
if (theme) document.documentElement.dataset.theme = theme;
if (prefs && prefs.colorblind) document.documentElement.dataset.colorblind = "1";
if (prefs && prefs.reduceMotion) document.documentElement.dataset.motion = "reduce";
if (prefs && prefs.noBird) document.documentElement.dataset.bird = "off";
if (prefs) document.documentElement.style.setProperty("--zoom", prefs.web ? 1 : (prefs.textSize || 100) / 100);
})();
// Settings' Reduce motion (#3813) applies the stylesheets' reduced-motion
// rules, their media set to all and back; calm() in app.js follows it
(function () {
var held = [];
window.holdStill = function (on) {
var root = document.documentElement;
if (on) root.dataset.motion = "reduce"; else delete root.dataset.motion;
held.forEach(function (h) { h[0].media.mediaText = h[1]; });
held = [];
if (on) for (var i = 0, s = document.styleSheets; i < s.length; i++) for (var j = 0, r = s[i].cssRules; j < r.length; j++)
if (r[j].media && /reduced-motion: *reduce/.test(r[j].media.mediaText)) held.push([r[j], r[j].media.mediaText]), r[j].media.mediaText = "all";
};
})();