Commit 748ce478 by yexing

替换测试

parent 41122a67
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.2", "@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-node-resolve": "^16.0.0", "@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-replace": "^6.0.3",
"@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-terser": "^0.4.4",
"@types/chrome": "^0.0.306", "@types/chrome": "^0.0.306",
"@types/node": "^22.13.10", "@types/node": "^22.13.10",
......
import babel from "@rollup/plugin-babel";
import nodeResolve from "@rollup/plugin-node-resolve"; import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs"; import commonjs from "@rollup/plugin-commonjs";
import replace from '@rollup/plugin-replace';
import babel from "@rollup/plugin-babel";
import terser from "@rollup/plugin-terser"; import terser from "@rollup/plugin-terser";
import Path from "path"; import Path from "path";
import fs from "fs"; import fs from "fs";
...@@ -20,7 +21,7 @@ const changeManifest = (others = {}) => { ...@@ -20,7 +21,7 @@ const changeManifest = (others = {}) => {
} }
const pack = (input, options = {}) => { const pack = (input, options = {}) => {
const fn = Path.parse(input); const fn = Path.parse(input);
const { isProd = false, outDir = "dist/js/" } = options; const { isProd = false, isReplace = false, outDir = "dist/js/" } = options;
fs.mkdirSync(outDir, { recursive: true }); fs.mkdirSync(outDir, { recursive: true });
const plugins = [ const plugins = [
nodeResolve({ nodeResolve({
...@@ -36,6 +37,14 @@ const pack = (input, options = {}) => { ...@@ -36,6 +37,14 @@ const pack = (input, options = {}) => {
format: "iife", format: "iife",
name: "G", name: "G",
} }
if (isReplace) {
plugins.push(
replace({
'chrome': 'undefined',
preventAssignment: true
}),
);
}
if (isProd) { if (isProd) {
output.file = Path.join(outDir, `${fn.name}.min.js`); output.file = Path.join(outDir, `${fn.name}.min.js`);
output.sourcemap = true; output.sourcemap = true;
...@@ -56,7 +65,7 @@ const conf = []; ...@@ -56,7 +65,7 @@ const conf = [];
const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV'; const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV';
console.log(`NODE_ENV: ${nodeEnv}`); console.log(`NODE_ENV: ${nodeEnv}`);
if (nodeEnv == 'TEST') { if (nodeEnv == 'TEST') {
conf.push(pack("test/main.js", { outDir: "test/js" })) conf.push(pack("test/main.js", { outDir: "test/js", isReplace: true }));
} else { } else {
changeManifest(); changeManifest();
const inputs = ["src/main.js", "src/popup.js", "src/background.js"]; const inputs = ["src/main.js", "src/popup.js", "src/background.js"];
......
...@@ -17,7 +17,7 @@ async function webJump() { ...@@ -17,7 +17,7 @@ async function webJump() {
} }
}; };
export async function run(options = {}) { export async function run(options = {}) {
const { uri, plan, sn, isDownload=false } = options; const { uri, plan, sn, isDownload = false } = options;
plan.period ||= [fmt0(new Date(), -10), fmt0(new Date(), -1)]; plan.period ||= [fmt0(new Date(), -10), fmt0(new Date(), -1)];
const [fromDate, toDate] = plan.period; const [fromDate, toDate] = plan.period;
const [key, { name }] = Object.entries(TABLE).find((item) => item[1].uri === uri); const [key, { name }] = Object.entries(TABLE).find((item) => item[1].uri === uri);
...@@ -67,7 +67,8 @@ export async function run(options = {}) { ...@@ -67,7 +67,8 @@ export async function run(options = {}) {
} }
addLog(`${name} 运行完成`); addLog(`${name} 运行完成`);
} }
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { if (typeof chrome !== 'undefined' && chrome.runtime) {
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
(async () => { (async () => {
try { try {
if (msg.type === "jump") { if (msg.type === "jump") {
...@@ -81,4 +82,5 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { ...@@ -81,4 +82,5 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
} }
})(); })();
return true; return true;
}); });
}
...@@ -81,7 +81,11 @@ export const makeLogEntry = (message) => { ...@@ -81,7 +81,11 @@ export const makeLogEntry = (message) => {
message message
} }
}; };
export const addLog = (message, push) => chrome.runtime.sendMessage({ type: "addLog", data: makeLogEntry(message), push }); export const addLog = (message, push) => {
if (typeof chrome !== 'undefined' && chrome.runtime) {
chrome.runtime.sendMessage({ type: "addLog", data: makeLogEntry(message), push });
}
};
const checkTime = (time) => { const checkTime = (time) => {
if (!time.isValid()) throw new Error("无效时间"); if (!time.isValid()) throw new Error("无效时间");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment