vault management

This commit is contained in:
Nystik
2026-03-10 22:31:01 +01:00
parent 21952f8130
commit 335f9ee4b7
11 changed files with 495 additions and 93 deletions

View File

@@ -2,6 +2,7 @@
// Patches the extracted Obsidian asar for browser use:
// 1. Removes Content-Security-Policy meta tag
// 2. Injects shim-loader.js script (non-deferred, before all other scripts)
// Patches both index.html and starter.html.
const fs = require("fs");
const path = require("path");
@@ -12,27 +13,29 @@ if (!asarDir) {
process.exit(1);
}
const indexPath = path.join(asarDir, "index.html");
if (!fs.existsSync(indexPath)) {
console.error(`Not found: ${indexPath}`);
process.exit(1);
function patchHtml(filePath) {
if (!fs.existsSync(filePath)) {
console.warn(`[patch] Skipping (not found): ${filePath}`);
return;
}
let html = fs.readFileSync(filePath, "utf-8");
// Remove CSP meta tag
html = html.replace(
/\s*<meta\s+http-equiv="Content-Security-Policy"[^>]*>\s*/g,
"\n",
);
// Inject shim-loader before the first <script> tag
html = html.replace(
'<script type="text/javascript"',
'<script type="text/javascript" src="shim-loader.js"></script>\n' +
'<script type="text/javascript"',
);
fs.writeFileSync(filePath, html);
console.log(`[patch] Patched ${filePath}`);
}
let html = fs.readFileSync(indexPath, "utf-8");
// Remove CSP meta tag
html = html.replace(
/\s*<meta\s+http-equiv="Content-Security-Policy"[^>]*>\s*/g,
"\n",
);
// Inject shim-loader before the first <script> tag
html = html.replace(
'<script type="text/javascript"',
'<!-- Shim loader MUST load before everything else (no defer) -->\n' +
'<script type="text/javascript" src="shim-loader.js"></script>\n' +
'<script type="text/javascript"',
);
fs.writeFileSync(indexPath, html);
console.log(`[patch] Patched ${indexPath}`);
patchHtml(path.join(asarDir, "index.html"));