mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-23 20:44:42 +08:00
编排新增HTML解析、上传、下载
This commit is contained in:
@@ -4,6 +4,7 @@ const fs = require("fs");
|
||||
const kill = require("tree-kill");
|
||||
const iconv = require("iconv-lite");
|
||||
const path = require("path");
|
||||
const axios = require("axios");
|
||||
|
||||
const getQuickcommandTempFile = require("./getQuickcommandTempFile");
|
||||
const getCommandToLaunchTerminal = require("./getCommandToLaunchTerminal");
|
||||
@@ -72,9 +73,9 @@ const quickcommand = {
|
||||
},
|
||||
|
||||
// 下载文件
|
||||
downloadFile: function (url, file = {}) {
|
||||
downloadFile: function (url, file) {
|
||||
return new Promise((reslove, reject) => {
|
||||
if (file instanceof Object)
|
||||
if (!file || file instanceof Object)
|
||||
file = window.utools.showSaveDialog(JSON.parse(JSON.stringify(file)));
|
||||
axios({
|
||||
method: "get",
|
||||
@@ -95,13 +96,13 @@ const quickcommand = {
|
||||
},
|
||||
|
||||
// 上传文件
|
||||
uploadFile: function (url, file = {}, name = "file", formData = {}) {
|
||||
uploadFile: function (url, file, name = "file", formData = {}) {
|
||||
return new Promise((reslove, reject) => {
|
||||
var objfile;
|
||||
if (file instanceof File) {
|
||||
objfile = file;
|
||||
} else {
|
||||
if (file instanceof Object)
|
||||
if (!file || file instanceof Object)
|
||||
file = window.utools.showOpenDialog(
|
||||
JSON.parse(JSON.stringify(file))
|
||||
)[0];
|
||||
|
14
plugin/lib/quickcomposer/data/htmlParser.js
Normal file
14
plugin/lib/quickcomposer/data/htmlParser.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const htmlParser = (html, selector = "", attr = "") => {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, "text/html");
|
||||
if (!selector) return doc;
|
||||
const elements = doc.querySelectorAll(selector);
|
||||
if (!attr) return elements;
|
||||
let result = Array.from(elements).map((element) => element[attr]);
|
||||
if (result.length === 1) return result[0];
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
htmlParser,
|
||||
};
|
@@ -1,9 +1,11 @@
|
||||
const string = require("./string");
|
||||
const buffer = require("./buffer");
|
||||
const zlib = require("./zlib");
|
||||
const htmlParser = require("./htmlParser");
|
||||
|
||||
module.exports = {
|
||||
...string,
|
||||
...htmlParser,
|
||||
buffer,
|
||||
zlib,
|
||||
};
|
||||
|
Reference in New Issue
Block a user