#!/usr/bin/env node // 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) // 3. Injects favicon link const fs = require("fs"); const path = require("path"); const { getVersion } = require("../server/version"); const asarDir = process.argv[2]; if (!asarDir) { console.error("Usage: node patch-obsidian.js "); process.exit(1); } function patchHtml(filePath, version) { const backupPath = filePath + ".orig"; if (!fs.existsSync(filePath) && !fs.existsSync(backupPath)) { console.warn(`[patch] Skipping (not found): ${filePath}`); return; } // Create backup of the original on first patch; restore from it on subsequent runs if (!fs.existsSync(backupPath)) { fs.copyFileSync(filePath, backupPath); console.log(`[patch] Backed up original: ${backupPath}`); } else { fs.copyFileSync(backupPath, filePath); } let html = fs.readFileSync(filePath, "utf-8"); // Remove CSP meta tag html = html.replace( /\s*]*>\s*/g, "\n", ); // Inject favicon into html = html.replace( "", ' \n', ); // Inject ignis scripts before the first \n` + `\n` + '