Added profile scraper with releases to Hush. Added qtexts to q to return text nodes individually. Including network in profile site.

This commit is contained in:
2020-03-06 02:49:55 +01:00
parent ae5bd374ba
commit db01599569
36 changed files with 298 additions and 83 deletions

View File

@@ -5,6 +5,11 @@ function inchesToCm(inches) {
}
function feetInchesToCm(feet, inches) {
if (typeof feet === 'string' && !inches) {
const [feetPart, inchesPart] = feet.match(/\d+/g);
return feetInchesToCm(feetPart, inchesPart);
}
return Math.round((Number(feet) * 30.48) + (Number(inches) * 2.54));
}

View File

@@ -64,17 +64,24 @@ function qall(context, selector, attrArg, applyTrim = true) {
return Array.from(context.querySelectorAll(selector));
}
function qtext(context, selector, applyTrim = true) {
function qtexts(context, selector, applyTrim = true, filter = true) {
const el = q(context, selector, null, applyTrim);
if (!el) return null;
const text = Array.from(el.childNodes)
const nodes = Array.from(el.childNodes)
.filter(node => node.nodeName === '#text')
.map(node => (applyTrim ? node.textContent : trim(node.textContent)))
.join(' ');
.map(node => (applyTrim ? trim(node.textContent) : node.textContent));
if (applyTrim) return trim(text);
return text;
return filter ? nodes.filter(Boolean) : nodes;
}
function qtext(context, selector, applyTrim = true) {
const nodes = qtexts(context, selector, applyTrim, true);
if (!nodes) return null;
const text = nodes.join(' ');
return applyTrim ? trim(text) : text;
}
function qmeta(context, selector, attrArg = 'content', applyTrim = true) {
@@ -161,6 +168,7 @@ const funcs = {
qlength,
qmeta,
qtext,
qtexts,
qtrailer,
qtrailers,
qurl,
@@ -176,6 +184,9 @@ const funcs = {
qt: qtrailer,
qts: qtrailers,
qtx: qtext,
qtxt: qtext,
qtxs: qtexts,
qtxts: qtexts,
qu: qurl,
qus: qurls,
};