/* runtime-plugin-loader.js —— 插件脚本加载(内置 / 外部 / 本地开发) * * 从 app.js 抽出来:app.js 只做装配,加载细节在这里。 * 三个入口都返回 boolean,并把状态写回传进来的 record(status/error),供插件面板展示。 * · loadBuiltin :同源 /plugins/,走 SRI(integrity 强制校验) * · loadExternal :<资料目录>/plugins/,先读文本 → WebCrypto 校验 sha256 → blob 注入 * · loadLocal :开发者模式,code 已在内存里(免签名),blob 注入 */ ;(function (global) { 'use strict' function host () { return global.IWBPluginHost || null } // 外部插件源(<资料目录>/plugins/ 的读写封装) function source () { const F = global.IWBStorageFile || null return (F && F.plugins && typeof F.plugins.read === 'function') ? F.plugins : null } async function verifyCode (code, integrity) { if (!integrity) return false const expect = String(integrity).replace(/^sha256-/, '') const buf = await global.crypto.subtle.digest('SHA-256', new global.TextEncoder().encode(code)) const u8 = new Uint8Array(buf) let bin = '' for (let i = 0; i < u8.length; i++) bin += String.fromCharCode(u8[i]) return global.btoa(bin) === expect } // 版本比较(v3.25.44):外置插件不再无条件覆盖内置 —— 高版本胜,同版本外置胜(允许本地打补丁)。 // 否则用户资料目录里残留的旧外置插件会永久盖住随包升级后的内置插件(browser 1.6.0 盖 1.7.0 的真实案例)。 function compareVersions (a, b) { const pa = String(a || '0').split('.').map(function (x) { return parseInt(x, 10) || 0 }) const pb = String(b || '0').split('.').map(function (x) { return parseInt(x, 10) || 0 }) const n = Math.max(pa.length, pb.length) for (let i = 0; i < n; i++) { const x = pa[i] || 0 const y = pb[i] || 0 if (x !== y) return x > y ? 1 : -1 } return 0 } async function sha256Hex (text) { const buf = await global.crypto.subtle.digest('SHA-256', new global.TextEncoder().encode(String(text))) return Array.from(new Uint8Array(buf)).map(function (b) { return b.toString(16).padStart(2, '0') }).join('') } // 目录插件(v3.25.41 / M1):一个插件一个目录 // <内置>/plugins//{manifest.json,main.js,styles.css} // <资料目录>/plugins//{同} // 与单文件插件共用同一套「自注册」契约,区别只是多读一个 manifest 和可选 styles.css。 const styleNodes = {} const pendingStyles = {} // v3.26.109 教训(两次踩坑): // 1) WKWebView 下插到 的