Last active
March 20, 2025 05:46
-
-
Save JonasGao/df0feed0e7371e098dc1b87cbdf5a9e8 to your computer and use it in GitHub Desktop.
替换 Apifox 界面字体
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const path = require("path"); | |
const asar = require("asar"); | |
const src = "../resources/app.asar"; | |
const dest = "../resources/app_copy"; | |
// if dest exists, remove it | |
if (fs.existsSync(dest)) { | |
fs.rmSync(dest, { recursive: true }); | |
console.log(`${dest} removed`); | |
} | |
const extract = async () => { | |
asar.extractAll(src, dest); | |
console.log(`${src} extracted to ${dest}`); | |
// find string from index.html in app_copy/dist/renderer | |
const indexHtml = fs.readFileSync( | |
path.join(dest, "dist", "renderer", "index.html"), | |
"utf8" | |
); | |
// find index.xxxx.css from indexHtml | |
const indexCss = indexHtml.match( | |
/<link [a-z0-9=" ]*href="\.\/index\.([a-z0-9]+)\.css"/g | |
); | |
// extract href from indexCss | |
const hrefs = indexCss.map((css) => css.match(/href="([^"]+)"/)[1]); | |
console.log(hrefs); | |
// replace "--ui-font-family:xxxxxxxx;" with "--ui-font-family:'等距更纱黑体 SC';" in content of hrefs[0] | |
// replace "--ui-code-family" with "--ui-code-family:'等距更纱黑体 SC';" | |
const content = fs.readFileSync( | |
path.join(dest, "dist", "renderer", hrefs[0]), | |
"utf8" | |
); | |
let newContent = content | |
.replace( | |
/--ui-font-family:([^;]+);/g, | |
"--ui-font-family:'等距更纱黑体 SC';" | |
) | |
.replace( | |
/--ui-code-family:([^;]+);/g, | |
"--ui-code-family:'等距更纱黑体 SC';" | |
); | |
// append new class | |
newContent += "\n\n.c-json-schema-editor-delicate-schema-node-field-input {max-width: 220px;}" | |
newContent += "\n\n.c-json-schema-editor-delicate-schema-node-faker-select {display: none !important;}" | |
// save new css content | |
fs.writeFileSync(path.join(dest, "dist", "renderer", hrefs[0]), newContent); | |
console.log(`${hrefs[0]} updated`); | |
// if src.backup exists, remove it | |
if (fs.existsSync(src + ".backup")) { | |
fs.rmSync(src + ".backup", { recursive: true }); | |
console.log(`${src}.backup removed`); | |
} | |
// move src to src.backup | |
fs.renameSync(src, src + ".backup"); | |
console.log(`${src} renamed to ${src}.backup`); | |
// package app_copy to app.asar | |
await asar.createPackage(dest, src); | |
console.log(`${dest} packaged to ${src}`); | |
}; | |
extract(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment