Context q methods can accept alternative element as first argument. Added BoobPedia profile scraper. Showing fake boobs icon again.

This commit is contained in:
2020-01-23 22:45:46 +01:00
parent 7a77de9ff6
commit 42d07e86f8
6 changed files with 98 additions and 7 deletions

View File

@@ -79,12 +79,18 @@ const funcs = {
qt: qtrailer,
};
function ctx(element) {
function ctx(element, window) {
const contextFuncs = Object.entries(funcs) // dynamically attach methods with context
.reduce((acc, [key, func]) => ({ ...acc, [key]: (...args) => func(element, ...args) }), {});
.reduce((acc, [key, func]) => ({
...acc,
[key]: (...args) => (window && args[0] instanceof window.HTMLElement // allow for different context
? func(...args)
: func(element, ...args)),
}), {});
return {
element,
...(window && { window }),
...contextFuncs,
};
}
@@ -94,9 +100,9 @@ function ctxa(context, selector) {
}
function ex(html) {
const { document } = new JSDOM(html).window;
const { window } = new JSDOM(html);
return ctx(document);
return ctx(window.document, window);
}
module.exports = {