Files
yianxue-assistant/build-userscript.mjs
T

30 lines
1.7 KiB
JavaScript

import { readFileSync, writeFileSync } from 'node:fs';
const metadata = `// ==UserScript==
// @name 谊安学助手 2.0
// @namespace yianxue-question-bank
// @version 2.0.2
// @description 不绑定网址的题库助手:岗位搜索、答案全文核对、练习及桌面考试自动选择。
// @match *://*/*
// @match file:///*
// @run-at document-idle
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_setClipboard
// @noframes
// ==/UserScript==
`;
const zip = readFileSync(new URL('./vendor/jszip.min.js', import.meta.url), 'utf8');
const zipLicense = readFileSync(new URL('./vendor/LICENSE-JSZip.md', import.meta.url), 'utf8').split(/\r?\nGPL version 3/)[0];
const pakoLicense = readFileSync(new URL('./vendor/LICENSE-pako.txt', import.meta.url), 'utf8');
const notices = '/* Third-party notices: JSZip and pako distributed under their MIT licenses.\n'
+ zipLicense + '\n' + pakoLicense + '\n*/\n';
// 用局部 CommonJS 环境加载内置 ZIP 库,避免被网页的 AMD / require 接管。
const zipWrapper = '(function () { const module = { exports: {} }; const exports = module.exports;\n'
+ zip + '\nwindow.JSZip = module.exports;\n})();\n';
const modules = ['question-bank-core.js', 'bank-store.js', 'answer-matcher.js',
'copy-controller.js', 'assistant-panel.js', 'answer-runner.js', 'practice-exporter.js'];
const source = modules.map(name => readFileSync(new URL('./' + name, import.meta.url), 'utf8')).join('\n');
writeFileSync(new URL('./谊安学助手 2.0.user.js', import.meta.url), metadata + '\n' + notices + zipWrapper + source, 'utf8');
console.log('已生成 谊安学助手 2.0.user.js');