UNPKG

@ginstone/nga-api

Version:

43 lines (42 loc) 1.51 kB
"use strict"; //解析网页中的导航栏 Object.defineProperty(exports, "__esModule", { value: true }); exports.NgaLink = exports.DocLink = exports.Navigation = void 0; const StrUtils_1 = require("@ginstone/common-utils/dist/src/utils/StrUtils"); const NgaPhpApi_1 = require("../enums/NgaPhpApi"); const NgaLinkType_1 = require("../enums/NgaLinkType"); const WebUtils_1 = require("@ginstone/common-utils/dist/src/utils/WebUtils"); class Navigation { constructor(doc) { const nav = doc.getElementsByClassName("nav")[0]; this.links = [...nav.getElementsByTagName("a")].map(i => new DocLink(i)); } /** * 查找列表中最后一个指定类型的链接 * @param type 类型 */ findLast(type) { const list = this.links.filter(i => i.link.type === type); if (list.length == 0) { return undefined; } return list[list.length - 1]; } } exports.Navigation = Navigation; class DocLink { constructor(a) { this.title = (0, StrUtils_1.unEscape)(a.outerText) || ""; this.link = new NgaLink(a.getAttribute("href")); } } exports.DocLink = DocLink; class NgaLink { constructor(url) { this.ngaPhpApi = !url ? undefined : (0, NgaPhpApi_1.findApi)(url); this.rawUrl = url ? url : undefined; this.queryParam = url ? (0, WebUtils_1.parseQueryParam)(url) : undefined; this.type = (0, NgaLinkType_1.findType)(this.ngaPhpApi, this.queryParam); } } exports.NgaLink = NgaLink;