mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-24 04:53:31 +08:00
编排新增HTML解析、上传、下载
This commit is contained in:
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