dsh-folia 2.5.0 → 2.5.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/lib/client.js +43 -29
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -16231,30 +16231,38 @@ window.__ModuleLoader__.load({
|
|
|
16231
16231
|
}
|
|
16232
16232
|
|
|
16233
16233
|
/**
|
|
16234
|
-
*
|
|
16234
|
+
* 把一套皮肤的样式**当场**挂进文档。
|
|
16235
16235
|
*
|
|
16236
|
-
*
|
|
16237
|
-
*
|
|
16238
|
-
*
|
|
16239
|
-
*
|
|
16236
|
+
* 为什么是 `<style>` 而不是 `<link>`:
|
|
16237
|
+
* · `<link rel=stylesheet>` 是**异步**的,加载完成的时机不定,容易输给皮肤中心随后
|
|
16238
|
+
* 重新注入的那份;
|
|
16239
|
+
* · `<style>` 一赋值就参与样式计算,且追加到 `<body>` **末尾** ⇒ 文档顺序最后,
|
|
16240
|
+
* 同等特异性下后写的赢。这是"不刷新换肤"能真正看见的关键。
|
|
16241
|
+
*
|
|
16242
|
+
* 仍然不跑 `hooks.mjs`(粒子等动效),那部分只有整页重载才生效。
|
|
16240
16243
|
*
|
|
16241
16244
|
* @param {string} id 皮肤 id
|
|
16245
|
+
* @returns {Promise<{ bytes: number, rules: number }>}
|
|
16242
16246
|
*/
|
|
16243
|
-
function applySkinCss(id) {
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
|
|
16251
|
-
|
|
16252
|
-
|
|
16253
|
-
el
|
|
16254
|
-
|
|
16255
|
-
|
|
16256
|
-
|
|
16257
|
-
}
|
|
16247
|
+
async function applySkinCss(id) {
|
|
16248
|
+
const resp = await apiFetch("/skins/css?id=" + encodeURIComponent(id) + "&t=" + Date.now(), {
|
|
16249
|
+
parse: false,
|
|
16250
|
+
cache: "no-store",
|
|
16251
|
+
});
|
|
16252
|
+
if (!resp || !resp.ok || !resp.response) throw new Error("css-http-" + ((resp && resp.status) || 0));
|
|
16253
|
+
const css = await resp.response.text();
|
|
16254
|
+
if (!css || !css.trim()) throw new Error("css-empty");
|
|
16255
|
+
let el = document.getElementById("folia-skin-hot");
|
|
16256
|
+
if (!el) {
|
|
16257
|
+
el = document.createElement("style");
|
|
16258
|
+
el.id = "folia-skin-hot";
|
|
16259
|
+
// 挂 body 末尾(不是 head):文档顺序最后 ⇒ 同等特异性下覆盖先前的规则。
|
|
16260
|
+
(document.body || document.head).appendChild(el);
|
|
16261
|
+
}
|
|
16262
|
+
el.textContent = css;
|
|
16263
|
+
let rules = 0;
|
|
16264
|
+
try { rules = (el.sheet && el.sheet.cssRules && el.sheet.cssRules.length) || 0; } catch { /* 读不到就报 0 */ }
|
|
16265
|
+
return { bytes: css.length, rules };
|
|
16258
16266
|
}
|
|
16259
16267
|
|
|
16260
16268
|
function SkinsTabPanel() {
|
|
@@ -16319,14 +16327,22 @@ window.__ModuleLoader__.load({
|
|
|
16319
16327
|
setNote({ kind: "ok", text: weT("已安装:") + label });
|
|
16320
16328
|
await load(true);
|
|
16321
16329
|
} else if (kind === "activate") {
|
|
16322
|
-
//
|
|
16323
|
-
//
|
|
16324
|
-
|
|
16330
|
+
// **当场换肤**:把皮肤样式同步注入文档,不刷新、不重启。
|
|
16331
|
+
// 注入结果直接写进提示里(字节数 / 规则条数):万一样式还是没盖住皮肤中心,
|
|
16332
|
+
// 这一行就是判断"是没注入"还是"注入了但被压住"的依据,不用再猜。
|
|
16333
|
+
let info = null;
|
|
16334
|
+
let applyErr = "";
|
|
16335
|
+
try {
|
|
16336
|
+
info = await applySkinCss(id);
|
|
16337
|
+
} catch (e) {
|
|
16338
|
+
applyErr = String((e && e.message) || e);
|
|
16339
|
+
}
|
|
16325
16340
|
setNote({
|
|
16326
|
-
kind: "ok",
|
|
16327
|
-
text:
|
|
16328
|
-
? weT("
|
|
16329
|
-
: weT("
|
|
16341
|
+
kind: applyErr ? "err" : "ok",
|
|
16342
|
+
text: applyErr
|
|
16343
|
+
? weT("已切换为「") + label + weT("」,但样式注入失败:") + applyErr
|
|
16344
|
+
: weT("已切换到「") + label + weT("」—— 已注入 ")
|
|
16345
|
+
+ Math.round(info.bytes / 1024) + " KB / " + info.rules + weT(" 条样式规则"),
|
|
16330
16346
|
// hooks(粒子等动效)只有整页重载才会跑:给一个可选入口,不强制。
|
|
16331
16347
|
reload: true,
|
|
16332
16348
|
});
|
|
@@ -16528,8 +16544,6 @@ window.__ModuleLoader__.load({
|
|
|
16528
16544
|
: React.createElement("div", { style: SKINS_STYLE.thumb }),
|
|
16529
16545
|
React.createElement("div", { style: SKINS_STYLE.body },
|
|
16530
16546
|
React.createElement("div", { style: SKINS_STYLE.title }, s.name || s.id),
|
|
16531
|
-
React.createElement("div", { style: SKINS_STYLE.meta },
|
|
16532
|
-
(s.author ? s.author : weT("未知作者")) + " · " + skinsFmtBytes(s.zipBytes)),
|
|
16533
16547
|
s.tagline ? React.createElement("div", { style: SKINS_STYLE.meta }, s.tagline) : null,
|
|
16534
16548
|
(s.tags || []).length
|
|
16535
16549
|
? React.createElement("div", { style: SKINS_STYLE.tags },
|