Skip to content

Commit

Permalink
feat(core): 新增userjs未经压缩代码打包
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed May 21, 2022
1 parent 4099fc4 commit 42badc8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/core/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
const { series } = require('gulp');
const del = require('del');
const { execOut } = require('../../scripts/utils');
const fs = require('fs');
const path = require('path');
const { version } = require('../../package.json');

function cleanOutput() {
return del(['./dist']);
}

function buildUserJs(cb) {
const template = fs.readFileSync(path.join(__dirname, './userjs.template')).toString();
const script = fs.readFileSync('./dist/index.js').toString();
const style = fs.readFileSync('./dist/style.css').toString();
const userjs = template.replace(/{{version}}/g, version).replace(/{{script}}/g, script).replace(/{{style}}/g, style);
fs.writeFileSync('./dist/ocs.user.js', userjs);
cb();
}

exports.default = series(
cleanOutput,
series(
() => execOut('vue-tsc --noEmit && vite build --emptyOutDir false -c vite.config.ts'),
() => execOut('vue-tsc --noEmit && vite build --emptyOutDir false -c vite.config.min.ts')
() => execOut('vue-tsc --noEmit && vite build --emptyOutDir false -c vite.config.min.ts'),
buildUserJs
)
);
47 changes: 47 additions & 0 deletions packages/core/userjs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ==UserScript==
// @name OCS 网课助手
// @version {{version}}
// @description ocs 网课助手,支持各平台网课学习,支持超星学习通,知道智慧树,等网课的学习,作业,考试功能。
// @author enncy
// @antifeature payment
// @license MIT
// @namespace https://enncy.cn
// @homepage https://enncy.github.io/online-course-script/
// @source https://github.com/enncy/online-course-script/
// @icon https://cdn.ocs.enncy.cn/logo.ico
// @connect enncy.cn
// @connect icodef.com
// @match *://*.chaoxing.com/*
// @match *://*.edu.cn/*
// @match *://*.org.cn/*
// @match *://*.zhihuishu.com/*
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// ==/UserScript==


{{script}}

const OCS_STYLE = `{{style}}`

/* eslint no-undef: 0 */

(function () {
"use strict";

// 将OCS对象加入到全局属性
unsafeWindow.OCS = OCS;
// 运行脚本
OCS.start({
// 加载样式
style: OCS_STYLE,
// 支持拖动
draggable: true,
// 加载默认脚本列表,默认 OCS.definedScripts
scripts: OCS.definedScripts,
});
})();

0 comments on commit 42badc8

Please sign in to comment.