本人做游戏攻略,每个职业都有各自的职业专有颜色,现有的 app 内自带的颜色不够用也不全面,故想提出请求,希望可以自定义字体颜色,望接纳 👌🙏
可否能增加一个自定义字体颜色的功能
相关帖子
-
写了个代码片段,想要啥颜色自己加

(function () { /******************* 配置区 ******************/ const CUSTOM_COLORS = [ { color: "rgba(255,0,0,0.2)", bgColor: "", text: "红", name: "浅红字" }, { color: "", bgColor: "#ffe58f", text: "", name: "黄背景" }, { color: "#1890ff"}, { color: "rgba(0,0,0,0)", bgColor: "rgba(0,0,0,.05)", text: "A" }, ]; const REMOVE_N = 2; // 区间起始(含) const REMOVE_M = 5; // 区间结束(含) /********************************************/ const CUSTOM_BTN_CLASS = "custom-color-btn"; const VISIBILITY_MAP = new WeakMap(); // key: 面板节点, value: 上一次是否可见 /* ---------- 工具函数 ---------- */ function getColorId(cfg) { return cfg.color || cfg.bgColor || ""; } function createBtn(cfg) { const id = getColorId(cfg); if (!id) return null; const btn = document.createElement("button"); btn.className = `color__square ${CUSTOM_BTN_CLASS}`; btn.textContent = cfg.text || "A"; btn.dataset.type = "style1"; btn.dataset.colorId = id; btn.setAttribute("aria-label", cfg.name || id); const style = []; if (cfg.color) style.push(`color: ${cfg.color}`); if (cfg.bgColor) style.push(`background-color: ${cfg.bgColor}`); btn.style.cssText = style.join("; "); return btn; } /* ---------- 对单个面板执行“删区间 + 注入” ---------- */ function handleOnePanel(panel) { const isVisible = !panel.classList.contains("fn__none"); const wasVisible = VISIBILITY_MAP.get(panel); /* 仅当“刚刚变成可见”时处理一次 */ if (isVisible && !wasVisible) { const allDivs = panel.querySelectorAll(".protyle-font > div"); let heading = null; for (const d of allDivs) { if (d.textContent.trim() === "颜色" && d.nextElementSibling?.classList.contains("fn__hr--small")) { heading = d; break; } } if (!heading) return; const container = heading.nextElementSibling.nextElementSibling; if (!container || !container.classList.contains("fn__flex-wrap")) return; /* 删区间 [REMOVE_N, REMOVE_M] 内的原按钮 */ const stockBtns = Array.from(container.querySelectorAll("button.color__square:not(.custom-color-btn)")); const start = REMOVE_N - 1; const end = REMOVE_M - 1; for (let i = end; i >= start; i--) { if (stockBtns[i]) stockBtns[i].remove(); } /* 清理旧自定义按钮 */ container.querySelectorAll(`button.${CUSTOM_BTN_CLASS}[data-color-id]`) .forEach(b => b.remove()); /* 插入最新自定义按钮 */ CUSTOM_COLORS.forEach(cfg => { const btn = createBtn(cfg); if (btn) container.appendChild(btn); }); } VISIBILITY_MAP.set(panel, isVisible); } /* ---------- 全局轮询:所有面板(含隐藏) ---------- */ setInterval(() => { document.querySelectorAll('.protyle-util').forEach(handleOnePanel); }, 300); })(); - 其他回帖

欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于