You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

52 lines
1.6 KiB

const {jsdomFromText, jsdomFromUrl, browser} = require('sdenv');
const path = require("path");
const fs = require("fs");
const {Script} = require("vm");
const baseUrl = "https://wcjs.sbj.cnipa.gov.cn"
const files = {
html: path.resolve('../public/shangbiao/static/makecode_input_html.html'),
js: path.resolve('../public/shangbiao/static/makecode_input_js.js'),
ts: path.resolve('../public/shangbiao/static/makecode_input_ts.json'),
}
function getFile(name) {
const filepath = files[name];
if (!filepath) throw new Error(`getFile: ${name}错误`);
if (!fs.existsSync(filepath)) throw new Error(`文件${filepath}不存在,请使用rs-reverse工具先获取文件`);
return fs.readFileSync(filepath);
}
function loadPages() {
const htmlText = getFile('html');
const jsText = getFile('js');
let file = getFile('ts');
let url = `${baseUrl}/sgtmi`;
const [jsDom, cookieJar] = jsdomFromText({
url: url,
referrer: url,
contentType: "text/html",
runScripts: "outside-only",
})
const dom = jsDom(htmlText);
window = dom.window
window.$_ts = JSON.parse(file.toString());
window.onbeforeunload = async (url) => {
const cookies = cookieJar.getCookieStringSync(baseUrl);
console.debug(`${url} 生成cookie:`, cookies);
window.close();
}
new Script(jsText.toString()).runInContext(dom.getInternalVMContext());
browser(dom.window, 'chrome');
return cookieJar.getCookieStringSync(baseUrl)
}
let promise = loadPages()
console.log(promise);
module.exports = promise